Beispiel #1
0
function workspaces_update_5_6()
{
    // create associations
    DB::execute("\n\t\t\tINSERT INTO `" . TABLE_PREFIX . "dimension_member_associations` (`dimension_id`,`object_type_id`,`associated_dimension_id`, `associated_object_type_id`, `is_required`,`is_multiple`, `keeps_record`) VALUES\n\t\t\t((SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'workspaces'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'workspace'),(SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'feng_persons'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'person' LIMIT 1),0,1,0),\n\t\t\t((SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'workspaces'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'workspace'),(SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'feng_persons'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'company' LIMIT 1),0,1,0);\n\t\t");
    // instantiate actual associations
    $ws_dim = Dimensions::findByCode('workspaces');
    $ws_ot = ObjectTypes::findByName('workspace');
    $ws_members = Members::findAll(array('conditions' => 'dimension_id = ' . $ws_dim->getId() . ' AND object_type_id = ' . $ws_ot->getId()));
    foreach ($ws_members as $ws_mem) {
        // after saving permissions the associations are instantiated by 'core_dimensions' plugin
        save_member_permissions($ws_mem);
    }
}
 function edit_permissions()
 {
     if (!can_manage_security(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $member = Members::findById(get_id());
     if (!$member instanceof Member) {
         flash_error(lang('member dnx'));
         ajx_current("empty");
         return;
     }
     if (!array_var($_POST, 'permissions')) {
         $permission_parameters = permission_member_form_parameters($member);
         tpl_assign('permission_parameters', $permission_parameters);
     } else {
         try {
             DB::beginWork();
             save_member_permissions($member);
             DB::commit();
             flash_success(lang('success user permissions updated'));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
     }
 }
$user = Contacts::findById($user_id);
if (!$user instanceof Contact || !$user->isValidToken($token)) {
    throw new Exception("Cannot login with user {$user_id} and token '{$token}'");
}
CompanyWebsite::instance()->setLoggedUser($user, false, false, false);
// save permissions
$member_id = array_var($argv, 4);
$permissions_filename = array_var($argv, 5);
$old_parent_id = array_var($argv, 6);
$permissions = file_get_contents($permissions_filename);
$member = Members::findById($member_id);
if ($member instanceof Member) {
    // transaction to save permission tables
    try {
        DB::beginWork();
        $result = save_member_permissions($member, $permissions, true, false, false, false);
        if ($old_parent_id != -1 && $old_parent_id != $member->getParentMemberId()) {
            do_member_parent_changed_refresh_object_permisssions($member_id, $old_parent_id);
        }
        DB::commit();
    } catch (Exception $e) {
        DB::rollback();
        Logger::log("Error saving permissions (1): " . $e->getMessage() . "\n" . $e->getTraceAsString());
    }
    $changed_pgs = array_var($result, 'changed_pgs');
    if (is_array($changed_pgs)) {
        foreach ($changed_pgs as $pg_id) {
            try {
                // create flag for this $pg_id
                DB::beginWork();
                $flag = new SharingTableFlag();
Beispiel #4
0
function save_member_permissions_background($user, $member, $permissions, $old_parent_id = -1)
{
    if (substr(php_uname(), 0, 7) == "Windows" || !can_save_permissions_in_background()) {
        //pclose(popen("start /B ". $command, "r"));
        save_member_permissions($member, $permissions);
        if ($old_parent_id != $member->getParentMemberId()) {
            member_parent_changed_refresh_object_permisssions($member, $old_parent_id, $user);
        }
    } else {
        // populate permission groups
        $permissions_decoded = json_decode($permissions);
        $to_insert = array();
        $to_delete = array();
        if (is_array($permissions_decoded)) {
            foreach ($permissions_decoded as $perm) {
                if ($perm->r) {
                    $to_insert[] = "('" . $perm->pg . "','" . $member->getId() . "','" . $perm->o . "','" . $perm->d . "','" . $perm->w . "')";
                } else {
                    $to_delete[] = "(permission_group_id='" . $perm->pg . "' AND member_id='" . $member->getId() . "' AND object_type_id='" . $perm->o . "')";
                }
            }
            if (count($to_insert) > 0) {
                $values = implode(',', $to_insert);
                DB::execute("INSERT INTO " . TABLE_PREFIX . "contact_member_permissions (permission_group_id,member_id,object_type_id,can_delete,can_write)\r\n\t\t\t\t\t VALUES {$values} ON DUPLICATE KEY UPDATE member_id=member_id");
            }
            if (count($to_delete) > 0) {
                $where = implode(' OR ', $to_delete);
                DB::execute("DELETE FROM " . TABLE_PREFIX . "contact_member_permissions WHERE {$where};");
            }
        }
        // save permissions in background
        $perm_filename = ROOT . "/tmp/perm_" . gen_id();
        file_put_contents($perm_filename, $permissions);
        $command = "nice -n19 " . PHP_PATH . " " . ROOT . "/application/helpers/save_member_permissions.php " . ROOT . " " . $user->getId() . " " . $user->getTwistedToken() . " " . $member->getId() . " {$perm_filename} {$old_parent_id}";
        exec("{$command} > /dev/null &");
        //Test php command
        exec(PHP_PATH . " -r 'echo function_exists(\"foo\") ? \"yes\" : \"no\";' 2>&1", $output, $return_var);
        if ($return_var != 0) {
            Logger::log(print_r("Error executing php command", true));
            Logger::log(print_r($output, true));
            Logger::log(print_r("Error code: " . $return_var, true));
        }
        //END Test php command
    }
}