Пример #1
0
 /**
  * Saves page data as new page (will update page groups)
  * @param array $pagePost
  * @param array $pageLangPost
  * @param array $pageGroupsPost
  * @param array $pageInfoOther
  * @return Page|false
  */
 public function saveDuplicateFromPostData($pagePost, $pageLangPost, $pageGroupsPost, $pageInfoOther = [])
 {
     /** @var Page $duplicatePage */
     $duplicatePage = $this->replicate();
     $duplicatePage->setRelations([]);
     $pageLangPost['name'] = preg_replace('/\\s+Duplicate$/', '', $pageLangPost['name']) . ' Duplicate';
     $pageLangPost['url'] = preg_replace('/--v\\w+$/', '', $pageLangPost['url']) . '--v' . base_convert(microtime(true), 10, 36);
     $pageVersion = PageVersion::prepareNew();
     if ($duplicatePage->savePostData($pageVersion, $pagePost, $pageLangPost, $pageGroupsPost, $pageInfoOther)) {
         // duplicate role actions from original page
         foreach (UserRole::all() as $role) {
             /** @var \Illuminate\Database\Eloquent\Relations\BelongsToMany $pageActionsRelation */
             $pageActionsRelation = $role->page_actions();
             /** @var Collection $pageActions */
             $pageActions = $pageActionsRelation->where('page_id', '=', $duplicatePage->id)->get();
             if (!$pageActions->isEmpty()) {
                 foreach ($pageActions as $pageAction) {
                     $pageActionsRelation->attach($duplicatePage->id, ['action_id' => $pageAction->pivot->action_id, 'access' => $pageAction->pivot->access]);
                 }
             }
         }
         return $duplicatePage;
     } else {
         return false;
     }
 }
Пример #2
0
 public function postPages($role_id)
 {
     if (config('coaster::admin.advanced_permissions')) {
         $page_actions = AdminAction::where('controller_id', '=', 2)->where('inherit', '=', 0)->where('edit_based', '=', 0)->get();
         $actionIds = [];
         foreach ($page_actions as $action) {
             $actionIds[$action->action] = $action->id;
         }
         if (!config('coaster::admin.publishing')) {
             unset($actionIds['version-publish']);
         }
         $pages_permissions = Request::input('page');
         $this->_role_permissions = UserRole::find($role_id);
         // defaults
         $defaults = [];
         foreach ($actionIds as $action => $id) {
             $defaults[$id] = false;
         }
         foreach ($this->_role_permissions->actions as $action) {
             if (array_key_exists($action->id, $defaults)) {
                 $defaults[$action->id] = 1;
             }
         }
         // existing
         $existing = [];
         foreach ($this->_role_permissions->page_actions as $page_permission) {
             if (!isset($existing[$page_permission->pivot->page_id])) {
                 $existing[$page_permission->pivot->page_id] = [];
             }
             $existing[$page_permission->pivot->page_id][$page_permission->pivot->action_id] = $page_permission->pivot->access;
         }
         // save updates
         $pages = Page::where('parent', '>=', '0')->get();
         foreach ($pages as $page) {
             foreach ($actionIds as $action => $action_id) {
                 // get value entered
                 if (isset($pages_permissions[$page->id][$action])) {
                     $value = 'allow';
                 } else {
                     $value = 'deny';
                 }
                 // check if update is required
                 if (isset($existing[$page->id][$action_id])) {
                     if ($defaults[$action_id] && $value == 'allow' || !$defaults[$action_id] && $value == 'deny') {
                         // remove existing
                         $this->_role_permissions->page_actions()->newPivotStatementForId($page->id)->whereActionId($action_id)->delete();
                         if ($page->group_container > 0) {
                             $group = PageGroup::find($page->group_container);
                             foreach ($group->pages as $group_page) {
                                 $this->_role_permissions->page_actions()->newPivotStatementForId($group_page->id)->whereActionId($action_id)->delete();
                             }
                         }
                     } elseif ($existing[$page->id][$action_id] != $value) {
                         // update existing
                         $this->_role_permissions->page_actions()->newPivotStatementForId($page->id)->whereActionId($action_id)->update(['access' => $value]);
                         if ($page->group_container > 0) {
                             $group = PageGroup::find($page->group_container);
                             foreach ($group->pages as $group_page) {
                                 $this->_role_permissions->page_actions()->newPivotStatementForId($group_page->id)->whereActionId($action_id)->update(['access' => $value]);
                             }
                         }
                     }
                 } elseif (!$defaults[$action_id] && $value == 'allow' || $defaults[$action_id] && $value == 'deny') {
                     // add new page action
                     $this->_role_permissions->page_actions()->attach($page->id, ['action_id' => $action_id, 'access' => $value]);
                     if ($page->group_container > 0) {
                         $group = PageGroup::find($page->group_container);
                         foreach ($group->pages as $group_page) {
                             $this->_role_permissions->page_actions()->attach($group_page->id, ['action_id' => $action_id, 'access' => $value]);
                         }
                     }
                 }
             }
         }
         $this->addAlert('success', 'Page Permissions Updated');
     }
     $this->getPages($role_id);
 }
Пример #3
0
 public function postAdd()
 {
     $authUser = Auth::user();
     $v = Validator::make(Request::all(), array('email' => 'required|email', 'role' => 'required|integer'));
     $perm_issue = true;
     $role = UserRole::find(Request::input('role'));
     if (!empty($role) && $role->admin <= $authUser->role->admin) {
         $perm_issue = false;
     }
     if ($v->passes() && !$perm_issue) {
         $password = str_random(8);
         $new_user = new User();
         $new_user->email = Request::input('email');
         $new_user->role_id = Request::input('role');
         $new_user->password = Hash::make($password);
         $new_user->save();
         AdminLog::new_log('User \'' . $new_user->email . '\' added');
         Mail::send('coaster::emails.new_account', array('email' => $new_user->email, 'password' => $password), function ($message) use($new_user) {
             $message->from(config('coaster::site.email'));
             $message->to($new_user->email);
             $message->subject(config('coaster::site.name') . ': New Account Details');
         });
         $failures = Mail::failures();
         if (empty($failures)) {
             $email_message = 'An email has been sent to the new user with their login details.';
             $email_status = 'success';
         } else {
             $email_message = 'There was an error sending the login details to the new user.';
             $email_status = 'warning';
         }
         $this->layoutData['content'] = View::make('coaster::pages.users.add', array('success' => true, 'password' => $password, 'email_message' => $email_message, 'email_status' => $email_status));
     } else {
         FormMessage::set($v->messages());
         if ($perm_issue) {
             FormMessage::add('role', 'Don\'t have permission to create user with this role, or doesn\'t exist');
         }
         $this->getAdd();
     }
 }