/**
  * @Route("/{id}", methods="DELETE", requirements={"id"="\d+"})
  * @Request({"id": "int"}, csrf=true)
  */
 public function deleteAction($id = 0)
 {
     if ($role = Role::find($id)) {
         $role->delete();
     }
     return ['message' => 'success'];
 }
Ejemplo n.º 2
0
 /**
  * Finds user's roles.
  *
  * @param  User $user
  * @return Role[]
  */
 public static function findRoles(User $user)
 {
     static $cached = [];
     if ($ids = array_diff($user->roles, array_keys($cached))) {
         $cached += Role::where('id IN (' . implode(',', $user->roles) . ')')->get();
     }
     return array_intersect_key($cached, array_flip($user->roles));
 }
Ejemplo n.º 3
0
 /**
  * @Request({"id": "int", "type": "string"})
  */
 public function editAction($id = 0, $type = null)
 {
     if (!$id) {
         $widget = Widget::create(['type' => $type]);
     } else {
         if (!($widget = Widget::find($id))) {
             App::abort(404, 'Widget not found.');
         }
     }
     return ['$view' => ['title' => __('Widgets'), 'name' => 'system/widget/edit.php'], '$data' => ['widget' => $widget, 'config' => ['menus' => App::menu(), 'nodes' => array_values(Node::query()->get()), 'roles' => array_values(Role::findAll()), 'types' => array_values(App::widget()->all()), 'positions' => array_values(App::position()->all())]]];
 }
Ejemplo n.º 4
0
 /**
  * @Route("category/edit", name="admin/category/edit")
  * @Access("download: manage categories")
  * @Request({"id": "int"})
  */
 public function editCategoryAction($id = 0)
 {
     if (!($category = Category::where(compact('id'))->related('files')->first())) {
         if ($id) {
             App::abort(404, __('Invalid file id.'));
         }
         $category = Category::create(['status' => 1, 'slug' => '']);
         $category->set('markdown', $this->download->config('markdown'));
     }
     return ['$view' => ['title' => $id ? __('Edit category') : __('Add category'), 'name' => 'bixie/download/admin/category.php'], '$data' => ['roles' => array_values(Role::findAll()), 'category' => $category], 'category' => $category];
 }
Ejemplo n.º 5
0
 /**
  * Gets the user roles.
  *
  * @param  User $user
  * @return array
  */
 protected function getRoles(User $user = null)
 {
     $roles = [];
     $self = $user && $user->id === App::user()->id;
     foreach (Role::where(['id <> ?'], [Role::ROLE_ANONYMOUS])->orderBy('priority')->get() as $role) {
         $r = $role->jsonSerialize();
         if ($role->isAuthenticated()) {
             $r['disabled'] = true;
         }
         if ($user && $role->isAdministrator() && (!App::user()->isAdministrator() || $self)) {
             $r['disabled'] = true;
         }
         $roles[$r['id']] = $r;
     }
     return $roles;
 }
 /**
  * @Route("/edit")
  * @Request({"id"})
  * @Access("site: manage site", admin=true)
  */
 public function editAction($id = '')
 {
     $userprofile = App::module('bixie/userprofile');
     if (is_numeric($id)) {
         $field = Field::find($id);
     } else {
         $field = Field::create();
         $field->setType($id);
     }
     if (!$field) {
         throw new NotFoundException(__('Field not found.'));
     }
     if (!($type = $userprofile->getType($field->type))) {
         throw new NotFoundException(__('Type not found.'));
     }
     return ['$view' => ['title' => __('Field'), 'name' => 'bixie/userprofile/admin/edit.php'], '$data' => ['field' => $field, 'type' => $type, 'roles' => array_values(Role::findAll())]];
 }
Ejemplo n.º 7
0
 /**
  * @Route("site/page/edit", name="page/edit")
  * @Access("site: manage site", admin=true)
  * @Request({"id", "menu"})
  */
 public function editAction($id = '', $menu = '')
 {
     if (is_numeric($id)) {
         if (!$id or !($node = Node::find($id))) {
             App::abort(404, 'Node not found.');
         }
     } else {
         $node = Node::create(['type' => $id]);
         if ($menu && !App::menu($menu)) {
             App::abort(404, 'Menu not found.');
         }
         $node->menu = $menu;
     }
     if (!($type = $this->site->getType($node->type))) {
         App::abort(404, 'Type not found.');
     }
     return ['$view' => ['title' => __('Pages'), 'name' => 'system/site/admin/edit.php'], '$data' => ['node' => $node, 'type' => $type, 'roles' => array_values(Role::findAll())]];
 }
 /**
  * @Route("/edit")
  * @Request({"id"})
  */
 public function editAction($id = '')
 {
     $formmaker = App::module('formmaker');
     if (is_numeric($id)) {
         $field = Field::find($id);
     } else {
         $field = Field::create();
         $field->setType($id);
     }
     if (!$field) {
         App::abort(404, __('Field not found.'));
     }
     if (!($type = $formmaker->getType($field->type))) {
         App::abort(404, __('Type not found.'));
     }
     //check fixed value
     foreach (['multiple', 'required'] as $key) {
         if ($type[$key] != -1) {
             $field->set($key, $type[$key]);
         }
     }
     return ['field' => $field, 'type' => $type, 'roles' => array_values(Role::findAll())];
 }
