/**
  *
  **/
 public static function onEnable($pluginId)
 {
     # TODO performance - use cache on success ?
     $role_persistence = new RolePersistence();
     $plugin_roles = $role_persistence->getAssignedPluginRoles($pluginId);
     $role_names = array_map(function ($role) {
         return $role->getRolename();
     }, $plugin_roles);
     if (!in_array('Nobody', $role_names)) {
         $message = _('Das OAuth-Plugin ist aktiviert, aber nicht für die Rolle "Nobody" freigegeben.');
         $details = array();
         $details[] = _('Dies behindert die Kommunikation externer Applikationen mit dem System.');
         $details[] = sprintf(_('Klicken Sie <a href="%s">hier</a>, um die Rollenzuweisung zu bearbeiten.'), URLHelper::getLink('dispatch.php/admin/role/assign_plugin_role/' . $pluginId));
         PageLayout::postMessage(Messagebox::info($message, $details));
     }
 }
Esempio n. 2
0
 /**
  * On enable set roles
  *
  * @param string $pluginid
  */
 public static function onEnable($pluginid)
 {
     $removeIds = array();
     foreach (RolePersistence::getAssignedPluginRoles($pluginid) as $role) {
         // Lets assume nobody changed root
         if ($role->roleid != 1) {
             // Add for delete
             $removeIds[] = $role->roleid;
         }
     }
     // Remove role assignment
     RolePersistence::deleteAssignedPluginRoles($pluginid, $removeIds);
 }
Esempio n. 3
0
 /**
  * Callback function being called before an action is executed.
  */
 function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     // AJAX request, so no page layout.
     if (Request::isXhr()) {
         $this->via_ajax = true;
         $this->set_layout(null);
         $request = Request::getInstance();
         foreach ($request as $key => $value) {
             $request[$key] = studip_utf8decode($value);
         }
         // Open base layout for normal view
     } else {
         $layout = $GLOBALS['template_factory']->open('layouts/base');
         $this->set_layout($layout);
     }
     $this->set_content_type('text/html;charset=windows-1252');
     $this->help_admin = $GLOBALS['perm']->have_perm('root') || RolePersistence::isAssignedRole($GLOBALS['user']->id, 'Hilfe-Administrator(in)');
 }
Esempio n. 4
0
 public function hosts_action()
 {
     //init
     LernmarktplatzHost::thisOne();
     $this->hosts = LernmarktplatzHost::findAll();
     foreach ($this->hosts as $host) {
         if (strpos($host['public_key'], "\r") !== false) {
             $host['public_key'] = str_replace("\r", "", $host['public_key']);
             $host->store();
         }
     }
     if (!function_exists("curl_init")) {
         PageLayout::postMessage(MessageBox::error(_("Ihr PHP hat kein aktiviertes cURL-Modul.")));
     }
     $plugin = PluginManager::getInstance()->getPluginInfo(get_class($this->plugin));
     $plugin_roles = RolePersistence::getAssignedPluginRoles($plugin['id']);
     $nobody_allowed = false;
     foreach ($plugin_roles as $role) {
         if (strtolower($role->rolename) === "nobody") {
             $nobody_allowed = true;
         }
     }
     if (!$nobody_allowed) {
         PageLayout::postMessage(MessageBox::error(_("Dieses Plugin ist nicht für nobody freigegeben. Damit kann sich dieser Marktplatz nicht mit anderen Stud.IP verbinden.")));
     }
     //zufällig einen Host nach Neuigkeiten fragen:
     if (count($this->hosts) > 1) {
         $index = rand(0, count($this->hosts) - 1);
         while ($this->hosts[$index]->isMe()) {
             $index++;
             if ($index >= count($this->hosts)) {
                 $index = 0;
             }
         }
         $this->askForHosts($this->hosts[$index]);
     }
 }
Esempio n. 5
0
 /**
  * Deletes a role assignment from the database
  *
  * @param StudIPUser[] $users
  * @param Role $role
  */
 public static function deleteRoleAssignment($user,$role, $institut_id = null)
 {
     if ($institut_id === null) {
         $stmt = DBManager::get()->prepare("DELETE FROM roles_user WHERE roleid=? AND userid=?");
         $stmt->execute(array($role->getRoleid(),$user->getUserid()));
     } else {
         $stmt = DBManager::get()->prepare("DELETE FROM roles_user WHERE roleid=? AND userid=? AND institut_id=?");
         $stmt->execute(array($role->getRoleid(),$user->getUserid(),$institut_id));
     }
     self::$user_roles = array();
 }
Esempio n. 6
0
 /**
  * Returns whether the user was assigned a certain role.
  *
  * @param string $role         The role to check
  * @param string $institute_id An optional institute_id
  * @return bool True if the user was assigned this role, false otherwise
  */
 public function hasRole($role, $institute_id = '')
 {
     return RolePersistence::isAssignedRole($this->user_id, $role, $institute_id);
 }
Esempio n. 7
0
 /**
  * Enter description here...
  *
  * @param string $assignedrole
  * @return boolean
  */
 public function isAssignedRole($assignedrole = '')
 {
     return RolePersistence::isAssignedRole($this->userid, $assignedrole);
 }
Esempio n. 8
0
 function assign_role_institutes_action($role_id, $user_id)
 {
     if (Request::isXhr()) {
         $this->set_layout(null);
         $this->set_content_type('text/html;charset=windows-1252');
         $this->response->add_header('X-No-Buttons', 1);
         $this->response->add_header('X-Title', PageLayout::getTitle());
         foreach (array_keys($_POST) as $param) {
             Request::set($param, studip_utf8decode(Request::get($param)));
         }
     }
     if (Request::submitted('add_institute') && ($institut_id = Request::option('institute_id'))) {
         $roles = RolePersistence::getAllRoles();
         $role = $roles[$role_id];
         $user = new StudIPUser($user_id);
         RolePersistence::assignRole($user, $role, Request::option('institute_id'));
         PageLayout::postMessage(MessageBox::success(_("Die Einrichtung wurde zugewiesen.")));
     }
     if ($remove_institut_id = Request::option('remove_institute')) {
         $roles = RolePersistence::getAllRoles();
         $role = $roles[$role_id];
         $user = new StudIPUser($user_id);
         RolePersistence::deleteRoleAssignment($user, $role, $remove_institut_id);
         PageLayout::postMessage(MessageBox::success(_("Die Einrichtung wurde entfernt.")));
     }
     $roles = RolePersistence::getAllRoles();
     $this->role = $roles[$role_id];
     $this->user = new User($user_id);
     $this->institutes = SimpleCollection::createFromArray(Institute::findMany(RolePersistence::getAssignedRoleInstitutes($user_id, $role_id)));
     $this->institutes->orderBy('name');
     $this->qsearch = QuickSearch::get("institute_id", new StandardSearch("Institut_id"));
     if (Request::isXhr()) {
         $this->qsearch->withoutButton();
     }
 }
Esempio n. 9
0
 public function __construct()
 {
     parent::__construct();
     $this->json_directory = $GLOBALS['STUDIP_BASE_PATH'] . '/doc/helpbar';
     $this->help_admin = isset($GLOBALS['perm']) && ($GLOBALS['perm']->have_perm('root') || RolePersistence::isAssignedRole($GLOBALS['user']->id, 'Hilfe-Administrator(in)'));
 }