/**
  * Constructor.
  */
 public function __construct(Role $role, AbstractRoleSubject $subject)
 {
     $this->role = $role;
     $details = array('role' => array('name' => $role->getTranslationKey()));
     if ($role->getWorkspace()) {
         $details['workspace'] = array('name' => $role->getWorkspace()->getName(), 'id' => $role->getWorkspace()->getId());
     }
     if ($subject instanceof User) {
         $details['receiverUser'] = array('firstName' => $subject->getFirstName(), 'lastName' => $subject->getLastName());
         $this->receiver = $subject;
     } else {
         $details['receiverGroup'] = array('name' => $subject->getName());
         $this->receiverGroup = $subject;
     }
     $this->details = $details;
     parent::__construct($this->getActionKey(), $details, $this->receiver, $this->receiverGroup, null, $role, $role->getWorkspace());
 }
 /**
  * Constructor.
  */
 public function __construct(Role $role, AbstractRoleSubject $subject)
 {
     $receiver = null;
     $receiverGroup = null;
     $details = array('role' => array('name' => $role->getTranslationKey()));
     if ($role->getWorkspace()) {
         $details['workspace'] = array('name' => $role->getWorkspace()->getName());
     }
     if ($subject instanceof User) {
         $details['receiverUser'] = array('firstName' => $subject->getFirstName(), 'lastName' => $subject->getLastName());
         $action = self::ACTION_USER;
         $receiver = $subject;
     } else {
         $details['receiverGroup'] = array('name' => $subject->getName());
         $action = self::ACTION_GROUP;
         $receiverGroup = $subject;
     }
     parent::__construct($action, $details, $receiver, $receiverGroup, null, $role, $role->getWorkspace());
 }
Beispiel #3
0
 /**
  * Returns if a role can be added to a RoleSubject.
  *
  * @param AbstractRoleSubject $ars
  * @param Role $role
  * @return bool
  */
 public function validateRoleInsert(AbstractRoleSubject $ars, Role $role)
 {
     $total = $this->countUsersByRoleIncludingGroup($role);
     //cli always win!
     if ($role->getName() === 'ROLE_ADMIN' && php_sapi_name() === 'cli' || $this->container->get('security.token_storage')->getToken() === null) {
         return true;
     }
     if ($role->getName() === 'ROLE_ADMIN' && !$this->container->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
         return false;
     }
     //if we already have the role, then it's ok
     if ($ars->hasRole($role->getName())) {
         return true;
     }
     if ($role->getWorkspace()) {
         $maxUsers = $role->getWorkspace()->getMaxUsers();
         $countByWorkspace = $this->container->get('claroline.manager.workspace_manager')->countUsers($role->getWorkspace(), true);
         if ($maxUsers <= $countByWorkspace) {
             return false;
         }
     }
     if ($ars instanceof User) {
         return $total < $role->getMaxUsers();
     }
     if ($ars instanceof Group) {
         $userCount = $this->userRepo->countUsersOfGroup($ars);
         $userWithRoleCount = $this->userRepo->countUsersOfGroupByRole($ars, $role);
         return $total + $userCount - $userWithRoleCount < $role->getMaxUsers();
     }
     return false;
 }
 public function sendMessageToAbstractRoleSubject(AbstractRoleSubject $subject, $content, $object, $sender = null, $withMail = true)
 {
     $users = array();
     if ($subject instanceof User) {
         $users[] = $subject;
     }
     if ($subject instanceof Group) {
         foreach ($subject->getUsers() as $user) {
             $users[] = $user;
         }
     }
     $message = $this->create($content, $object, $users, $sender);
     $this->send($message, true, $withMail);
 }
Beispiel #5
0
 public function __construct()
 {
     parent::__construct();
     $this->users = new ArrayCollection();
     $this->models = new ArrayCollection();
     $this->organizations = new ArrayCollection();
 }
Beispiel #6
0
 /**
  * Returns the user's roles as an array of string values (needed for
  * Symfony security checks). The roles owned by groups the user is a
  * member are included by default.
  *
  * @param boolean $areGroupsIncluded
  *
  * @return array[string]
  */
 public function getRoles($areGroupsIncluded = true)
 {
     $roleNames = parent::getRoles();
     if ($areGroupsIncluded) {
         foreach ($this->getGroups() as $group) {
             $roleNames = array_unique(array_merge($roleNames, $group->getRoles()));
         }
     }
     return $roleNames;
 }