Пример #1
0
 /**
  * Grants users permissions for the given role on the given project.
  * 
  * @param $user UserAgent instance for the user to be assigned permissions.
  * @param $projectName name of the Project the user is being assigned to.
  * @param $role Role constant defining the role assigned to the user.
  */
 public static function grantUser($user, $projectName, $role)
 {
     // Remove from other Sentry-groups on the same Project
     ProjectHandler::revokeUser($user, $projectName);
     $sentryGroup = Sentry::findGroupByName(str_replace('#', $projectName, $role));
     $user->addGroup($sentryGroup);
 }
Пример #2
0
 public function index()
 {
     // run database seeder on first load
     $groups = ProjectHandler::listProjects();
     if (count($groups) == 0) {
         Artisan::call('db:seed');
     }
     return View::make('index');
 }
Пример #3
0
 /**
  * Create root user and basic permission structure in the database.
  * For detailed documentation on permission structure, see
  * PermissionHandler class.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     // Create admin user with admin permisions
     Sentry::getUserProvider()->create(['_id' => ProjectHandler::ADMIN_USER, 'password' => 'admin', 'email' => '*****@*****.**', 'firstname' => 'Admin', 'lastname' => 'Crowdtruth']);
     // Create the admin group with special permission Permissions::ALLOW_ALL
     ProjectHandler::createGroup('admin');
     $adminGroup = Sentry::findGroupByName('admin:admin');
     $permissions = $adminGroup->permissions;
     $permissions[Permissions::ALLOW_ALL] = 1;
     // Allowed everything !
     $adminGroup->permissions = $permissions;
     $adminGroup->save();
     // Assign user admin to group admin.
     $root = Sentry::findUserByLogin(ProjectHandler::ADMIN_USER);
     $root->addGroup($adminGroup);
 }
Пример #4
0
 /**
  * Handle POST requests to create a new group. 
  */
 public function createGroup()
 {
     $groupName = Input::get('addGrp');
     try {
         ProjectHandler::createGroup($groupName);
         ProjectHandler::grantUser(Auth::user(), $groupName, Roles::PROJECT_ADMIN);
         return Redirect::back()->with('flashSuccess', 'Group <b>' . $groupName . '</b> succesfully created!');
     } catch (\Cartalyst\Sentry\Groups\GroupExistsException $e) {
         return Redirect::back()->with('flashError', 'Group <b>' . $groupName . '</b> already exists!');
     }
 }
Пример #5
0
 public function store($documentType, $parameters, $noOfVideos)
 {
     //fastcgi_finish_request();
     $listOfVideoIdentifiers = array();
     $this->listRecords($parameters, $noOfVideos, $listOfVideoIdentifiers);
     // get list of existing projects
     $projects = ProjectHandler::listProjects();
     //	dd("done");
     $status = array();
     try {
         $this->createOpenimagesVideoGetterSoftwareAgent();
     } catch (Exception $e) {
         $status['error']['OnlineData'] = $e->getMessage();
         return $status;
     }
     try {
         $activity = new Activity();
         $activity->softwareAgent_id = "openimagesgetter";
         $activity->save();
     } catch (Exception $e) {
         // Something went wrong with creating the Activity
         $status['error']['OnlineData'] = $e->getMessage();
         $activity->forceDelete();
         return $status;
     }
     $count["count"] = 0;
     foreach ($listOfVideoIdentifiers as $video) {
         $title = $video;
         try {
             $entity = new Unit();
             $entity->_id = $entity->_id;
             $entity->title = strtolower($title);
             $entity->documentType = $documentType;
             $entity->source = "openimages";
             $entity->project = "soundandvision";
             $entity->type = "unit";
             $videoMetadata = $this->getRecord($video, $parameters["metadataPrefix"]);
             $entity->content = $videoMetadata["content"];
             $parents = array();
             $entity->parents = $parents;
             $entity->tags = array("unit");
             $entity->segments = $count;
             $entity->keyframes = $count;
             $hashing = array();
             $hashing["content"] = $entity->content;
             $hashing["project"] = $entity->project;
             $entity->hash = md5(serialize($hashing));
             $entity->activity_id = $activity->_id;
             $entity->save();
             $status['success'][$title] = $title . " was successfully uploaded. (URI: {$entity->_id})";
             // add the project if it doesnt exist yet
             if (!in_array($entity->project, $projects)) {
                 ProjectHandler::createGroup($entity->project);
                 // add the project to the temporary list
                 array_push($projects, $entity->project);
             }
             // add the user to the project if it has no access yet
             if (!ProjectHandler::inGroup($entity->user_id, $entity->project)) {
                 $user = UserAgent::find($entity->user_id);
                 ProjectHandler::grantUser($user, $entity->project, Roles::PROJECT_MEMBER);
             }
         } catch (Exception $e) {
             // Something went wrong with creating the Entity
             $activity->forceDelete();
             $entity->forceDelete();
             $status['error'][$title] = $e->getMessage();
         }
     }
     $status["recno"] = count($listOfVideoIdentifiers);
     return $status;
 }
Пример #6
0
 /**
  * Display user settings
  */
 public function getSettings(UserAgent $user)
 {
     $groups = ProjectHandler::getUserProjects($user);
     return View::make('users.settings')->with('user', $user)->with('groups', $groups);
 }
Пример #7
0
 private function userDocTypes()
 {
     // get all projects a user has access to
     $projects = ProjectHandler::getUserProjects(Auth::user());
     $projects = array_column($projects, 'name');
     $types = [];
     $allunits = 0;
     $searchComponent = new MediaSearchComponent();
     // for each project get the document types in it
     foreach ($projects as $key => $project) {
         $docTypes = Unit::distinct('documentType')->where('project', $project)->get()->toArray();
         // skip if there is no data
         if (!empty($docTypes[0])) {
             // for each document type get the number of units
             $types[$project] = [];
             foreach ($docTypes as $key => $type) {
                 $count = Unit::where('project', $project)->where('documentType', $type[0])->count();
                 $allunits += $count;
                 $types[$project][$type[0]] = $count;
             }
         }
     }
     return [$types, $allunits];
 }
Пример #8
0
 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]);
 }