Ejemplo n.º 1
0
 /**
  * Update group and membership info in underlying 'course-' group (group type 4)
  *
  * Method is called anytime after a course is saved
  *
  * @param $course - course object
  */
 public function onAfterStoreCourse($course)
 {
     // Get a new group object
     $group = new \Hubzero\User\Group();
     // If the course doesn't have a group id set, then we need to create a new group
     if (!$course->get('group_id')) {
         // Set some group info
         $group->set('cn', 'course-' . $course->cn);
         $group->create();
         $group->set('type', 4);
         // group type 4 = course
         // Set the new group gidNumber as the group_id in the course and update
         $course->set('group_id', $group->get('gidNumber'));
         $course->update();
     } else {
         $group->read($course->get('group_id'));
     }
     // Set the group description (in case it's been changed)
     $group->set('description', $course->get('description'));
     // Get all of the course members that are not yet group members (i.e. they need to be added to the group)
     $add = array_diff($course->get('members'), $group->get('members'));
     foreach ($add as $a) {
         $group->add('members', $a);
     }
     // Get all of the group members that are not members of the course (i.e. they need to be removed from the group)
     $remove = array_diff($group->get('members'), $course->get('members'));
     foreach ($remove as $r) {
         $group->remove('members', $r);
     }
     // Finally, update the group
     $group->update();
 }
Ejemplo n.º 2
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.º 3
0
 /**
  * Save an entry
  *
  * @return     void
  */
 public function saveTask()
 {
     $exportmap = array('@OPEN' => null, '@GROUP' => null, '@US' => 'us', '@us' => 'us', '@PU' => 'pu', '@pu' => 'pu', '@D1' => 'd1', '@d1' => 'd1');
     // set vars
     $tool = Request::getVar('tool', array(), 'post');
     $tool = array_map('trim', $tool);
     // Sanitize the input a bit
     $noHtmlFilter = \JFilterInput::getInstance();
     foreach ($tool as $i => $var) {
         $tool[$i] = $noHtmlFilter->clean($var);
     }
     $today = Date::toSql();
     $group_prefix = $this->config->get('group_prefix', 'app-');
     $dev_suffix = $this->config->get('dev_suffix', '_dev');
     // pass data from forms
     $id = Request::getInt('toolid', 0);
     $this->_action = Request::getVar('action', '');
     $comment = Request::getVar('comment', '');
     $editversion = Request::getVar('editversion', 'dev', 'post');
     //$toolname     = strtolower($tool['toolname']);
     $oldstatus = array();
     // Create a Tool Version object
     $objV = new \Components\Tools\Tables\Version($this->database);
     // Create a Tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     if ($id) {
         // make sure user is authorized to go further
         if (!$this->_checkAccess($id)) {
             App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
             return;
         }
     }
     if (!\Components\Tools\Models\Tool::validate($tool, $err, $id)) {
         // display form with errors
         //$title = Lang::txt(strtoupper($this->_option)).': '.Lang::txt('COM_TOOLS_EDIT_TOOL');
         //Document::setTitle($title);
         if (is_array($err)) {
             foreach ($err as $error) {
                 $this->setError($error);
             }
         } else {
             $this->setError($err);
         }
         if ($id) {
             // get tool status
             $obj->getToolStatus($id, $this->_option, $fstatus, $editversion);
             $tool['developers'] = $fstatus['developers'];
             $tool['membergroups'] = $fstatus['membergroups'];
             $tool['published'] = $fstatus['published'];
         }
         $this->editTask($tool);
         return;
     }
     $tool['vncGeometry'] = $tool['vncGeometryX'] . 'x' . $tool['vncGeometryY'];
     $tool['toolname'] = strtolower($tool['toolname']);
     $tool['developers'] = array_map('trim', explode(',', $tool['developers']));
     $tool['membergroups'] = array_map('trim', explode(',', $tool['membergroups']));
     $tool['hostreq'] = array_map('trim', explode(',', $tool['hostreq']));
     // save tool info
     if (!$id) {
         $hzt = \Components\Tools\Models\Tool::createInstance($tool['toolname']);
         $hzt->toolname = $tool['toolname'];
         $hzt->title = $tool['title'];
         $hzt->published = 0;
         $hzt->state = 1;
         $hzt->priority = 3;
         $hzt->registered = $today;
         $hzt->state_changed = $today;
         $hzt->registered_by = User::get('username');
     } else {
         $hzt = \Components\Tools\Models\Tool::getInstance($id);
     }
     // get tool id for newly registered tool
     $this->_toolid = $hzt->id;
     // save version info
     $hztv = $hzt->getRevision($editversion);
     if ($hztv) {
         $oldstatus = $hztv->toArray();
         $oldstatus['toolstate'] = $hzt->state;
         $oldstatus['membergroups'] = $tool['membergroups'];
         if ($id) {
             $oldstatus['developers'] = $obj->getToolDevelopers($id);
         }
     }
     // NEW: save github repo as param
     $params = '';
     $version = $objV->getVersionInfo($this->_toolid, 'dev');
     if ($version && !empty($version[0])) {
         $txt = new \Hubzero\Config\Registry($version[0]->params);
     } else {
         $txt = new \Hubzero\Config\Registry('');
     }
     $txt->set('github', $tool['github']);
     $ptype = empty($tool['publishType']) || $tool['publishType'] == 'standard' ? 'standard' : 'weber=';
     $txt->set('publishType', $ptype);
     $params = $txt->toString();
     if ($editversion == 'dev') {
         if ($hztv === false) {
             Log::debug(__FUNCTION__ . "() HZTV createInstance dev_suffix={$dev_suffix}");
             $hztv = \Components\Tools\Models\Version::createInstance($tool['toolname'], $tool['toolname'] . $dev_suffix);
             $oldstatus = $hztv->toArray();
             $oldstatus['toolstate'] = $hzt->state;
             $oldstatus['membergroups'] = $tool['membergroups'];
         }
         if ($id) {
             $oldstatus['developers'] = $obj->getToolDevelopers($id);
         }
         $invokedir = $this->config->get('invokescript_dir', DS . 'apps');
         $invokedir = rtrim($invokedir, DS);
         $hztv->toolid = $this->_toolid;
         $hztv->toolname = $tool['toolname'];
         $hztv->title = $tool['title'];
         $hztv->version = $tool['version'];
         $hztv->description = $tool['description'];
         $hztv->toolaccess = $tool['exec'];
         $hztv->codeaccess = $tool['code'];
         $hztv->wikiaccess = $tool['wiki'];
         $hztv->vnc_command = $invokedir . DS . $tool['toolname'] . DS . 'dev' . DS . 'middleware' . DS . 'invoke -T dev';
         $hztv->vnc_geometry = $tool['vncGeometry'];
         $hztv->exportControl = $exportmap[$tool['exec']];
         $hztv->state = 3;
         $hztv->instance = $tool['toolname'] . $dev_suffix;
         $hztv->mw = $this->config->get('default_mw', 'narwhal');
         $hztv->hostreq = $tool['hostreq'];
         $hztv->params = $params;
         $hzt->add('version', $hztv->instance);
     } else {
         if ($hztv) {
             $hztv->toolid = $this->_toolid;
             $hztv->toolname = $tool['toolname'];
             $hztv->title = $tool['title'];
             $hztv->version = $tool['version'];
             $hztv->description = $tool['description'];
             $hztv->toolaccess = $tool['exec'];
             $hztv->codeaccess = $tool['code'];
             $hztv->wikiaccess = $tool['wiki'];
             $hztv->vnc_geometry = $tool['vncGeometry'];
             $hztv->exportControl = $exportmap[$tool['exec']];
             $hztv->hostreq = $tool['hostreq'];
             $hzt->add('version', $hztv->instance);
         }
     }
     $this->_setTracAccess($tool['toolname'], $hztv->codeaccess, $hztv->wikiaccess);
     if ($this->_error) {
         App::abort(500, $this->_error);
         return;
     }
     // create/update developers group
     $gid = $hztv->getDevelopmentGroup();
     if (empty($gid)) {
         $hzg = new \Hubzero\User\Group();
         $hzg->cn = $group_prefix . strtolower($tool['toolname']);
         $hzg->create();
         $hzg->set('type', 2);
         $hzg->set('description', Lang::txt('COM_TOOLS_DELEVOPMENT_GROUP', $tool['title']));
         $hzg->set('created', Date::toSql());
         $hzg->set('created_by', User::get('id'));
     } else {
         $hzg = \Hubzero\User\Group::getInstance($gid);
     }
     $hzg->set('members', $tool['developers']);
     $hztrac = \Hubzero\Trac\Project::find_or_create('app:' . $tool['toolname']);
     $hztrac->add_group_permission('apps', array('WIKI_ADMIN', 'MILESTONE_ADMIN', 'BROWSER_VIEW', 'LOG_VIEW', 'FILE_VIEW', 'CHANGESET_VIEW', 'ROADMAP_VIEW', 'TIMELINE_VIEW', 'SEARCH_VIEW'));
     $hztrac->add_group_permission($hzg->cn, array('WIKI_ADMIN', 'MILESTONE_ADMIN', 'BROWSER_VIEW', 'LOG_VIEW', 'FILE_VIEW', 'CHANGESET_VIEW', 'ROADMAP_VIEW', 'TIMELINE_VIEW', 'SEARCH_VIEW'));
     $hztv->set('owner', $hzg->cn);
     $hztv->add('owner', 'apps');
     $hztv->set('member', $tool['membergroups']);
     // Add repo for new tools
     $auto_addrepo = $this->config->get('auto_addrepo', 1);
     if (!$id && $auto_addrepo) {
         $hzt->update();
         // Make sure tool exists in database or gensvn won't configure apachce access to it
         $hztv->update();
         // Make sure tool exists in database or gensvn won't configure apachce access to it
         // Run add repo
         $this->_addRepo($output, array('toolname' => $tool['toolname'], 'title' => $tool['title'], 'description' => $tool['description']));
         if ($output['class'] != 'error') {
             $hzt->state = 2;
             $hzt->update();
         }
     }
     // get ticket information
     if (empty($hzt->ticketid)) {
         $hzt->ticketid = $this->_createTicket($this->_toolid, $tool);
     }
     // create resource page
     $rid = \Components\Tools\Models\Tool::getResourceId($hzt->toolname, $hzt->id);
     if (empty($rid)) {
         include_once __DIR__ . DS . 'resource.php';
         $resource = new Resource();
         $rid = $resource->createPage($this->_toolid, $tool);
         // save authors by default
         //$objA = new \Components\Tools\Tables\Author($this->database);
         //if (!$id) { $objA->saveAuthors($tool['developers'], 'dev', $rid, '', $tool['toolname']); }
         if (!$id) {
             require_once __DIR__ . DS . 'authors.php';
             $controller = new Authors();
             $controller->saveTask(0, $rid, $tool['developers']);
             //$this->author_save(0, $rid, $tool['developers']);
         }
     }
     // display status page
     //$this->_task = 'status';
     //$this->_msg = $id ? Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_CHANGED'): Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_REGISTERED');
     $hzg->update();
     $hzt->update();
     $hztv->update();
     // @FIXME: look
     $status = $hztv->toArray();
     $status['toolstate'] = $hzt->state;
     $status['membergroups'] = $tool['membergroups'];
     $status['toolname'] = $tool['toolname'];
     if ($id) {
         $status['developers'] = $obj->getToolDevelopers($id);
     }
     // update history ticket
     if ($id && $oldstatus != $status && $editversion != 'current') {
         $this->_newUpdateTicket($hzt->id, $hzt->ticketid, $oldstatus, $status, $comment, 0, 1);
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=status&app=' . $hzt->toolname), $id ? Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_CHANGED') : Lang::txt('COM_TOOLS_NOTICE_TOOL_INFO_REGISTERED'));
 }
Ejemplo n.º 4
0
 /**
  * Save a group
  *
  * @param      string  $toolid   Tool ID
  * @param      string  $devgroup Group name
  * @param      array   $members  List of members
  * @param      boolean $exist    Group exists?
  * @return     boolean True if no errors
  */
 public function saveGroup($toolid = NULL, $devgroup, $members, $exist)
 {
     if (!$toolid or !$devgroup) {
         return false;
     }
     $members = \Components\Tools\Helpers\Utils::transform($members, 'uidNumber');
     $group = new \Hubzero\User\Group();
     if (\Hubzero\User\Group::exists($devgroup)) {
         $group->read($devgroup);
         $existing_members = \Components\Tools\Helpers\Utils::transform(Tool::getToolDevelopers($toolid), 'uidNumber');
         $group->set('members', $existing_members);
         $group->set('managers', $existing_managers);
     } else {
         $group->create();
         $group->set('type', 2);
         $group->set('published', 1);
         $group->set('discoverability', 0);
         $group->set('description', 'Dev group for tool ' . $toolid);
         $group->set('cn', $devgroup);
         $group->set('members', $existing_members);
         $group->set('managers', $existing_managers);
     }
     $group->update();
     if (!$exist) {
         $this->save($devgroup, $toolid, '1');
     }
     return true;
 }