initial permcat creation ability, in /settings/permcats; functional permcat creation for testing but still needs a lot of UX work before promoting the ability
This commit is contained in:
parent
46d0e23e7b
commit
30659aef50
@ -90,7 +90,8 @@ class Permcat {
|
|||||||
);
|
);
|
||||||
if($x) {
|
if($x) {
|
||||||
foreach($x as $xv) {
|
foreach($x as $xv) {
|
||||||
$permcats[] = [ $xv['k'], $xv['k'], $xv['v'] ];
|
$value = ((preg_match('|^a:[0-9]+:{.*}$|s', $xv['v'])) ? unserialize($xv['v']) : $xv['v']);
|
||||||
|
$permcats[] = [ $xv['k'], $xv['k'], $value ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
111
Zotlabs/Module/Settings/Permcats.php
Normal file
111
Zotlabs/Module/Settings/Permcats.php
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zotlabs\Module\Settings;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Permcats {
|
||||||
|
|
||||||
|
function post() {
|
||||||
|
|
||||||
|
if(! local_channel())
|
||||||
|
return;
|
||||||
|
|
||||||
|
$channel = \App::get_channel();
|
||||||
|
|
||||||
|
check_form_security_token_redirectOnErr('/settings/permcats', 'settings_permcats');
|
||||||
|
|
||||||
|
|
||||||
|
$all_perms = \Zotlabs\Access\Permissions::Perms();
|
||||||
|
|
||||||
|
$name = escape_tags(trim($_POST['name']));
|
||||||
|
|
||||||
|
$pcarr = [];
|
||||||
|
|
||||||
|
if($all_perms) {
|
||||||
|
foreach($all_perms as $perm => $desc) {
|
||||||
|
if(array_key_exists('perms_' . $perm, $_POST)) {
|
||||||
|
$pcarr[] = $perm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
\Zotlabs\Lib\Permcat::update(local_channel(),$name,$pcarr);
|
||||||
|
|
||||||
|
build_sync_packet();
|
||||||
|
|
||||||
|
info( t('Permission category saved.') . EOL);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function get() {
|
||||||
|
|
||||||
|
if(! local_channel())
|
||||||
|
return;
|
||||||
|
|
||||||
|
$channel = \App::get_channel();
|
||||||
|
|
||||||
|
|
||||||
|
if(argc() > 2)
|
||||||
|
$name = argv(2);
|
||||||
|
|
||||||
|
|
||||||
|
$desc = t('Use this form to create permission rules for various classes of people or connections.');
|
||||||
|
|
||||||
|
$global_perms = \Zotlabs\Access\Permissions::Perms();
|
||||||
|
|
||||||
|
$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'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($global_perms as $k => $v) {
|
||||||
|
$thisperm = get_abconfig(local_channel(),$contact['abook_xchan'],'my_perms',$k);
|
||||||
|
//fixme
|
||||||
|
|
||||||
|
$checkinherited = \Zotlabs\Access\PermissionLimits::Get(local_channel(),$k);
|
||||||
|
|
||||||
|
if($existing[$k])
|
||||||
|
$thisperm = "1";
|
||||||
|
|
||||||
|
$perms[] = array('perms_' . $k, $v, ((array_key_exists($k,$their_perms)) ? intval($their_perms[$k]) : ''),$thisperm, 1, (($checkinherited & PERMS_SPECIFIC) ? '' : '1'), '', $checkinherited);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$tpl = get_markup_template("settings_permcats.tpl");
|
||||||
|
$o .= replace_macros($tpl, array(
|
||||||
|
'$form_security_token' => get_form_security_token("settings_permcats"),
|
||||||
|
'$title' => t('Permission Categories'),
|
||||||
|
'$desc' => $desc,
|
||||||
|
'$desc2' => $desc2,
|
||||||
|
'$tokens' => $t,
|
||||||
|
'$atoken' => $atoken,
|
||||||
|
'$url1' => z_root() . '/channel/' . $channel['channel_address'],
|
||||||
|
'$url2' => z_root() . '/photos/' . $channel['channel_address'],
|
||||||
|
'$name' => array('name', t('Permission Name') . ' <span class="required">*</span>', (($name) ? $name : ''), ''),
|
||||||
|
'$me' => t('My Settings'),
|
||||||
|
'$perms' => $perms,
|
||||||
|
'$inherited' => t('inherited'),
|
||||||
|
'$notself' => 0,
|
||||||
|
'$self' => 1,
|
||||||
|
'$permlbl' => t('Individual Permissions'),
|
||||||
|
'$permnote' => t('Some permissions may be inherited from your channel\'s <a href="settings"><strong>privacy settings</strong></a>, which have higher priority than individual settings. You can <strong>not</strong> change those settings here.'),
|
||||||
|
'$submit' => t('Submit')
|
||||||
|
));
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
view/tpl/settings_permcats.tpl
Normal file
51
view/tpl/settings_permcats.tpl
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<div class="generic-content-wrapper">
|
||||||
|
<div class="section-title-wrapper">
|
||||||
|
<h2>{{$title}}</h2>
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
<div class="section-content-tools-wrapper">
|
||||||
|
<div class="section-content-info-wrapper">
|
||||||
|
{{$desc}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form action="settings/permcats" id="settings-permcats-form" method="post" autocomplete="off" >
|
||||||
|
<input type='hidden' name='form_security_token' value='{{$form_security_token}}'>
|
||||||
|
{{include file="field_input.tpl" field=$name}}
|
||||||
|
|
||||||
|
<div class="settings-submit-wrapper form-group">
|
||||||
|
<button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel">
|
||||||
|
<div class="section-subtitle-wrapper" role="tab" id="perms-tool">
|
||||||
|
<h3>
|
||||||
|
<a data-toggle="collapse" data-parent="#contact-edit-tools" href="#perms-tool-collapse" aria-expanded="true" aria-controls="perms-tool-collapse">
|
||||||
|
{{$permlbl}}
|
||||||
|
</a>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div id="perms-tool-collapse" class="panel-collapse collapse" role="tabpanel" aria-labelledby="perms-tool">
|
||||||
|
<div class="section-content-tools-wrapper">
|
||||||
|
<div class="section-content-warning-wrapper">
|
||||||
|
{{$permnote}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table id="perms-tool-table" class=form-group>
|
||||||
|
<tr>
|
||||||
|
<td></td><td colspan="2" class="abook-me">{{$me}}</td>
|
||||||
|
</tr>
|
||||||
|
{{foreach $perms as $prm}}
|
||||||
|
{{include file="field_acheckbox.tpl" field=$prm}}
|
||||||
|
{{/foreach}}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div class="settings-submit-wrapper" >
|
||||||
|
<button type="submit" name="submit" class="btn btn-primary">{{$submit}}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
Reference in New Issue
Block a user