2017-02-08 00:43:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Lib;
|
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
use Zotlabs\Access\PermissionRoles;
|
|
|
|
use Zotlabs\Access\Permissions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Permission Categories. Permission rules for various classes of connections.
|
|
|
|
*
|
|
|
|
* Connection permissions answer the question "Can Joe view my photos?"
|
|
|
|
*
|
|
|
|
* Some permissions may be inherited from the channel's "privacy settings"
|
|
|
|
* (@ref ::Zotlabs::Access::PermissionLimits "PermissionLimits") "Who can view my
|
|
|
|
* photos (at all)?" which have higher priority than individual connection settings.
|
|
|
|
* We evaluate permission limits first, and then fall through to connection
|
|
|
|
* permissions if the permission limits didn't already make a definitive decision.
|
|
|
|
*
|
|
|
|
* After PermissionLimits and connection permissions are evaluated, individual
|
|
|
|
* content ACLs are evaluated (@ref ::Zotlabs::Access::AccessList "AccessList").
|
|
|
|
* These answer the question "Can Joe view *this* album/photo?".
|
|
|
|
*/
|
2019-05-07 05:22:58 +00:00
|
|
|
|
2017-02-08 00:43:00 +00:00
|
|
|
class Permcat {
|
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-02-08 00:43:00 +00:00
|
|
|
private $permcats = [];
|
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Permcat constructor.
|
|
|
|
*
|
|
|
|
* @param int $channel_id
|
|
|
|
*/
|
2017-02-08 00:43:00 +00:00
|
|
|
public function __construct($channel_id) {
|
|
|
|
|
2017-02-10 03:52:13 +00:00
|
|
|
$perms = [];
|
|
|
|
|
|
|
|
// first check role perms for a perms_connect setting
|
|
|
|
|
|
|
|
$role = get_pconfig($channel_id,'system','permissions_role');
|
|
|
|
if($role) {
|
2017-12-23 13:42:23 +00:00
|
|
|
$x = PermissionRoles::role_perms($role);
|
2017-02-10 03:52:13 +00:00
|
|
|
if($x['perms_connect']) {
|
2017-12-23 13:42:23 +00:00
|
|
|
$perms = Permissions::FilledPerms($x['perms_connect']);
|
2017-02-08 00:43:00 +00:00
|
|
|
}
|
2017-02-10 03:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if no role perms it may be a custom role, see if there any autoperms
|
|
|
|
|
|
|
|
if(! $perms) {
|
2017-12-23 13:42:23 +00:00
|
|
|
$perms = Permissions::FilledAutoPerms($channel_id);
|
2017-02-10 03:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if no autoperms it may be a custom role with manual perms
|
|
|
|
|
|
|
|
if(! $perms) {
|
2018-06-08 03:17:30 +00:00
|
|
|
$c = channelx_by_n($channel_id);
|
|
|
|
if($c) {
|
|
|
|
$perms = Permissions::FilledPerms(get_abconfig($channel_id,$c['channel_hash'],'system','my_perms',EMPTY_STR));
|
2017-02-08 00:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 03:52:13 +00:00
|
|
|
// nothing was found - create a filled permission array where all permissions are 0
|
|
|
|
|
|
|
|
if(! $perms) {
|
2017-12-23 13:42:23 +00:00
|
|
|
$perms = Permissions::FilledPerms([]);
|
2017-02-10 03:52:13 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 00:43:00 +00:00
|
|
|
$this->permcats[] = [
|
2017-02-10 03:52:13 +00:00
|
|
|
'name' => 'default',
|
|
|
|
'localname' => t('default','permcat'),
|
2017-12-23 13:42:23 +00:00
|
|
|
'perms' => Permissions::Operms($perms),
|
2017-02-09 01:21:32 +00:00
|
|
|
'system' => 1
|
2017-02-08 00:43:00 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
2017-02-08 01:51:56 +00:00
|
|
|
$p = $this->load_permcats($channel_id);
|
2017-02-08 00:43:00 +00:00
|
|
|
if($p) {
|
|
|
|
for($x = 0; $x < count($p); $x++) {
|
|
|
|
$this->permcats[] = [
|
|
|
|
'name' => $p[$x][0],
|
|
|
|
'localname' => $p[$x][1],
|
2017-12-23 13:42:23 +00:00
|
|
|
'perms' => Permissions::Operms(Permissions::FilledPerms($p[$x][2])),
|
2017-02-09 01:21:32 +00:00
|
|
|
'system' => intval($p[$x][3])
|
2017-02-08 00:43:00 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
/**
|
|
|
|
* @brief Return array with permcats.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-02-08 00:43:00 +00:00
|
|
|
public function listing() {
|
|
|
|
return $this->permcats;
|
|
|
|
}
|
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return array
|
|
|
|
* * \e array with permcats
|
|
|
|
* * \e bool \b error if $name not found in permcats true
|
|
|
|
*/
|
2017-02-08 00:43:00 +00:00
|
|
|
public function fetch($name) {
|
|
|
|
if($name && $this->permcats) {
|
|
|
|
foreach($this->permcats as $permcat) {
|
2017-12-23 13:42:23 +00:00
|
|
|
if(strcasecmp($permcat['name'], $name) === 0) {
|
2017-02-08 00:43:00 +00:00
|
|
|
return $permcat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-23 13:42:23 +00:00
|
|
|
|
2017-02-08 00:43:00 +00:00
|
|
|
return ['error' => true];
|
|
|
|
}
|
|
|
|
|
2017-02-08 01:51:56 +00:00
|
|
|
public function load_permcats($uid) {
|
|
|
|
|
|
|
|
$permcats = [
|
|
|
|
[ 'follower', t('follower','permcat'),
|
|
|
|
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
|
2017-02-09 01:21:32 +00:00
|
|
|
'post_like' ], 1
|
2017-02-08 01:51:56 +00:00
|
|
|
],
|
|
|
|
[ 'contributor', t('contributor','permcat'),
|
|
|
|
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
|
2017-02-09 01:21:32 +00:00
|
|
|
'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ], 1
|
2017-02-08 01:51:56 +00:00
|
|
|
],
|
2017-02-08 19:24:21 +00:00
|
|
|
[ 'publisher', t('publisher','permcat'),
|
2017-02-08 01:51:56 +00:00
|
|
|
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
|
2017-02-08 03:49:15 +00:00
|
|
|
'write_storage','post_wall','write_pages','write_wiki','post_comments','post_like','tag_deliver',
|
2017-02-09 01:21:32 +00:00
|
|
|
'chat', 'republish' ], 1
|
2017-02-08 01:51:56 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
if($uid) {
|
|
|
|
$x = q("select * from pconfig where uid = %d and cat = 'permcat'",
|
|
|
|
intval($uid)
|
|
|
|
);
|
|
|
|
if($x) {
|
|
|
|
foreach($x as $xv) {
|
2017-02-08 04:29:03 +00:00
|
|
|
$value = ((preg_match('|^a:[0-9]+:{.*}$|s', $xv['v'])) ? unserialize($xv['v']) : $xv['v']);
|
2017-02-09 01:21:32 +00:00
|
|
|
$permcats[] = [ $xv['k'], $xv['k'], $value, 0 ];
|
2017-02-08 01:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-23 13:42:23 +00:00
|
|
|
}
|
2017-02-08 01:51:56 +00:00
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
/**
|
|
|
|
* @hooks permcats
|
|
|
|
* * \e array
|
|
|
|
*/
|
|
|
|
call_hooks('permcats', $permcats);
|
2017-02-08 01:51:56 +00:00
|
|
|
|
|
|
|
return $permcats;
|
|
|
|
}
|
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
static public function find_permcat($arr, $name) {
|
2017-02-09 01:21:32 +00:00
|
|
|
if((! $arr) || (! $name))
|
|
|
|
return false;
|
2017-12-23 13:42:23 +00:00
|
|
|
|
2017-02-09 01:21:32 +00:00
|
|
|
foreach($arr as $p)
|
|
|
|
if($p['name'] == $name)
|
|
|
|
return $p['value'];
|
|
|
|
}
|
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
static public function update($channel_id, $name, $permarr) {
|
|
|
|
PConfig::Set($channel_id, 'permcat', $name, $permarr);
|
2017-02-08 03:49:15 +00:00
|
|
|
}
|
2017-02-08 01:51:56 +00:00
|
|
|
|
2017-12-23 13:42:23 +00:00
|
|
|
static public function delete($channel_id, $name) {
|
|
|
|
PConfig::Delete($channel_id, 'permcat', $name);
|
2017-02-08 03:49:15 +00:00
|
|
|
}
|
2017-02-08 01:51:56 +00:00
|
|
|
|
2017-02-08 00:43:00 +00:00
|
|
|
}
|