Ejemplo n.º 9
0
 /**
  * @Route("/edit")
  * @Request({"id"})
  * @Access("site: manage site", admin=true)
  */
 public function editAction($id = '')
 {
     /** @var \Bixie\Userprofile\UserprofileModule $userprofile */
     $userprofile = App::module('bixie/userprofile');
     if (is_numeric($id)) {
         $field = Field::find($id);
     } else {
         $field = Field::create();
         $field->setFieldType($id);
         $field->set('value', []);
         $field->set('data', []);
     }
     if (!$field) {
         throw new NotFoundException(__('Field not found.'));
     }
     if (!($type = $userprofile->getFieldType($field->type))) {
         throw new NotFoundException(__('Type not found.'));
     }
     $fixedFields = ['multiple', 'required', 'controls', 'repeatable'];
     if (!$field->id) {
         foreach ($type->getConfig() as $key => $value) {
             if (!in_array($key, $fixedFields)) {
                 $field->set($key, $value);
             }
         }
     }
     //check fixed value
     foreach ($fixedFields as $key) {
         if (!isset($type[$key])) {
             $type[$key] = 0;
         }
         if ($type[$key] != -1) {
             $field->set($key, $type[$key]);
         }
     }
     return ['$view' => ['title' => __('Field'), 'name' => 'bixie/userprofile/admin/edit.php'], '$data' => ['field' => $field, 'type' => $type, 'roles' => array_values(Role::findAll())]];
 }
Ejemplo n.º 10
0
 /**
  * @Route("/post/edit", name="post/edit")
  * @Access("blog: manage own posts || blog: manage all posts")
  * @Request({"id": "int"})
  */
 public function editAction($id = 0)
 {
     try {
         if (!($post = Post::where(compact('id'))->related('user')->first())) {
             if ($id) {
                 App::abort(404, __('Invalid post id.'));
             }
             $module = App::module('blog');
             $post = Post::create(['user_id' => App::user()->id, 'status' => Post::STATUS_DRAFT, 'date' => new \DateTime(), 'comment_status' => (bool) $module->config('posts.comments_enabled')]);
             $post->set('title', $module->config('posts.show_title'));
             $post->set('markdown', $module->config('posts.markdown_enabled'));
         }
         $user = App::user();
         if (!$user->hasAccess('blog: manage all posts') && $post->user_id !== $user->id) {
             App::abort(403, __('Insufficient User Rights.'));
         }
         $roles = App::db()->createQueryBuilder()->from('@system_role')->where(['id' => Role::ROLE_ADMINISTRATOR])->whereInSet('permissions', ['blog: manage all posts', 'blog: manage own posts'], false, 'OR')->execute('id')->fetchAll(\PDO::FETCH_COLUMN);
         $authors = App::db()->createQueryBuilder()->from('@system_user')->whereInSet('roles', $roles)->execute('id, username')->fetchAll();
         return ['$view' => ['title' => $id ? __('Edit Post') : __('Add Post'), 'name' => 'blog/admin/post-edit.php'], '$data' => ['post' => $post, 'statuses' => Post::getStatuses(), 'roles' => array_values(Role::findAll()), 'canEditAll' => $user->hasAccess('blog: manage all posts'), 'authors' => $authors], 'post' => $post];
     } catch (\Exception $e) {
         App::message()->error($e->getMessage());
         return App::redirect('@blog/post');
     }
 }
Ejemplo n.º 11
0
 /**
  * @Route("/edit")
  * @Request({"id"})
  */
 public function editAction($id = '')
 {
     /** @var \Bixie\Formmaker\FormmakerModule $formmaker */
     $formmaker = App::module('bixie/formmaker');
     if (is_numeric($id)) {
         $field = Field::find($id);
     } else {
         $field = Field::create();
         $field->setFieldType($id);
     }
     if (!$field) {
         App::abort(404, __('Field not found.'));
     }
     if (!($type = $formmaker->getFieldType($field->type))) {
         App::abort(404, __('Type not found.'));
     }
     //default values
     $fixedFields = ['multiple', 'required'];
     if (!$field->id) {
         foreach ($type->getConfig() as $key => $value) {
             if (!in_array($key, $fixedFields)) {
                 $field->set($key, $value);
             }
         }
     }
     //check fixed value
     foreach ($fixedFields as $key) {
         if ($type[$key] != -1) {
             $field->set($key, $type[$key]);
         }
     }
     return ['field' => $field, 'type' => $type, 'roles' => array_values(Role::findAll())];
 }