forked from fengoffice/fengoffice
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cut_users_permissions_by_role_and_max_perm.php
50 lines (39 loc) · 1.64 KB
/
cut_users_permissions_by_role_and_max_perm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
chdir(dirname(__FILE__));
define("CONSOLE_MODE", true);
define('PUBLIC_FOLDER', 'public');
include "init.php";
header("Content-type: text/plain");
$admin_pg = PermissionGroups::instance()->findOne(array('conditions' => "`name`='Super Administrator'"));
$all_roles_max_permissions = RoleObjectTypePermissions::getAllRoleObjectTypePermissionsInfo();
$admin_perms = $all_roles_max_permissions[$admin_pg->getId()];
$all_object_types = array();
foreach ($admin_perms as &$aperm) {
$all_object_types[] = $aperm['object_type_id'];
}
$users = Contacts::getAllUsers();
echo date('H:i:s')." - Processing ".count($users)." users...\n";
foreach ($users as $user) {
/* @var $user Contact */
$max_permissions = array_var($all_roles_max_permissions, $user->getUserType());
$pg_id = $user->getPermissionGroupId();
foreach ($all_object_types as $ot) {
if (!$ot) continue;
$max = array_var($max_permissions, $ot);
if (!$max) {
// cannot read -> delete in contact_member_permissions
$sql = "DELETE FROM ".TABLE_PREFIX."contact_member_permissions WHERE permission_group_id=$pg_id AND object_type_id=$ot";
DB::execute($sql);
} else {
// cut can_delete and can_write using max permissions
$can_d = $max['can_delete'] ? "1" : "0";
$can_w = $max['can_write'] ? "1" : "0";
$sql = "UPDATE ".TABLE_PREFIX."contact_member_permissions
SET can_delete=(can_delete AND $can_d), can_write=(can_write AND $can_w)
WHERE permission_group_id=$pg_id AND object_type_id=$ot";
DB::execute($sql);
}
}
echo $user->getObjectName()."\n";
}
echo date('H:i:s')." -------------------------------\n";