Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2485220
SharedFolderConfigTrait.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
SharedFolderConfigTrait.php
View Options
<?php
namespace
App\Traits
;
use
Illuminate\Support\Facades\Validator
;
trait
SharedFolderConfigTrait
{
/**
* A helper to get a shared folder configuration.
*/
public
function
getConfig
():
array
{
$config
=
[];
$settings
=
$this
->
getSettings
([
'acl'
]);
$config
[
'acl'
]
=
!
empty
(
$settings
[
'acl'
])
?
json_decode
(
$settings
[
'acl'
],
true
)
:
[];
return
$config
;
}
/**
* A helper to update a shared folder configuration.
*
* @param array $config An array of configuration options
*
* @return array A list of input validation errors
*/
public
function
setConfig
(
array
$config
):
array
{
$errors
=
[];
foreach
(
$config
as
$key
=>
$value
)
{
// validate and save the acl
if
(
$key
===
'acl'
)
{
// Here's the list of acl labels supported by kolabd
// 'all': 'lrsedntxakcpiw',
// 'append': 'wip',
// 'full': 'lrswipkxtecdn',
// 'read': 'lrs',
// 'read-only': 'lrs',
// 'read-write': 'lrswitedn',
// 'post': 'p',
// 'semi-full': 'lrswit',
// 'write': 'lrswite',
// For now we support read-only, read-write, and full
if
(!
is_array
(
$value
))
{
$value
=
(
array
)
$value
;
}
$users
=
[];
foreach
(
$value
as
$i
=>
$v
)
{
if
(!
is_string
(
$v
)
||
empty
(
$v
)
||
!
substr_count
(
$v
,
','
))
{
$errors
[
$key
][
$i
]
=
\trans
(
'validation.acl-entry-invalid'
);
}
else
{
list
(
$user
,
$acl
)
=
explode
(
','
,
$v
,
2
);
$user
=
trim
(
$user
);
$acl
=
trim
(
$acl
);
$error
=
null
;
if
(
!
in_array
(
$acl
,
[
'read-only'
,
'read-write'
,
'full'
])
||
(
$error
=
$this
->
validateAclIdentifier
(
$user
))
||
in_array
(
$user
,
$users
)
)
{
$errors
[
$key
][
$i
]
=
$error
?:
\trans
(
'validation.acl-entry-invalid'
);
}
$value
[
$i
]
=
"$user, $acl"
;
$users
[]
=
$user
;
}
}
if
(
empty
(
$errors
[
$key
]))
{
$this
->
setSetting
(
$key
,
json_encode
(
$value
));
}
}
else
{
$errors
[
$key
]
=
\trans
(
'validation.invalid-config-parameter'
);
}
}
return
$errors
;
}
/**
* Validate an ACL identifier.
*
* @param string $identifier Email address or a special identifier
*
* @return ?string Error message on validation error
*/
protected
function
validateAclIdentifier
(
string
$identifier
):
?
string
{
if
(
$identifier
===
'anyone'
)
{
return
null
;
}
$v
=
Validator
::
make
([
'email'
=>
$identifier
],
[
'email'
=>
'required|email'
]);
if
(
$v
->
fails
())
{
return
\trans
(
'validation.emailinvalid'
);
}
$user
=
\App\User
::
where
(
'email'
,
\strtolower
(
$identifier
))->
first
();
// The user and shared folder must be in the same wallet
if
(
$user
&&
(
$wallet
=
$user
->
wallet
()))
{
if
(
$wallet
->
user_id
==
$this
->
wallet
()->
user_id
)
{
return
null
;
}
}
return
\trans
(
'validation.notalocaluser'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 21, 7:16 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
387432
Default Alt Text
SharedFolderConfigTrait.php (3 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment