Ejemplo n.º 1
0
 /**
  * Sync with system project group
  *
  * @param      string $alias project alias
  * @param      string $prefix all project group names start with this
  * @return     void
  */
 public function sysGroup($alias = NULL, $prefix = 'pr-')
 {
     if ($alias) {
         $cn = $prefix . $alias;
         $group = new \Hubzero\User\Group();
         if (\Hubzero\User\Group::exists($cn)) {
             $group = \Hubzero\User\Group::getInstance($cn);
         } else {
             // Create system group
             $group->set('cn', $cn);
             $group->set('gidNumber', 0);
             $group->create();
             $group = \Hubzero\User\Group::getInstance($cn);
         }
         $members = $this->getIds($alias, $role = '0', 1);
         $authors = $this->getIds($alias, $role = '2', 1);
         $managers = $this->getIds($alias, $role = '1', 1);
         $all = array_merge($members, $managers, $authors);
         $all = array_unique($all);
         $group->set('members', $all);
         $group->set('managers', $managers);
         $group->set('type', 2);
         $group->set('published', 1);
         $group->set('discoverability', 1);
         $group->update();
     }
 }
Ejemplo n.º 2
0
 /**
  * Saves changes to a group or saves a new entry if creating
  *
  * @return void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $g = Request::getVar('group', array(), 'post', 'none', 2);
     $g = $this->_multiArrayMap('trim', $g);
     // Instantiate a Group object
     $group = new Group();
     // Is this a new entry or updating?
     $isNew = false;
     if (!$g['gidNumber']) {
         $isNew = true;
         // Set the task - if anything fails and we re-enter edit mode
         // we need to know if we were creating new or editing existing
         $this->_task = 'new';
         $before = new Group();
     } else {
         $this->_task = 'edit';
         // Load the group
         $group->read($g['gidNumber']);
         $before = clone $group;
     }
     $task = $this->_task == 'edit' ? 'edit' : 'create';
     if (!$this->authorize($task, $group)) {
         return;
     }
     // Check for any missing info
     if (!$g['cn']) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_ID'));
     }
     if (!$g['description']) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_MISSING_INFORMATION') . ': ' . Lang::txt('COM_GROUPS_TITLE'));
     }
     // Push back into edit mode if any errors
     if ($this->getError()) {
         $this->view->setLayout('edit');
         $this->view->group = $group;
         // Set any errors
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         // Output the HTML
         $this->view->display();
         return;
     }
     $g['cn'] = strtolower($g['cn']);
     // Ensure the data passed is valid
     if (!$this->_validCn($g['cn'], true)) {
         $this->setError(Lang::txt('COM_GROUPS_ERROR_INVALID_ID'));
     }
     //only check if cn exists if we are creating or have changed the cn
     if ($this->_task == 'new' || $group->get('cn') != $g['cn']) {
         if (Group::exists($g['cn'], true)) {
             $this->setError(Lang::txt('COM_GROUPS_ERROR_GROUP_ALREADY_EXIST'));
         }
     }
     // Push back into edit mode if any errors
     if ($this->getError()) {
         $this->view->setLayout('edit');
         $this->view->group = $group;
         // Set any errors
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         // Output the HTML
         $this->view->display();
         return;
     }
     // group params
     $gparams = new Registry($group->get('params'));
     $gparams->merge(new Registry($g['params']));
     // set membership control param
     $membership_control = isset($g['params']['membership_control']) ? 1 : 0;
     $gparams->set('membership_control', $membership_control);
     $params = $gparams->toString();
     // Set the group changes and save
     $group->set('cn', $g['cn']);
     $group->set('type', $g['type']);
     if ($isNew) {
         $group->create();
         $group->set('published', 1);
         $group->set('approved', 1);
         $group->set('created', Date::toSql());
         $group->set('created_by', User::get('id'));
         $group->add('managers', array(User::get('id')));
         $group->add('members', array(User::get('id')));
     }
     $group->set('description', $g['description']);
     $group->set('discoverability', $g['discoverability']);
     $group->set('join_policy', $g['join_policy']);
     $group->set('public_desc', $g['public_desc']);
     $group->set('private_desc', $g['private_desc']);
     $group->set('restrict_msg', $g['restrict_msg']);
     $group->set('logo', $g['logo']);
     $group->set('plugins', $g['plugins']);
     $group->set('discussion_email_autosubscribe', $g['discussion_email_autosubscribe']);
     $group->set('params', $params);
     $group->update();
     // create home page
     if ($isNew) {
         // create page
         $page = new Page(array('gidNumber' => $group->get('gidNumber'), 'parent' => 0, 'lft' => 1, 'rgt' => 2, 'depth' => 0, 'alias' => 'overview', 'title' => 'Overview', 'state' => 1, 'privacy' => 'default', 'home' => 1));
         $page->store(false);
         // create page version
         $version = new Page\Version(array('pageid' => $page->get('id'), 'version' => 1, 'content' => "<!-- {FORMAT:HTML} -->\n<p>[[Group.DefaultHomePage()]]</p>", 'created' => Date::of('now')->toSql(), 'created_by' => User::get('id'), 'approved' => 1));
         $version->store(false);
     }
     // Get plugins
     Event::trigger('groups.onGroupAfterSave', array($before, $group));
     // log edit
     Log::log(array('gidNumber' => $group->get('gidNumber'), 'action' => 'group_edited', 'comments' => 'edited by administrator'));
     // handle special groups
     if ($group->isSuperGroup()) {
         $this->_handleSuperGroup($group);
         // git lab stuff
         $this->_handSuperGroupGitlab($group);
     }
     // Output messsage and redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_GROUPS_SAVED'));
 }
Ejemplo n.º 3
0
 /**
  * Get a group's availability
  *
  * @param      object $group Group
  * @return     string
  */
 public function groupavailabilityTask($group = NULL)
 {
     //get the group
     $group = !is_null($group) ? $group : Request::getVar('group', '');
     $group = trim($group);
     if ($group == '') {
         return;
     }
     // Ensure the data passed is valid
     if ($group == 'new' || $group == 'browse' || !$this->_validCn($group) || Group::exists($group, true)) {
         $availability = false;
     } else {
         $availability = true;
     }
     if (Request::getVar('no_html', 0) == 1) {
         echo json_encode(array('available' => $availability));
         return;
     } else {
         return $availability;
     }
 }
Ejemplo n.º 4
0
 /**
  * Create a group
  *
  * @apiMethod POST
  * @apiUri    /groups
  * @apiParameter {
  * 		"name":          "cn",
  * 		"description":   "Group alias that appears in the url for group. Only lowercase alphanumeric chars allowed.",
  * 		"type":          "string",
  * 		"required":      true,
  * 		"default":       null
  * }
  * @apiParameter {
  * 		"name":          "title",
  * 		"description":   "Group title",
  * 		"type":          "string",
  * 		"required":      true,
  * 		"default":       null
  * }
  * @apiParameter {
  * 		"name":          "tags",
  * 		"description":   "Group tags",
  * 		"type":          "string (comma separated)",
  * 		"required":      false,
  * 		"default":       null
  * }
  * @apiParameter {
  * 		"name":          "public_description",
  * 		"description":   "Group public description",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       null
  * }
  * @apiParameter {
  * 		"name":          "private_description",
  * 		"description":   "Group private description",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       null
  * }
  * @apiParameter {
  * 		"name":          "join_policy",
  * 		"description":   "Membership join policy",
  * 		"type":          "string",
  * 		"required":      true,
  * 		"default":       "open",
  * 		"allowedValues": "open, restricted, invite_only, closed"
  * }
  * @apiParameter {
  * 		"name":          "discoverability",
  * 		"description":   "Is the group shown in hub searches/listings.",
  * 		"type":          "string",
  * 		"required":      true,
  * 		"default":       "visible",
  * 		"allowedValues": "visible, hidden"
  * }
  * @return  void
  */
 public function createTask()
 {
     $this->requiresAuthentication();
     $cn = Request::getWord('cn', '');
     $title = Request::getVar('title', '');
     $tags = Request::getVar('tags', '');
     $publicDesc = Request::getVar('public_description', '');
     $privateDesc = Request::getVar('private_description', '');
     $joinPolicy = strtolower(Request::getWord('join_policy', 'open'));
     $discoverability = Request::getWord('discoverability', 'visible');
     // var to hold errors
     $errors = array();
     // check for required fields (cn & title)
     if ($cn == '') {
         $errors[] = array('field' => 'cn', 'message' => Lang::txt('Group cn cannot be empty.'));
     }
     if ($title == '') {
         $errors[] = array('field' => 'title', 'message' => Lang::txt('Group title cannot be empty.'));
     }
     // check to make sure cn is valid & isnt taken
     if (!\Hubzero\Utility\Validate::group($cn, false)) {
         $errors[] = array('field' => 'cn', 'message' => Lang::txt('COM_GROUPS_SAVE_ERROR_INVALID_ID'));
     }
     if (\Hubzero\User\Group::exists($cn, false)) {
         $errors[] = array('field' => 'cn', 'message' => Lang::txt('COM_GROUPS_SAVE_ERROR_ID_TAKEN'));
     }
     // valid join policy
     $policies = array(0 => 'open', 1 => 'restricted', 2 => 'invite_only', 3 => 'closed');
     // make sure we have a valid policy
     if (!in_array($joinPolicy, $policies)) {
         $errors[] = array('field' => 'join_policy', 'message' => Lang::txt('Group "join_policy" value must be one of the following: %s', implode(', ', $policies)));
     }
     // valid discoverabilities
     $discoverabilities = array(0 => 'visible', 1 => 'hidden');
     // make sure we have a valid discoverability
     if (!in_array($discoverability, $discoverabilities)) {
         $errors[] = array('field' => 'discoverability', 'message' => Lang::txt('Group "discoverability" value must be one of the following: %s', implode(', ', $discoverabilities)));
     }
     // check for errors at this point
     if (!empty($errors)) {
         throw new Exception(Lang::txt('Validation Failed') . ': ' . implode("\n", $errors), 422);
     }
     // make sure we have a public desc of none was entered
     if ($publicDesc == '') {
         $publicDesc = $title;
     }
     // map the join policy & discoverability values to their int value
     $joinPolicy = array_search($joinPolicy, $policies);
     $discoverability = array_search($discoverability, $discoverabilities);
     // bind all our fields to the group object
     $group = new \Hubzero\User\Group();
     $group->set('cn', $cn);
     $group->set('type', 1);
     $group->set('published', 1);
     $group->set('approved', \App::get('component')->params('com_groups')->get('auto_approve', 1));
     $group->set('description', $title);
     $group->set('public_desc', $publicDesc);
     $group->set('private_desc', $privateDesc);
     $group->set('join_policy', $joinPolicy);
     $group->set('discoverability', $discoverability);
     $group->set('created', with(new Date('now'))->toSql());
     $group->set('created_by', User::get('id'));
     $group->add('managers', array(User::get('id')));
     $group->add('members', array(User::get('id')));
     if (!$group->create() || !$group->update()) {
         throw new Exception(Lang::txt('Failed to create group.'), 500);
     }
     $this->send($group);
 }
Ejemplo n.º 5
0
 /**
  * Return data on a group view (this will be some form of HTML)
  *
  * @param      object  $group      Current group
  * @param      string  $option     Name of the component
  * @param      string  $authorized User's authorization level
  * @param      integer $limit      Number of records to pull
  * @param      integer $limitstart Start of records to pull
  * @param      string  $action     Action to perform
  * @param      array   $access     What can be accessed
  * @param      array   $areas      Active area(s)
  * @return     array
  */
 public function onGroup($group, $option, $authorized, $limit = 0, $limitstart = 0, $action = '', $access, $areas = null)
 {
     $return = 'html';
     $active = 'wishlist';
     // The output array we're returning
     $arr = array('html' => '');
     //get this area details
     $this_area = $this->onGroupAreas();
     // Check if our area is in the array of areas we want to return results for
     if (is_array($areas) && $limit) {
         if (!in_array($this_area['name'], $areas)) {
             $return = 'metadata';
         }
     }
     //get the group members
     $members = $group->get('members');
     //if we want to return content
     if ($return == 'html') {
         //set group members plugin access level
         $group_plugin_acl = $access[$active];
         //if set to nobody make sure cant access
         if ($group_plugin_acl == 'nobody') {
             $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_OFF', ucfirst($active)) . '</p>';
             return $arr;
         }
         //check if guest and force login if plugin access is registered or members
         if (User::isGuest() && ($group_plugin_acl == 'registered' || $group_plugin_acl == 'members')) {
             $url = Route::url('index.php?option=com_groups&cn=' . $group->get('cn') . '&active=' . $active, false, true);
             App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url)), Lang::txt('GROUPS_PLUGIN_REGISTERED', ucfirst($active)), 'warning');
             return;
         }
         //check to see if user is member and plugin access requires members
         if (!in_array(User::get('id'), $members) && $group_plugin_acl == 'members' && $authorized != 'admin') {
             $arr['html'] = '<p class="info">' . Lang::txt('GROUPS_PLUGIN_REQUIRES_MEMBER', ucfirst($active)) . '</p>';
             return $arr;
         }
     }
     //instantiate database
     $database = App::get('db');
     // Set some variables so other functions have access
     $this->database = $database;
     $this->authorized = $authorized;
     $this->members = $members;
     $this->group = $group;
     $this->option = $option;
     $this->action = $action;
     //include com_wishlist files
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php';
     // Get the component parameters
     $this->config = Component::params('com_wishlist');
     Lang::load('com_wishlist') || Lang::load('com_wishlist', PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site');
     //set some more vars
     $gid = $this->group->get('gidNumber');
     $cn = $this->group->get('cn');
     $category = 'group';
     $admin = 0;
     // Configure controller
     $controller = new \Components\Wishlist\Site\Controllers\Wishlists();
     // Get filters
     $filters = $controller->getFilters(0);
     $filters['limit'] = $this->params->get('limit');
     // Load some objects
     $obj = new \Components\Wishlist\Tables\Wishlist($this->database);
     $objWish = new \Components\Wishlist\Tables\Wish($this->database);
     $objOwner = new \Components\Wishlist\Tables\Owner($this->database);
     // Get wishlist id
     $id = $obj->get_wishlistID($gid, $category);
     // Create a new list if necessary
     if (!$id) {
         // create private list for group
         if (\Hubzero\User\Group::exists($gid)) {
             $group = \Hubzero\User\Group::getInstance($gid);
             $id = $obj->createlist($category, $gid, 0, $cn . ' ' . Lang::txt('PLG_GROUPS_WISHLIST_NAME_GROUP'));
         }
     }
     // get wishlist data
     $wishlist = $obj->get_wishlist($id, $gid, $category);
     //if we dont have a wishlist display error
     if (!$wishlist) {
         $arr['html'] = '<p class="error">' . Lang::txt('PLG_GROUPS_WISHLIST_ERROR_WISHLIST_NOT_FOUND') . '</p>';
         return $arr;
     }
     // Get list owners
     $owners = $objOwner->get_owners($id, $this->config->get('group'), $wishlist);
     //if user is guest and wishlist isnt public
     //if (!$wishlist->public && User::isGuest())
     //{
     //	$arr['html'] = '<p class="warning">' . Lang::txt('The Group Wishlist is not a publicly viewable list.') . '</p>';
     //	return $arr;
     //}
     // Authorize admins & list owners
     if (User::authorise($option, 'manage')) {
         $admin = 1;
     }
     //authorized based on wishlist
     if (in_array(User::get('id'), $owners['individuals'])) {
         $admin = 2;
     } else {
         if (in_array(User::get('id'), $owners['advisory'])) {
             $admin = 3;
         }
     }
     //get item count
     $items = $objWish->get_count($id, $filters, $admin);
     $arr['metadata']['count'] = $items;
     if ($return == 'html') {
         // Get wishes
         $wishlist->items = $objWish->get_wishes($wishlist->id, $filters, $admin, User::getInstance());
         // HTML output
         // Instantiate a view
         $view = $this->view('default', 'browse');
         // Pass the view some info
         $view->option = $option;
         //$view->owners = $owners;
         $view->group = $this->group;
         $view->wishlist = $wishlist;
         $view->items = $items;
         $view->filters = $filters;
         $view->admin = $admin;
         $view->config = $this->config;
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         // Return the output
         $arr['html'] = $view->loadTemplate();
     }
     return $arr;
 }
