bringer - all basic functionality is implemented

This commit is contained in:
zotlabs 2017-02-08 17:21:32 -08:00
parent 6ee691e019
commit 91819bfc2d
8 changed files with 106 additions and 23 deletions

View file

@ -28,7 +28,8 @@ class Permcat {
$this->permcats[] = [
'name' => $name,
'localname' => $localname,
'perms' => Zaccess\Permissions::Operms($perms)
'perms' => Zaccess\Permissions::Operms($perms),
'system' => 1
];
@ -38,7 +39,8 @@ class Permcat {
$this->permcats[] = [
'name' => $p[$x][0],
'localname' => $p[$x][1],
'perms' => Zaccess\Permissions::Operms(Zaccess\Permissions::FilledPerms($p[$x][2]))
'perms' => Zaccess\Permissions::Operms(Zaccess\Permissions::FilledPerms($p[$x][2])),
'system' => intval($p[$x][3])
];
}
}
@ -65,16 +67,16 @@ class Permcat {
$permcats = [
[ 'follower', t('follower','permcat'),
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
'post_like' ]
'post_like' ], 1
],
[ 'contributor', t('contributor','permcat'),
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ]
'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ], 1
],
[ 'publisher', t('publisher','permcat'),
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
'write_storage','post_wall','write_pages','write_wiki','post_comments','post_like','tag_deliver',
'chat', 'republish' ]
'chat', 'republish' ], 1
]
];
@ -85,7 +87,7 @@ class Permcat {
if($x) {
foreach($x as $xv) {
$value = ((preg_match('|^a:[0-9]+:{.*}$|s', $xv['v'])) ? unserialize($xv['v']) : $xv['v']);
$permcats[] = [ $xv['k'], $xv['k'], $value ];
$permcats[] = [ $xv['k'], $xv['k'], $value, 0 ];
}
}
}
@ -96,6 +98,14 @@ class Permcat {
}
static public function find_permcat($arr,$name) {
if((! $arr) || (! $name))
return false;
foreach($arr as $p)
if($p['name'] == $name)
return $p['value'];
}
static public function update($channel_id, $name,$permarr) {
PConfig::Set($channel_id,'permcat',$name,$permarr);
}

View file

