/** * This function will create a new user object and return the newly created user object. * * @param array $userInfo This should have the properties: username, firstname, lastname, password, ui_language * * @return mixed */ public function registerUser(array $userInfo, $userLanguage) { $user = \User::create($userInfo); //make the first user an admin if (\User::all()->count() <= 1) { $user->is_admin = 1; } // Trim trailing whitespace from user first and last name. $user->firstname = trim($user->firstname); $user->lastname = trim($user->lastname); $user->save(); \Setting::create(['ui_language' => $userLanguage, 'user_id' => $user->id]); /* Add welcome note to user - create notebook, tag and note */ //$notebookCreate = Notebook::create(array('title' => Lang::get('notebooks.welcome_notebook_title'))); $notebookCreate = new \Notebook(); $notebookCreate->title = Lang::get('notebooks.welcome_notebook_title'); $notebookCreate->save(); $notebookCreate->users()->attach($user->id, ['umask' => \PaperworkHelpers::UMASK_OWNER]); //$tagCreate = Tag::create(array('title' => Lang::get('notebooks.welcome_note_tag'), 'visibility' => 0)); $tagCreate = new \Tag(); $tagCreate->title = Lang::get('notebooks.welcome_note_tag'); $tagCreate->visibility = 0; $tagCreate->user_id = $user->id; $tagCreate->save(); //$tagCreate->users()->attach($user->id); $noteCreate = new \Note(); $versionCreate = new \Version(['title' => Lang::get('notebooks.welcome_note_title'), 'content' => Lang::get('notebooks.welcome_note_content'), 'content_preview' => mb_substr(strip_tags(Lang::get('notebooks.welcome_note_content')), 0, 255), 'user_id' => $user->id]); $versionCreate->save(); $noteCreate->version()->associate($versionCreate); $noteCreate->notebook_id = $notebookCreate->id; $noteCreate->save(); $noteCreate->users()->attach($user->id, ['umask' => \PaperworkHelpers::UMASK_OWNER]); $noteCreate->tags()->sync([$tagCreate->id]); return $user; }
/** * @param $title */ protected function createNotebook($title) { $this->notebook = \Notebook::firstOrCreate(['title' => $title]); if (!$this->notebook->users->contains(\Auth::user()->id)) { $this->notebook->users()->attach(\Auth::user()->id, array('umask' => \PaperworkHelpers::UMASK_OWNER)); } }
public function get($argv = array()) { $defaultNotebooksSelect = array('notebooks.id', 'notebooks.parent_id', 'notebooks.type', 'notebooks.title', 'notebook_user.umask', 'notebooks.created_at', 'notebooks.updated_at'); $userId = $this->getArg($argv, 'userid'); $id = $this->getArg($argv, 'id'); $data = \Notebook::with(array('children' => function ($query) use(&$userId, &$defaultNotebooksSelect) { $query->join('notebook_user', function ($join) use(&$userId) { $join->on('notebook_user.notebook_id', '=', 'notebooks.id')->where('notebook_user.user_id', '=', $userId)->where('notebook_user.umask', '>', 0); })->select($defaultNotebooksSelect)->whereNull('deleted_at'); }))->join('notebook_user', function ($join) use(&$userId) { $join->on('notebook_user.notebook_id', '=', 'notebooks.id')->where('notebook_user.user_id', '=', $userId)->where('notebook_user.umask', '>', 0); })->whereNull('parent_id')->select($defaultNotebooksSelect); $idCount = count($id); if ($idCount > 0) { $data->where('notebooks.id', '=', $argv['id'][0]); } if ($idCount > 1) { for ($i = 1; $i < $idCount; $i++) { $data->orWhere('notebooks.id', '=', $argv['id'][$i]); } } $data->whereNull('deleted_at'); $data->orderBy('type', 'desc'); return $data->get(); }
public function store() { $validator = $this->getNewNotebookValidator(); if ($validator->passes()) { $newNotebook = Input::json(); $notebook = Notebook::create(array('title' => $newNotebook->get('title'), 'type' => $newNotebook->get('type'))); $notebook->save(); $notebook->users()->attach(Auth::user()->id, array('umask' => PaperworkHelpers::UMASK_OWNER)); if ($newNotebook->get('shortcut')) { $shortcut = new Shortcut(array('sortkey' => 255, 'user_id' => Auth::user()->id)); $notebook->shortcuts()->save($shortcut); } return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $notebook); } else { return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, $validator->getMessageBag()->toArray()); } }
/** * * @param array $items */ public function add($items) { $this->objects_imported = 0; $this->objects_skipped = 0; foreach ($items as $item) { $title = $item->title; $description = $item->description; if (empty($title) || empty($description)) { $this->objects_skipped++; continue; } $item->c_id = $this->course->c_id; $item->session_id = $this->course->session_id; $repo = Notebook::repository(); $success = $repo->save($item); if ($success) { $this->objects_imported++; } else { $this->objects_skipped++; } } }
function testRenderAsEdit_newNotebook() { global $USER; $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB); $n = Notebook::createNewNotebookForUser($USER->user_id, $this->DB); // $this->fail(); // $canonical = '<div id="edit_rendered_notebook_NEW" class="edit_rendered_notebook" data-notebook_id="NEW" data-created_at="'.$n->created_at.'" data-updated_at="'.$n->updated_at.'" data-user_id="101" data-name="'.htmlentities($n->name).'" data-notes="'.htmlentities(util_lang('new_notebook_notes')).'" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1"> //<form action="'.APP_ROOT_PATH.'/app_code/notebook.php"> // <input type="hidden" name="action" value="update"/> // <input type="hidden" name="notebook_id" value="NEW"/> // <h3 class="notebook_title">'.ucfirst(util_lang('notebook')).': <input id="notebook-name" type="text" name="name" value="'.htmlentities($n->name).'"/></h3> // <span class="created_at">'.util_lang('created_at').' '.util_datetimeFormatted($n->created_at).'</span>, <span class="updated_at">'.util_lang('updated_at').' '.util_datetimeFormatted($n->updated_at).'</span><br/> // <span class="owner">'.util_lang('owned_by').' <a href="'.APP_ROOT_PATH.'/app_code/user.php?action=view&user_id=101">'.$USER->screen_name.'</a></span><br/> // <div class="notebook-notes"><textarea id="notebook-notes" name="notes" rows="4" cols="120">'.htmlentities(util_lang('new_notebook_notes')).'</textarea></div> // <input id="edit-submit-control" class="btn" type="submit" name="edit-submit-control" value="'.util_lang('save','properize').'"/> // <a id="edit-cancel-control" class="btn" href="/digitalfieldnotebooks/app_code/notebook.php?action=list">'.util_lang('cancel','properize').'</a> //</form> // <h4>'.ucfirst(util_lang('pages')).'</h4> // '.util_lang('new_notebook_must_be_saved').' //</div>'; $canonical = '<div id="edit_rendered_notebook_NEW" class="edit_rendered_notebook" data-notebook_id="NEW" data-created_at="' . $n->created_at . '" data-updated_at="' . $n->updated_at . '" data-user_id="101" data-name="' . htmlentities($n->name) . '" data-notes="' . htmlentities(util_lang('new_notebook_notes')) . '" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1"> <form action="' . APP_ROOT_PATH . '/app_code/notebook.php"> <div id="actions"> <button id="edit-submit-control" class="btn btn-success" type="submit" name="edit-submit-control"><i class="icon-ok-sign icon-white"></i> ' . util_lang('save', 'properize') . '</button> <a id="edit-cancel-control" class="btn" href="' . APP_ROOT_PATH . '/app_code/notebook.php?action=list"><i class="icon-remove"></i> ' . util_lang('cancel', 'properize') . '</a> </div> <input type="hidden" name="action" value="update"/> <input type="hidden" name="notebook_id" value="NEW"/> <h3 class="notebook_title">' . ucfirst(util_lang('notebook')) . ': <input id="notebook-name" type="text" name="name" value="' . htmlentities($n->name) . '"/></h3> <div class="info-timestamps"><span class="created_at">' . util_lang('created_at') . ' ' . util_datetimeFormatted($n->created_at) . '</span>, <span class="updated_at">' . util_lang('updated_at') . ' ' . util_datetimeFormatted($n->updated_at) . '</span></div> <div class="info-owner">' . util_lang('owned_by') . ' <a href="' . APP_ROOT_PATH . '/app_code/user.php?action=view&user_id=101">' . $USER->screen_name . '</a></div> <div class="control-workflows"></div> <div class="notebook_notes"><textarea id="notebook-notes" name="notes" rows="4" cols="120">' . htmlentities(util_lang('new_notebook_notes')) . '</textarea></div> </form> <h4>' . ucfirst(util_lang('pages')) . '</h4> ' . util_lang('new_notebook_must_be_saved') . ' </div>'; $rendered = $n->renderAsEdit(); // echo "<pre>\n".htmlentities($canonical)."\n-----------------\n".htmlentities($rendered)."\n</pre>"; $this->assertEqual($canonical, $rendered); $this->assertNoPattern('/IMPLEMENTED/', $rendered); }
public function addNoteFromJSON($glob) { //WHY DOESNT THIS HAPPEN VIA THE FRAMEWORK?! $data = file_get_contents("php://input"); $glob = json_decode($data); $gameId = $glob->gameId; $noteId = $glob->noteId; $playerId = $glob->playerId; $title = $glob->title; $description = $glob->description; $publicToMap = $glob->publicToMap; $publicToBook = $glob->publicToBook; $location = $glob->location; $media = $glob->media; $tags = $glob->tags; $publicToMap = 1; $publicToBook = 1; if (!is_numeric($gameId)) { return new returnData(1, NULL, "JSON package has no numeric member \"gameId\""); } if (!is_numeric($playerId)) { return new returnData(1, NULL, "JSON package has no numeric member \"playerId\""); } if (!$noteId) { $noteId = Notebook::createNote($gameId, $playerId)->data; } Notebook::updateNote($noteId, $title, $publicToMap, $publicToBook, $location->latitude, $location->longitude); //THIS IS THE CLEANEST WAY TO HANDLE LEGACY DESCRIPTION STORAGE Module::query("DELETE FROM note_content WHERE game_id = '{$gameId}' AND note_id = '{$noteId}' AND type = 'TEXT'"); Module::query("INSERT INTO note_content (note_id, game_id, media_id, type, text) VALUES ('" . $noteId . "', '" . $gameId . "', 0, 'TEXT', '" . $description . "')"); for ($i = 0; is_array($media) && $i < count($media); $i++) { $mediaId = Media::createMediaFromJSON($media[$i])->data->media_id; Notebook::addContentToNote($noteId, $mediaId, "MEDIA"); } $oldTags = Notebook::getNoteTags($noteId, $gameId); for ($i = 0; is_array($oldTags) && $i < count($oldTags); $i++) { $tagDeleted = true; for ($j = 0; is_array($tags) && $j < count($tags); $j++) { if ($oldTags[$i]->tag == $tags[$j]) { $tagDeleted = false; } } if ($tagDeleted) { Notebook::deleteTagFromNote($noteId, $oldTags[$i]->tag_id); } } for ($i = 0; is_array($tags) && $i < count($tags); $i++) { Notebook::addTagToNote($noteId, $tags[$i]); } return new returnData(0, Notebook::getNote($noteId)->data); }
$notebook = new Notebook(['DB' => $DB]); if (!$USER->canActOnTarget($ACTIONS['create'], $notebook)) { util_redirectToAppHome('failure', util_lang('no_notebooks_found')); } } else { $notebook = $all_accessible_notebooks[0]; } } else { // if ((! isset($_REQUEST['notebook_id'])) || (! is_numeric($_REQUEST['notebook_id']))) { //// util_redirectToAppHome('failure',util_lang('no_notebook_specified')); // util_redirectToAppPage('app_code/notebook.php?action=list','failure',util_lang('no_notebook_specified')); // } if ($_REQUEST['notebook_id'] == 'NEW') { $notebook = Notebook::createNewNotebookForUser($USER->user_id, $DB); } else { $notebook = Notebook::getOneFromDb(['notebook_id' => $_REQUEST['notebook_id']], $DB); if (!$notebook->matchesDb) { // util_redirectToAppHome('failure',util_lang('no_notebook_found')); util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_notebook_found')); } } } # 3. confirm that the user is allowed to take that action on that object (if not, redirect them to the home page with an appropriate warning) if (!$USER->canActOnTarget($ACTIONS[$action], $notebook)) { // util_redirectToAppHome('failure',util_lang('no_permission')); if ($action == 'edit') { util_redirectToAppPage('app_code/notebook.php?action=view¬ebook_id=' . $notebook->notebook_id, 'failure', util_lang('no_permission')); } util_redirectToAppPage('app_code/notebook.php?action=list', 'failure', util_lang('no_permission')); } if ($action != 'delete') {
/** * Exclude object from result * * @param Notebook $notebook Object to remove from the list of results * * @return NotebookQuery The current query, for fluid interface */ public function prune($notebook = null) { if ($notebook) { $this->addUsingAlias(NotebookPeer::NOTEBOOK_ID, $notebook->getNotebookId(), Criteria::NOT_EQUAL); } return $this; }
HTTP headers:</br> FORWARDED_PROTO: <?php echo $_SERVER['HTTP_X_FORWARDED_PROTO']; ?> <br/> PERMISSIONS: <?php echo $_SERVER['HTTP_X_SANDSTORM_PERMISSIONS']; ?> <br/> <br/> Amount of users: <?php echo User::all()->count(); ?> <br/> Amount of notebooks: <?php echo Notebook::all()->count(); ?> <br/> Amount of tags: <?php echo Tag::all()->count(); ?> <br/> Amount of notes: <?php echo Note::all()->count(); ?> <br/> <br/> Amount of Init Steps: <?php echo DB::table('migrations')->where('batch', '=', 1)->count(); ?> <br/>
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Notebook $value A Notebook object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(Notebook $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getNotebookId(); } // if key === null self::$instances[$key] = $obj; } }
public function getAccessibleNotebooks($for_action, $debug_flag = 0) { if ($this->flag_is_system_admin) { if ($debug_flag) { echo "user is system admin<br/>\n"; } return Notebook::getAllFromDb(['flag_delete' => FALSE], $this->dbConnection); } if (is_string($for_action)) { global $ACTIONS; $for_action = $ACTIONS[$for_action]; } //util_prePrintR($this); $accessible_notebooks_ids = array(); if ($for_action->name == 'view' || $for_action->name == 'list') { $all_notebooks = Notebook::getAllFromDb(['flag_workflow_published' => TRUE, 'flag_workflow_validated' => TRUE, 'flag_delete' => FALSE], $this->dbConnection); $accessible_notebooks_ids = Db_Linked::arrayOfAttrValues($all_notebooks, 'notebook_id'); } $roles = $this->getRoles(); if ($debug_flag) { echo "user roles are<br/>\n"; util_prePrintR($roles); } foreach (Db_Linked::arrayOfAttrValues($roles, 'role_id') as $role_id) { $global_check = Role_Action_Target::getAllFromDb(['role_id' => $role_id, 'action_id' => $for_action->action_id, 'target_type' => 'global_notebook'], $this->dbConnection); if ($debug_flag) { echo "global_check is <br/>\n"; util_prePrintR($global_check); } if (count($global_check) > 0) { $all_notebooks = Notebook::getAllFromDb(['flag_delete' => FALSE], $this->dbConnection); $accessible_notebooks_ids = Db_Linked::arrayOfAttrValues($all_notebooks, 'notebook_id'); } $role_action_targets = Role_Action_Target::getAllFromDb(['role_id' => $role_id, 'action_id' => $for_action->action_id, 'target_type' => 'notebook'], $this->dbConnection); foreach ($role_action_targets as $rat) { if (!in_array($rat->target_id, $accessible_notebooks_ids)) { $accessible_notebooks_ids[] = $rat->target_id; } } } // util_prePrintR($accessible_notebooks_ids); $owned_notebooks = Notebook::getAllFromDb(['user_id' => $this->user_id], $this->dbConnection); $owned_notebook_ids = Db_Linked::arrayOfAttrValues($owned_notebooks, 'notebook_id'); $additional_notebook_ids = array(); foreach ($accessible_notebooks_ids as $an_id) { if (!in_array($an_id, $owned_notebook_ids)) { $additional_notebook_ids[] = $an_id; } } $additional_notebooks = array(); if (count($additional_notebook_ids) > 0) { $additional_notebooks = Notebook::getAllFromDb(['notebook_id' => $additional_notebook_ids], $this->dbConnection); } $ret = array_merge($owned_notebooks, $additional_notebooks); // util_prePrintR($accessible_notebooks_ids); return $ret; }
function testViewNotEditable() { $this->doLoginBasic(); $this->goToNotebookView(1004); $this->checkBasicAsserts(); $n = Notebook::getOneFromDb(['notebook_id' => 1004], $this->DB); // util_prePrintR($n); $ap1 = Authoritative_Plant::getOneFromDb(['authoritative_plant_id' => 5001], $this->DB); // page heading text $this->assertText(ucfirst(util_lang('notebook'))); $this->assertText($n->name); $this->assertText($n->notes); // NO 'edit' control $this->assertNoLink(util_lang('edit')); // number of notebook pages $this->assertEltByIdHasAttrOfValue('list-of-notebook-pages', 'data-notebook-page-count', '1'); $this->assertEltByIdHasAttrOfValue('notebook-page-item-1', 'data-notebook_page_id', '1104'); $this->assertLink($ap1->renderAsShortText()); // NO 'add page' control $this->assertNoLink(util_lang('add_notebook_page')); }
function testRenderAsListItemForNotebook() { $np = Notebook_Page::getOneFromDb(['notebook_page_id' => 1101], $this->DB); global $USER; $USER = User::getOneFromDb(['username' => TESTINGUSER], $this->DB); $nb = Notebook::getOneFromDb(['notebook_id' => 1001], $this->DB); $rendered = $np->renderAsListItemForNotebook(); $canonical = '<li data-notebook_page_id="1101" data-created_at="' . $np->created_at . '" data-updated_at="' . $np->updated_at . '" data-notebook_id="1001" data-authoritative_plant_id="5001" data-notes="testing notebook page the first in testnotebook1, owned by user 101" data-flag_workflow_published="0" data-flag_workflow_validated="0" data-flag_delete="0" data-can-edit="1"><a href="' . APP_ROOT_PATH . '/app_code/notebook_page.php?action=view¬ebook_page_id=1101">' . util_lang('page_in_notebook') . ' ' . htmlentities($nb->name) . '</a></li>'; // echo "<pre>\n".htmlentities($canonical)."\n--------------\n".htmlentities($rendered)."\n</pre>"; $this->assertEqual($canonical, $rendered); }
function testBaseDataUpdate() { $this->doLoginBasic(); $this->get('http://localhost/digitalfieldnotebooks/app_code/notebook.php?action=edit¬ebook_id=1001'); $this->checkBasicAsserts(); // NOTE: the identifier to use for setField is the value of the name attribute of the field $this->setField('name', 'new name for testnotebook1'); // NOTE: the identifier to use for form buttons is the value of the value attribute of the button, or the interior html of a button element $this->click('<i class="icon-ok-sign icon-white"></i> ' . util_lang('update', 'properize')); $this->checkBasicAsserts(); $this->assertText('new name for testnotebook1'); $n = Notebook::getOneFromDb(['notebook_id' => 1001], $this->DB); $this->assertEqual($n->name, 'new name for testnotebook1'); // util_prePrintR(htmlentities($this->getBrowser()->getContent())); }
public function checkSandstormUsers() { if (Config::get('paperwork.emergency_export') && DB::table('migrations')->where('batch', '=', 1)->count() == Config::get('paperwork.emergency_export_count')) { $credentials = ["username" => "sandstorm_dummy", "password" => "sandstorm_dummy"]; if (Auth::attempt($credentials)) { $settings = Setting::where('user_id', '=', Auth::user()->id)->first(); Session::put('ui_language', $settings->ui_language); return View::make('user.emergency_export'); } } else { // get permission via HTTP_X_SANDSTORM header $sandstorm_permissions = $_SERVER['HTTP_X_SANDSTORM_PERMISSIONS']; // Only when we are admin, we check and create users if ($sandstorm_permissions == "admin,write,read") { // check for admin user if (User::where('username', '=', 'sandstorm_admin')->count() == 0) { $sandstorm_admin = User::create(Input::except('_token', 'password_confirmation', 'ui_language')); if ($sandstorm_admin) { //make the first user an admin $sandstorm_admin->firstname = "sandstorm_admin"; $sandstorm_admin->lastname = " "; $sandstorm_admin->username = "******"; $sandstorm_admin->password = "******"; $sandstorm_admin->is_admin = 1; $sandstorm_admin->save(); $setting_sandstorm_admin = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_admin->id]); } } else { $sandstorm_admin = User::where('username', '=', 'sandstorm_admin'); } // Then the read & write user if (User::where('username', '=', 'sandstorm_readwrite')->count() == 0) { $sandstorm_readwrite = User::create(Input::except('_token', 'password_confirmation', 'ui_language')); if ($sandstorm_readwrite) { $sandstorm_readwrite->firstname = "sandstorm_readwrite"; $sandstorm_readwrite->lastname = " "; $sandstorm_readwrite->username = "******"; $sandstorm_readwrite->password = "******"; $sandstorm_readwrite->save(); $setting_sandstorm_readwrite = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_readwrite->id]); } } else { $sandstorm_readwrite = User::where('username', '=', 'sandstorm_readwrite'); } // Then the read only user if (User::where('username', '=', 'sandstorm_readonly')->count() == 0) { $sandstorm_readonly = User::create(Input::except('_token', 'password_confirmation', 'ui_language')); if ($sandstorm_readonly) { $sandstorm_readonly->firstname = "sandstorm_readonly"; $sandstorm_readonly->lastname = " "; $sandstorm_readonly->username = "******"; $sandstorm_readonly->password = "******"; $sandstorm_readonly->save(); $setting_sandstorm_readonly = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_readonly->id]); } } else { $sandstorm_readonly = User::where('username', '=', 'sandstorm_readonly'); } } // Now that the required users are there we create the default if (Notebook::all()->count() == 0 && Tag::all()->count() == 0 && Note::all()->count() == 0) { // Notebook ... $notebookCreate = new Notebook(); $notebookCreate->title = Lang::get('notebooks.welcome_notebook_title'); $notebookCreate->save(); $notebookCreate->users()->attach($sandstorm_readonly->id, ['umask' => PaperworkHelpers::UMASK_READONLY]); $notebookCreate->users()->attach($sandstorm_readwrite->id, ['umask' => PaperworkHelpers::UMASK_READWRITE]); $notebookCreate->users()->attach($sandstorm_admin->id, ['umask' => PaperworkHelpers::UMASK_OWNER]); // Tag ... $tagCreate = new Tag(); $tagCreate->title = Lang::get('notebooks.welcome_note_tag'); $tagCreate->visibility = 1; $tagCreate->user_id = $sandstorm_admin->id; $tagCreate->save(); // Note ... $noteCreate = new Note(); $versionCreate = new Version(['title' => Lang::get('notebooks.welcome_note_title'), 'content' => Lang::get('notebooks.welcome_note_content'), 'content_preview' => mb_substr(strip_tags(Lang::get('notebooks.welcome_note_content')), 0, 255), 'user_id' => $sandstorm_admin->id]); $versionCreate->save(); $noteCreate->version()->associate($versionCreate); $noteCreate->notebook_id = $notebookCreate->id; $noteCreate->save(); $noteCreate->users()->attach($sandstorm_readonly->id, ['umask' => PaperworkHelpers::UMASK_READONLY]); $noteCreate->users()->attach($sandstorm_readwrite->id, ['umask' => PaperworkHelpers::UMASK_READWRITE]); $noteCreate->users()->attach($sandstorm_admin->id, ['umask' => PaperworkHelpers::UMASK_OWNER]); $noteCreate->tags()->sync([$tagCreate->id]); } // login if ($sandstorm_permissions == "read") { $credentials = ["username" => "sandstorm_readonly", "password" => "sandstorm_readonly"]; } if ($sandstorm_permissions == "write,read") { $credentials = ["username" => "sandstorm_readwrite", "password" => "sandstorm_readwrite"]; } if ($sandstorm_permissions == "admin,write,read") { $credentials = ["username" => "sandstorm_admin", "password" => "sandstorm_admin"]; } if (Auth::attempt($credentials)) { $settings = Setting::where('user_id', '=', Auth::user()->id)->first(); Session::put('ui_language', $settings->ui_language); return Redirect::route("/"); } } }
public function storeCollection() { $validator = $this->getNewCollectionValidator(); if ($validator->passes()) { $data = Input::json(); $collection = Notebook::create(array('title' => $data->get('title'), 'type' => 1)); $collection->save(); $collection->users()->attach(Auth::user()->id, array('umask' => PaperworkHelpers::UMASK_OWNER)); $notebooks = $data->get('notebooks'); for ($i = 0; $i < count($notebooks); $i++) { $notebook = Notebook::find($notebooks[$i]); $notebook->parent_id = $collection->id; $notebook->save(); } return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $collection); } else { return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, $validator->getMessageBag()->toArray()); } }
function testNewNotebookPage() { $n = Notebook::getOneFromDb(['notebook_id' => 1001], $this->DB); $this->doLoginBasic(); $this->get('http://localhost/digitalfieldnotebooks/app_code/notebook.php?action=edit¬ebook_id=1001'); $this->checkBasicAsserts(); $this->click(util_lang('add_notebook_page')); $this->checkBasicAsserts(); $this->assertEltByIdHasAttrOfValue('form-edit-notebook-page-base-data', 'action', APP_ROOT_PATH . '/app_code/notebook_page.php'); // $this->showContent(); }
public function getNotebook() { return Notebook::getOneFromDb(['notebook_id' => $this->notebook_id], $this->dbConnection); }
function testCanActOnTarget_Pub_Verify() { $n2 = Notebook::getOneFromDb(['notebook_id' => 1003], $this->DB); // owned by 102 $actions_list = Action::getAllFromDb([], $this->DB); $actions = []; foreach ($actions_list as $act_elt) { $actions[$act_elt->name] = $act_elt; } $rat = new Role_Action_Target(['last_user_id' => 110, 'role_id' => 3, 'action_id' => 1, 'target_type' => 'notebook', 'target_id' => 1003, 'DB' => $this->DB]); $rat->updateDb(); $this->assertTrue($rat->matchesDb); // basic, field user $u = User::getOneFromDb(['user_id' => 101], $this->DB); $this->assertFalse($n2->flag_workflow_published); $this->assertFalse($n2->flag_workflow_validated); $this->assertFalse($u->canActOnTarget($actions['view'], $n2)); $this->assertFalse($u->canActOnTarget($actions['edit'], $n2)); $this->assertTrue($u->canActOnTarget($actions['create'], $n2)); $this->assertFalse($u->canActOnTarget($actions['delete'], $n2)); $this->assertFalse($u->canActOnTarget($actions['publish'], $n2)); $this->assertFalse($u->canActOnTarget($actions['verify'], $n2)); $n2->flag_workflow_published = true; $n2->updateDb(); $this->assertTrue($n2->matchesDb); $u->clearCaches(); $this->assertFalse($u->canActOnTarget($actions['view'], $n2)); $this->assertFalse($u->canActOnTarget($actions['edit'], $n2)); $this->assertTrue($u->canActOnTarget($actions['create'], $n2)); $this->assertFalse($u->canActOnTarget($actions['delete'], $n2)); $this->assertFalse($u->canActOnTarget($actions['publish'], $n2)); $this->assertFalse($u->canActOnTarget($actions['verify'], $n2)); $n2->flag_workflow_validated = true; $n2->updateDb(); $this->assertTrue($n2->matchesDb); $u->clearCaches(); $this->assertTrue($u->canActOnTarget($actions['view'], $n2)); $this->assertFalse($u->canActOnTarget($actions['edit'], $n2)); $this->assertTrue($u->canActOnTarget($actions['create'], $n2)); $this->assertFalse($u->canActOnTarget($actions['delete'], $n2)); $this->assertFalse($u->canActOnTarget($actions['publish'], $n2)); $this->assertFalse($u->canActOnTarget($actions['verify'], $n2)); }
public function getTargets() { switch ($this->target_type) { case 'global_notebook': return Notebook::getAllFromDb([], $this->dbConnection); break; case 'global_metadata': return Metadata_Structure::getAllFromDb([], $this->dbConnection); break; case 'global_plant': return Authoritative_Plant::getAllFromDb([], $this->dbConnection); break; case 'global_specimen': return Specimen::getAllFromDb([], $this->dbConnection); break; case 'notebook': return array(Notebook::getOneFromDb(['notebook_id' => $this->target_id], $this->dbConnection)); break; case 'metadata_structure': return array(Metadata_Structure::getOneFromDb(['metadata_structure_id' => $this->target_id], $this->dbConnection)); break; case 'plant': return array(Authoritative_Plant::getOneFromDb(['authoritative_id' => $this->target_id], $this->dbConnection)); break; case 'specimen': return array(Specimen::getOneFromDb(['specimen_id' => $this->target_id], $this->dbConnection)); break; default: return array(); } }