Exemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Permission::truncate();
     $permissions = [[2, 'forum.view'], [3, 'forum.startDiscussion'], [3, 'discussion.reply'], [4, 'discussion.delete'], [4, 'discussion.rename'], [4, 'post.delete'], [4, 'post.edit'], [4, 'user.suspend']];
     foreach ($permissions as &$permission) {
         $permission = ['group_id' => $permission[0], 'permission' => $permission[1]];
     }
     Permission::insert($permissions);
 }
Exemplo n.º 2
0
 public function extend(Application $app)
 {
     PermissionModel::addPermission($this->permission);
     list($entity, $permission) = explode('.', $this->permission);
     if ($this->serialize) {
         $extender = new SerializeAttributes('Flarum\\Api\\Serializers\\' . ucfirst($entity) . 'Serializer', function (&$attributes, $model, $serializer) use($permission) {
             $attributes['can' . ucfirst($permission)] = (bool) $model->can($serializer->actor->getUser(), $permission);
         });
         $extender->extend($app);
     }
     foreach ($this->grant as $callback) {
         $model = 'Flarum\\Core\\Models\\' . ucfirst($entity);
         $model::grantPermission($permission, $callback);
     }
 }
Exemplo n.º 3
0
 /**
  * Define the relationship with the user's permissions.
  *
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function permissions()
 {
     $groupIds = [Group::GUEST_ID];
     if ($this->is_activated) {
         $groupIds = array_merge($groupIds, [Group::MEMBER_ID], $this->groups->lists('id'));
     }
     return Permission::whereIn('group_id', $groupIds);
 }