@ -827,6 +827,8 @@ class Connedit extends \Zotlabs\Web\Controller {
'$header' => (($self) ? t('Connection Default Permissions') : sprintf( t('Connection: %s'),$contact['xchan_name'])),
'$autoperms' => array('autoperms',t('Apply these permissions automatically'), ((get_pconfig(local_channel(),'system','autoperms')) ? 1 : 0), t('Connection requests will be approved without your interaction'), $yes_no),
'$permcat' => [ 'permcat', t('Permission role'), '', '',$permcats ],
'$permcat_new' => t('Add permission role'),
'$permcat_enable' => feature_enabled(local_channel(),'permcats'),
'$addr' => $contact['xchan_addr'],
'$section' => $section,
'$sections' => $sections,

View file

@ -42,6 +42,8 @@ class Permcats {
function get() {
logger('cmd: ' . \App::$cmd);
if(! local_channel())
return;
@ -51,30 +53,33 @@ class Permcats {
if(argc() > 2)
$name = argv(2);
if(argc() > 3 && argv(3) === 'drop') {
\Zotlabs\Lib\Permcat::delete(local_channel(),$name);
build_sync_packet();
json_return_and_die([ 'success' => true ]);
}
$desc = t('Use this form to create permission rules for various classes of people or connections.');
$global_perms = \Zotlabs\Access\Permissions::Perms();
$existing = [];
$their_perms = [];
$existing = get_all_perms(local_channel(),(($atoken_xchan) ? $atoken_xchan : ''));
if($atoken_xchan) {
$theirs = q("select * from abconfig where chan = %d and xchan = '%s' and cat = 'their_perms'",
intval(local_channel()),
dbesc($atoken_xchan)
);
if($theirs) {
foreach($theirs as $t) {
$their_perms[$t['k']] = $t['v'];
}
$pcat = new \Zotlabs\Lib\Permcat(local_channel());
$pcatlist = $pcat->listing();
$permcats = [];
if($pcatlist) {
foreach($pcatlist as $pc) {
if(($pc['name']) && ($name) && ($pc['name'] == $name))
$existing = $pc['perms'];
if(! $pc['system'])
$permcats[$pc['name']] = $pc['localname'];
}
}
foreach($global_perms as $k => $v) {
$thisperm = get_abconfig(local_channel(),$contact['abook_xchan'],'my_perms',$k);
//fixme
$global_perms = \Zotlabs\Access\Permissions::Perms();
foreach($global_perms as $k => $v) {
$thisperm = \Zotlabs\Lib\Permcat::find_permcat($existing,$k);
$checkinherited = \Zotlabs\Access\PermissionLimits::Get(local_channel(),$k);
if($existing[$k])
@ -92,6 +97,7 @@ class Permcats {
'$desc' => $desc,
'$desc2' => $desc2,
'$tokens' => $t,
'$permcats' => $permcats,
'$atoken' => $atoken,
'$url1' => z_root() . '/channel/' . $channel['channel_address'],
'$url2' => z_root() . '/photos/' . $channel['channel_address'],

View file

@ -148,6 +148,15 @@ function get_features($filtered = true) {
feature_level('ajaxchat',1),
],
[
'permcats',
t('Permission Groups'),
t('Provide alternate connection permission roles.'),
false,
get_config('feature_lock','permcats'),
feature_level('permcats',2),
],
[
'smart_birthdays',
t('Smart Birthdays'),

View file

@ -661,6 +661,14 @@ function widget_settings_menu($arr) {
);
}
if(feature_enabled(local_channel(),'permcats')) {
$tabs[] = array(
'label' => t('Permission Categories'),
'url' => z_root() . '/settings/permcats',
'selected' => ((argv(1) === 'permcats') ? 'active' : ''),
);
}
if($role === false || $role === 'custom') {
$tabs[] = array(

View file

@ -17,6 +17,16 @@ $(document).ready(function() {
else
$('#advanced-perm').hide();
});
$('#id_permcat_list').change(function() {
$('.loading-role-rotator').spin(true);
var permName = $('#id_permcat').val();
loadPermcat(permName);
});
});
@ -137,3 +147,25 @@ function channel_privacy_macro(n) {
$('#id_profile_in_directory').val(1);
}
}
function loadPermcat(name) {
if(! name)
name = 'default';
$('.abook-edit-me').each(function() {
if(! $(this).is(':disabled'))
$(this).removeAttr('checked');
});
$.get('permcat/' + name, function(data) {
$(data.perms).each(function() {
if(this.value)
$('#me_id_perms_' + this.name).attr('checked','checked');
});
$('.loading-role-rotator').spin(false);
});
}

View file

@ -473,8 +473,11 @@
{{if $self}}{{$permnote_self}}{{/if}}
</div>
{{if $permcat_enable}}
<div class="loading-role-rotator"></div>
<a href="settings/permcats" class="pull-right"><i class="fa fa-plus"></i>&nbsp;{{$permcat_new}}</a>
{{include file="field_select.tpl" field=$permcat}}
{{/if}}
<table id="perms-tool-table" class=form-group>
<tr>

View file

@ -45,6 +45,19 @@
</div>
</div>
</div>
{{if $permcats}}
<div class="section-content-wrapper-np">
<table id="permcat-index">
{{foreach $permcats as $k => $v}}
<tr class="permcat-row-{{$k}}">
<td width="99%"><a href="settings/permcats/{{$k}}">{{$k}}</a></td>
<td width="1%"><i class="fa fa-trash-o drop-icons" onClick="dropItem('/settings/permcats/{{$k}}/drop', '.permcat-row-{{$k}}')"></i></td>
</tr>
{{/foreach}}
</table>
</div>
{{/if}}
</div>
</form>