/** * Perform actions triggered from the user list page (/users). Actions performed: * addGroup - Adds a given user to a given CT-group * assignRole - Assigns the given role to a given user on the given CT-group. * removeGroup - Removes the given user from the given CT-group. * * Browser is redirected to calling page (hopefully /users), with a flashError or * flashSuccess message indicating the result. */ public function groupActions($groupName) { $targetUserName = Input::get('usedId'); $targetUser = UserAgent::find($targetUserName); if (!$targetUser) { return Redirect::back()->with('flashError', 'User does not exist: ' . $targetUserName); } $action = Input::get('action'); if ($action == 'addGroup') { $userRole = ProjectHandler::grantUser($targetUser, $groupName, Roles::PROJECT_GUEST); return Redirect::back()->with('flashSuccess', 'User ' . $targetUserName . ' added to group ' . $groupName); } elseif ($action == 'assignRole') { $roleName = Input::get('role'); $role = Roles::getRoleByName($roleName); $userRole = ProjectHandler::grantUser($targetUser, $groupName, $role); return Redirect::back()->with('flashSuccess', 'User ' . $targetUserName . ' assigned role ' . $roleName . ' on group ' . $groupName); } elseif ($action == 'removeGroup') { ProjectHandler::revokeUser($targetUser, $groupName); return Redirect::back()->with('flashSuccess', 'User ' . $targetUserName . ' removed from group ' . $groupName); } else { return Redirect::back()->with('flashError', 'Invalid action selected: ' . $action); } }
/** * update units to new data structure */ public function postUpdatedb() { $searchComponent = new MediaSearchComponent(); // amount of units to index per iteration $batchsize = 50; $from = Input::get('next'); $unitCount = Entity::whereIn('tags', ['unit'])->count(); // reset index on start if ($from == 0) { $searchComponent->clear(); } // reduce last batch to remaining units if ($from + $batchsize > $unitCount) { $batchsize = $unitCount - $from; } // all units in this range $units = Entity::distinct('_id')->where('tags', ['unit'])->skip($from)->take($batchsize)->get(); // get list of existing projects $projects = ProjectHandler::listGroups(); // for each unit get the keys and check if the project exists $allKeys = []; for ($i = $from; $i < $from + $batchsize; $i++) { // get data of unit $unit = Entity::where('_id', $units[$i][0])->first(); switch ($unit['documentType']) { case 'annotatedmetadatadescription': $unit['project'] = 'soundandvision'; break; case 'biographynet-sentence': $unit['project'] = 'biographynet'; break; case 'drawing': $unit['project'] = 'rijksmuseum'; break; case 'enrichedvideo': $unit['project'] = 'soundandvision'; break; case 'enrichedvideov2': $unit['project'] = 'soundandvision'; break; case 'enrichedvideov3': $unit['project'] = 'soundandvision'; break; case 'fullvideo': $unit['project'] = 'soundandvision'; break; case 'metadatadescription': $unit['project'] = 'soundandvision'; break; case 'metadatadescription-event': $unit['project'] = 'soundandvision'; break; case 'painting': $unit['project'] = 'rijksmuseum'; break; case 'relex': $unit['project'] = 'ibmrelex'; break; case 'relex-sentence': $unit['project'] = 'ibmrelex'; break; case 'relex-structured-sentence': $unit['project'] = 'ibmrelex'; break; case 'termpairs-sentence': $unit['project'] = 'ibmdisdis'; break; } // add the project if it doesnt exist yet if (!in_array($unit['project'], $projects)) { ProjectHandler::createGroup($unit['project']); // add the project to the temporary list array_push($projects, $unit['project']); } // add the user to the project if it has no access yet if (!ProjectHandler::inGroup($unit['user_id'], $unit['project'])) { $user = UserAgent::find($unit['user_id']); ProjectHandler::grantUser($user, $unit['project'], Roles::PROJECT_MEMBER); } $id = explode('/', $unit['_id']); if (sizeof($id) == 5) { $entity = new Entity(); // copy properties $entity['documentType'] = $unit['documentType']; $entity['test'] = 'new'; $entity->_id = 'entity/' . $entity->documentType . '/' . $id[4]; $entity->save(); } } return ['log' => 'test', 'next' => $from + $batchsize, 'last' => $unitCount]; }