streams/Zotlabs/Access/PermissionRoles.php

193 lines
4.8 KiB
PHP
Raw Normal View History

2016-06-27 11:44:10 +00:00
<?php
namespace Zotlabs\Access;
/**
* @brief PermissionRoles class.
*
* @see Permissions
*/
2016-06-27 11:44:10 +00:00
class PermissionRoles {
/**
* @brief PermissionRoles version.
*
* This must match the version in Permissions.php before permission updates can run.
*
* @return number
*/
static public function version() {
return 2;
}
2016-06-27 11:44:10 +00:00
2016-07-05 05:37:30 +00:00
static function role_perms($role) {
$ret = array();
$ret['role'] = $role;
2019-02-13 23:33:45 +00:00
switch($role) {
case 'social':
$ret['perms_auto'] = false;
$ret['default_collection'] = false;
$ret['directory_publish'] = true;
$ret['online'] = true;
$ret['perms_connect'] = [
'view_stream', 'view_profile', 'view_contacts', 'view_storage',
'view_pages', 'send_stream', 'post_wall', 'post_comments'
];
$ret['limits'] = PermissionLimits::Std_Limits();
break;
case 'social_restricted':
$ret['perms_auto'] = false;
$ret['default_collection'] = true;
$ret['directory_publish'] = true;
$ret['online'] = false;
2019-02-13 23:33:45 +00:00
$ret['perms_connect'] = [
'view_stream', 'view_profile', 'view_storage',
2019-02-13 23:33:45 +00:00
'view_pages', 'send_stream', 'post_wall', 'post_comments'
];
$ret['limits'] = PermissionLimits::Std_Limits();
$ret['limits']['view_contacts'] = PERMS_SPECIFIC;
2019-02-13 23:33:45 +00:00
break;
case 'forum':
$ret['perms_auto'] = true;
$ret['default_collection'] = false;
$ret['directory_publish'] = true;
$ret['online'] = false;
$ret['perms_connect'] = [
2019-06-08 23:53:05 +00:00
'view_stream', 'view_profile', 'view_contacts', 'view_storage', 'write_storage',
2019-02-13 23:33:45 +00:00
'view_pages', 'post_wall', 'post_comments'
];
$ret['limits'] = PermissionLimits::Std_Limits();
2018-10-04 02:10:52 +00:00
2019-02-13 23:33:45 +00:00
break;
2019-03-13 03:41:58 +00:00
case 'forum_moderated':
$ret['perms_auto'] = true;
$ret['default_collection'] = false;
$ret['directory_publish'] = true;
$ret['online'] = false;
$ret['perms_connect'] = [
'view_stream', 'view_profile', 'view_contacts', 'view_storage',
'view_pages', 'post_wall', 'post_comments', 'moderated'
];
$ret['limits'] = PermissionLimits::Std_Limits();
break;
2019-02-13 23:33:45 +00:00
case 'forum_restricted':
$ret['perms_auto'] = false;
$ret['default_collection'] = true;
$ret['directory_publish'] = true;
$ret['online'] = false;
$ret['perms_connect'] = [
2019-06-08 23:53:05 +00:00
'view_stream', 'view_profile', 'view_contacts', 'view_storage', 'write_storage',
2019-02-13 23:33:45 +00:00
'view_pages', 'post_wall', 'post_comments'
];
$ret['limits'] = PermissionLimits::Std_Limits();
$ret['limits']['view_contacts'] = PERMS_SPECIFIC;
2019-02-13 23:33:45 +00:00
break;
2019-03-05 07:51:47 +00:00
case 'collection':
$ret['perms_auto'] = true;
$ret['default_collection'] = false;
$ret['directory_publish'] = true;
$ret['online'] = false;
$ret['perms_connect'] = [
'view_stream', 'view_profile', 'view_contacts', 'view_storage',
'view_pages', 'post_comments'
];
$ret['limits'] = PermissionLimits::Std_Limits();
break;
case 'collection_restricted':
$ret['perms_auto'] = false;
$ret['default_collection'] = true;
$ret['directory_publish'] = true;
$ret['online'] = false;
$ret['perms_connect'] = [
'view_stream', 'view_profile', 'view_storage',
2019-03-05 07:51:47 +00:00
'view_pages', 'post_comments'
];
$ret['limits'] = PermissionLimits::Std_Limits();
$ret['limits']['view_contacts'] = PERMS_SPECIFIC;
2019-03-05 07:51:47 +00:00
break;
2019-02-13 23:33:45 +00:00
case 'feed':
$ret['perms_auto'] = true;
$ret['default_collection'] = false;
$ret['directory_publish'] = true;
$ret['online'] = false;
$ret['perms_connect'] = [
'view_stream', 'view_profile', 'view_contacts', 'view_storage',
'view_pages', 'send_stream', 'post_wall', 'post_comments',
'republish'
];
$ret['limits'] = PermissionLimits::Std_Limits();
break;
default:
break;
2016-06-27 11:44:10 +00:00
}
2019-02-13 23:33:45 +00:00
2016-07-05 05:37:30 +00:00
$x = get_config('system','role_perms');
// let system settings over-ride any or all
2016-07-05 05:37:30 +00:00
if($x && is_array($x) && array_key_exists($role,$x))
$ret = array_merge($ret,$x[$role]);
2016-06-27 11:44:10 +00:00
/**
* @hooks get_role_perms
* * \e array
*/
$x = [ 'role' => $role, 'result' => $ret ];
2016-07-05 05:37:30 +00:00
call_hooks('get_role_perms', $x);
return $x['result'];
2016-07-05 05:37:30 +00:00
}
2016-06-27 11:44:10 +00:00
2016-07-06 03:21:47 +00:00
/**
* @brief Array with translated role names and grouping.
*
* Return an associative array with grouped role names that can be used
* to create select groups like in \e field_select_grouped.tpl.
*
* @return array
*/
2016-07-06 03:21:47 +00:00
static public function roles() {
2019-02-13 23:33:45 +00:00
$roles = [
t('Social Networking') => [
'social' => t('Social - Normal'),
'social_restricted' => t('Social - Restricted')
],
2019-02-15 01:06:17 +00:00
t('Community Group') => [
'forum' => t('Group - Normal'),
2019-03-14 01:28:23 +00:00
'forum_restricted' => t('Group - Restricted'),
2019-03-13 03:41:58 +00:00
'forum_moderated' => t('Group - Moderated')
2019-02-13 23:33:45 +00:00
],
2019-04-03 23:23:06 +00:00
t('Collection') => [
'collection' => t('Collection - Normal'),
'collection_restricted' => t('Collection - Restricted')
],
2019-03-05 07:51:47 +00:00
2019-02-13 23:33:45 +00:00
t('Feed Republish') => [
'feed' => t('Feed Republish')
]
];
2016-07-06 03:21:47 +00:00
call_hooks('list_permission_roles',$roles);
return $roles;
2016-07-06 03:21:47 +00:00
}
2016-06-27 11:44:10 +00:00
}