aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/Permcat.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib/Permcat.php')
-rw-r--r--Zotlabs/Lib/Permcat.php130
1 files changed, 116 insertions, 14 deletions
diff --git a/Zotlabs/Lib/Permcat.php b/Zotlabs/Lib/Permcat.php
index ca4aed9ed..bda35a9cb 100644
--- a/Zotlabs/Lib/Permcat.php
+++ b/Zotlabs/Lib/Permcat.php
@@ -4,6 +4,8 @@ namespace Zotlabs\Lib;
use Zotlabs\Access\PermissionRoles;
use Zotlabs\Access\Permissions;
+use Zotlabs\Lib\Libsync;
+use Zotlabs\Daemon\Master;
/**
* @brief Permission Categories. Permission rules for various classes of connections.
@@ -79,8 +81,9 @@ class Permcat {
$this->permcats[] = [
'name' => 'default',
- 'localname' => t('default','permcat'),
+ 'localname' => t('Default','permcat'),
'perms' => Permissions::Operms($perms),
+ 'raw_perms' => $perms,
'system' => 1
];
@@ -92,6 +95,7 @@ class Permcat {
'name' => $p[$x][0],
'localname' => $p[$x][1],
'perms' => Permissions::Operms(Permissions::FilledPerms($p[$x][2])),
+ 'raw_perms' => Permissions::FilledPerms($p[$x][2]),
'system' => intval($p[$x][3])
];
}
@@ -128,27 +132,24 @@ class Permcat {
}
public function load_permcats($uid) {
-
+/*
$permcats = [
- [ 'follower', t('follower','permcat'),
- [ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
- 'post_like' ], 1
+ [ 'contributor', t('Contributor','permcat'),
+ [ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
+ 'write_storage','post_wall','write_pages','write_wiki','post_comments', 'post_mail', 'post_like',
+ 'chat' ], 1
],
- [ 'contributor', t('contributor','permcat'),
+ [ 'muted', t('Muted','permcat'),
[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
- 'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ], 1
+ 'post_comments','write_wiki','post_like' ], 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' ], 1
- ]
];
-
+*/
if($uid) {
$x = q("select * from pconfig where uid = %d and cat = 'permcat'",
intval($uid)
);
+
if($x) {
foreach($x as $xv) {
$value = ((preg_match('|^a:[0-9]+:{.*}$|s', $xv['v'])) ? unserialize($xv['v']) : $xv['v']);
@@ -183,4 +184,105 @@ class Permcat {
PConfig::Delete($channel_id, 'permcat', $name);
}
-} \ No newline at end of file
+ /**
+ * @brief assign a contact role to contacts
+ *
+ * @param int $channel_id
+ * @param string $role the name of the role
+ * @param array $contacts an array of contact hashes
+ */
+ public static function assign($channel, $role, $contacts) {
+
+ if(!isset($channel['channel_id'])) {
+ return;
+ }
+
+ if(!is_array($contacts) || empty($contacts)) {
+ return;
+ }
+
+ if(!$role) {
+ // lookup the default
+ $role = get_pconfig($channel_id, 'system', 'default_permcat', 'default');
+ }
+
+
+ // Doublecheck that we do not assign a role to ourself.
+ // It does not make a difference but could be confusing.
+ if (in_array($channel['channel_hash'], $contacts)) {
+ $contacts = array_diff($contacts, [$channel['channel_hash']]);
+ }
+
+ $all_perms = Permissions::Perms();
+ $permcats = new Permcat($channel['channel_id']);
+ $role_perms = $permcats->fetch($role);
+
+ if (isset($role_perms['error'])) {
+ return false;
+ }
+
+ $perms = $role_perms['raw_perms'];
+
+ $values_sql = '';
+ stringify_array_elms($contacts, true);
+
+ if ($all_perms && $perms) {
+
+ foreach ($contacts as $contact) {
+ foreach ($all_perms as $perm => $desc) {
+ if (array_key_exists($perm, $perms)) {
+ $values_sql .= " (" . intval($channel['channel_id']) . ", " . protect_sprintf($contact) . ", 'my_perms', '" . dbesc($perm) . "', " . intval($perms[$perm]) . "),";
+ }
+ else {
+ $values_sql .= " (" . intval($channel['channel_id']) . ", " . protect_sprintf($contact) . ", 'my_perms', '" . dbesc($perm) . "', 0), ";
+ }
+ }
+ }
+ }
+
+ $values_sql = rtrim($values_sql, ',');
+
+ dbq("DELETE FROM abconfig WHERE chan = " . intval($channel['channel_id']) . " AND cat = 'my_perms' AND xchan IN (" . protect_sprintf(implode(',', $contacts)) . ")");
+
+ dbq("INSERT INTO abconfig ( chan, xchan, cat, k, v ) VALUES $values_sql");
+
+ q("UPDATE abook SET abook_role = '%s'
+ WHERE abook_xchan IN (" . protect_sprintf(implode(',', $contacts)) . ") AND abook_channel = %d",
+ dbesc($role),
+ intval($channel['channel_id'])
+ );
+
+ $r = q("SELECT abook.*, xchan.* FROM abook LEFT JOIN xchan ON abook.abook_xchan = xchan.xchan_hash WHERE abook.abook_xchan IN (" . protect_sprintf(implode(',', $contacts)) . ") AND abook.abook_channel = %d AND abook_self = 0",
+ intval($channel['channel_id'])
+ );
+
+ foreach ($r as $rr) {
+
+ if (intval($rr['abook_self'])) {
+ continue;
+ }
+
+ Master::Summon([
+ 'Notifier',
+ 'permission_update',
+ $rr['abook_id']
+ ]);
+
+ $clone = $rr;
+
+ unset($clone['abook_id']);
+ unset($clone['abook_account']);
+ unset($clone['abook_channel']);
+
+ $abconfig = load_abconfig($channel['channel_id'], $clone['abook_xchan']);
+ if ($abconfig)
+ $clone['abconfig'] = $abconfig;
+
+ Libsync::build_sync_packet(0 /* use the current local_channel */, ['abook' => [$clone]]);
+
+ }
+
+ return true;
+ }
+
+}