/** * 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); } }
public function getIndex() { $c = Input::get('collection', 'Entity'); $collection = $this->repository->returnCollectionObjectFor($c); // Filter data for projects for which the authenticated user has permissions. if (Input::has('authkey')) { $user = \MongoDB\UserAgent::where('api_key', Input::get('authkey'))->first(); if (is_null($user)) { return ['error' => 'Invalid auth key: ' . Input::get('authkey')]; } } elseif (Auth::check()) { $user = Auth::user(); } else { return ['error' => 'Authentication required. Please supply authkey.']; } $projects = ProjectHandler::getUserProjects($user, Permissions::PROJECT_READ); $projectNames = array_column($projects, 'name'); $collection = $collection->whereIn('project', $projectNames); if (Input::has('match')) { $collection = $this->processFields($collection); } $start = (int) Input::get('start', 0); $limit = (int) Input::get('limit', 100); $only = Input::get('only', array()); if ($orderBy = Input::get('orderBy')) { foreach ($orderBy as $sortingColumnName => $sortingDirection) { $collection = $collection->orderBy($sortingColumnName, $sortingDirection); } } $collection = $collection->paginate($limit, $only); $pagination = $collection->links()->render(); $count = $collection->toArray(); unset($count['data']); $documents = $collection->toArray()['data']; if (array_key_exists('tocsv', Input::all())) { set_time_limit(1200); $writer = new Writer(new \SplTempFileObject()); $writer->setNullHandlingMode(Writer::NULL_AS_EMPTY); $headerDotted = array(); foreach ($documents as $line_index => $row) { unset($row['metrics'], $row['platformJobId'], $row['results'], $row['cache']); if (isset($row['parents'])) { $row['wasDerivedFrom'] = implode(",", $row['parents']); unset($row['parents']); } foreach (array_dot($row) as $k => $v) { array_push($headerDotted, $k); } } $headerDotted = array_unique($headerDotted); natcasesort($headerDotted); $csvHeader = array_change_key_case(str_replace('.', '_', array_values($headerDotted)), CASE_LOWER); $writer->insertOne($csvHeader); foreach ($documents as $line_index => $row) { if (isset($row['parents'])) { $row['wasDerivedFrom'] = implode(",", $row['parents']); unset($row['parents']); } $row = array_dot($row); foreach ($headerDotted as $column) { if (isset($row[$column])) { $csvRow[str_replace('.', '_', $column)] = $row[$column]; } else { $csvRow[str_replace('.', '_', $column)] = ""; } } $writer->insertOne($csvRow); } $writer->output(time() . '.csv'); die; } return Response::json(["count" => $count, "pagination" => $pagination, "searchQuery" => Input::except('page'), "documents" => $documents]); }
/** * Get list of all users */ public static function getUserlist() { return UserAgent::orderBy('_id', 'asc')->get(); }
/** * 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]; }
/** * Change user profile settings. Three actions can be performed: * - Change User information (name and email) * - Change password * - Generate API key -- used for external API data calls. */ public function postSettings(UserAgent $user) { $action = Input::get('action'); if ($action == 'userinfo') { // Change user details $user['firstname'] = Input::get('firstname'); $user['lastname'] = Input::get('lastname'); $user['email'] = Input::get('email'); $user->save(); Session::flash('flashSuccess', 'Profile information succesfully changed'); } elseif ($action == 'password') { // Change user password $currPass = Input::get('oldpassword'); if ($user->checkPassword($currPass)) { $newPass1 = Input::get('newpassword1'); $newPass2 = Input::get('newpassword2'); if ($newPass1 == $newPass2) { $user->password = $newPass1; $user->save(); Session::flash('flashSuccess', 'Password succesfully changed'); } else { return Redirect::back()->with('flashError', 'New passwords do not match'); } } else { return Redirect::back()->with('flashError', 'Incorrect password'); } } elseif ($action == 'apikey') { // Generate new API key $user['api_key'] = hash('sha256', Str::random(10), false); $user->save(); Session::flash('flashSuccess', 'New API key generated'); } return Redirect::back(); }