Exemplo n.º 1
0
 /**
  * Creates a new Project -- all required sentryGroups are created for the Project.
  * When a new Project is created, roles for the Project are created as follows, 
  * with their corresponding permissions:
  * 
  *  - Roles::PROJECT_ADMIN, with Permissions::PROJECT_ADMIN, Permissions::PROJECT_WRITE and 
  *  	Permissions::PROJECT_READ;
  *  - Roles::PROJECT_MEMBER, with Permissions::PROJECT_WRITE, and Permissions::PROJECT_READ;
  *  - Roles::PROJECT_GUEST, with Permissions::PROJECT_READ,
  * 
  * Default invitation codes are also created for the Project.
  * 
  * Account credentials for CrowdFlower are also stored as part of the Project information.
  * 
  * @param $projectName Name of the Project to be created.
  */
 public static function createGroup($projectName)
 {
     // $groupName credentials are stored in the Admin Sentry-group
     Sentry::createGroup(['name' => str_replace('#', $projectName, Roles::PROJECT_ADMIN), 'permissions' => [str_replace('#', $projectName, Permissions::PROJECT_ADMIN) => 1, str_replace('#', $projectName, Permissions::PROJECT_WRITE) => 1, str_replace('#', $projectName, Permissions::PROJECT_READ) => 1], 'invite_code' => $projectName . '_invitation_admin', 'credentials' => [ProjectHandler::CF_USER => '', ProjectHandler::CF_PASS => '']]);
     Sentry::createGroup(['name' => str_replace('#', $projectName, Roles::PROJECT_MEMBER), 'permissions' => [str_replace('#', $projectName, Permissions::PROJECT_ADMIN) => 0, str_replace('#', $projectName, Permissions::PROJECT_WRITE) => 1, str_replace('#', $projectName, Permissions::PROJECT_READ) => 1], 'invite_code' => $projectName . '_invitation_member']);
     Sentry::createGroup(['name' => str_replace('#', $projectName, Roles::PROJECT_GUEST), 'permissions' => [str_replace('#', $projectName, Permissions::PROJECT_ADMIN) => 0, str_replace('#', $projectName, Permissions::PROJECT_WRITE) => 0, str_replace('#', $projectName, Permissions::PROJECT_READ) => 1], 'invite_code' => $projectName . '_invitation_guest']);
     // Assign user admin to group admin role.
     ProjectHandler::grantUser(Sentry::findUserByLogin(ProjectHandler::ADMIN_USER), $projectName, Roles::PROJECT_ADMIN);
 }
Exemplo n.º 2
0
 /**
  * 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);
     }
 }
Exemplo n.º 3
0
 /**
  * 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];
 }