Ejemplo n.º 6
0
 /**
  * Remove a user as owner
  *
  * @param   integer  $listid      List ID
  * @param   integer  $groupid     Group ID
  * @param   object   $admingroup  Admin group
  * @return  boolean  False if errors, true on success
  */
 public function delete_owner_group($listid, $groupid, $admingroup)
 {
     if ($listid === NULL or $groupid === NULL) {
         return false;
     }
     $nativegroups = $this->get_owner_groups($listid, $admingroup, '', 1);
     // cannot delete "native" owners (e.g. tool dev group)
     if (Group::exists($groupid) && !in_array($groupid, $nativegroups, true)) {
         $query = "DELETE FROM {$this->_tbl} WHERE wishlist=" . $this->_db->quote($listid) . " AND groupid=" . $this->_db->quote($groupid);
         $this->_db->setQuery($query);
         $this->_db->query();
         return true;
     }
 }
Ejemplo n.º 7
0
 /**
  * Write the list of group members
  *
  * @param      array   $new      New members
  * @param      unknown $id       Parameter description (if any) ...
  * @param      object  $database JDatabase
  * @param      string  &$err     Error message
  * @return     array
  */
 public function writeMemberGroups($new, $id, $database, &$err = '')
 {
     $toolhelper = new \Components\Tools\Helpers\Utils();
     $groups = is_array($new) ? $new : $toolhelper->makeArray($new);
     $grouplist = array();
     $invalid = '';
     $i = 0;
     if (count($groups) > 0) {
         foreach ($groups as $group) {
             if (\Hubzero\User\Group::exists($group)) {
                 if ($id) {
                     $grouplist[$i]->cn = $group;
                 } else {
                     $grouplist[$i] = $group;
                 }
                 $i++;
             } else {
                 $err = Lang::txt('CONTRIBTOOL_ERROR_GROUP_DOES_NOT_EXIST');
                 $invalid .= ' ' . $group . ';';
             }
         }
     }
     if ($err) {
         $err .= $invalid;
     }
     return $grouplist;
 }