* Copyright 1999-2001, VA Linux Systems, Inc.
* Copyright 2009-2010, Roland Mas
* Copyright 2010-2011, Franck Villaume - Capgemini
- * Copyright 2010-2011, Alain Peyrat - Alcatel-Lucent
+ * Copyright 2010-2012, Alain Peyrat - Alcatel-Lucent
+ * Copyright 2012, Franck Villaume - TrivialDev
* http://fusionforge.org
*
- * This file is part of FusionForge.
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
*
- * FusionForge is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * FusionForge is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once $gfcommon.'tracker/ArtifactTypes.class.php';
//create a common set of group objects
//saves a little wear on the database
- //automatically checks group_type and
+ //automatically checks group_type and
//returns appropriate object
-
+
global $GROUP_OBJ;
if (!isset($GROUP_OBJ["_".$group_id."_"])) {
if ($res) {
function &group_get_objects($id_arr) {
global $GROUP_OBJ;
-
+
// Note: if we don't do this, the result may be corrupted
$fetch = array();
$return = array();
-
+
foreach ($id_arr as $id) {
//
// See if this ID already has been fetched in the cache
return group_get_object(db_result($res, 0, 'group_id'), $res);
}
+/**
+ * get_public_active_projects_asc() - Get a list of rows for public active projects (initially in trove/full_list)
+ *
+ * @param int Opional Maximum number of rows to limit query length
+ */
+function get_public_active_projects_asc($max_query_limit = -1) {
+
+ $res_grp = db_query_params ('
+ SELECT group_id, group_name, unix_group_name, short_description, register_time
+ FROM groups
+ WHERE status = $1 AND type_id=1 AND group_id>4 AND register_time > 0
+ ORDER BY group_name ASC
+ ',
+ array ('A'),
+ $max_query_limit);
+ $projects = array();
+ while ($row_grp = db_fetch_array($res_grp)) {
+ if (!forge_check_perm ('project_read', $row_grp['group_id'])) {
+ continue ;
+ }
+ $projects[] = $row_grp;
+ }
+ return $projects;
+}
+
+
class Group extends Error {
/**
* Associative array of data from db.
- *
+ *
* @var array $data_array.
*/
var $data_array;
/**
* array of User objects.
- *
+ *
* @var array $membersArr.
*/
var $membersArr;
/**
* Artifact types result handle.
- *
+ *
* @var int $types_res.
*/
var $types_res;
/**
* Associative array of data for plugins.
- *
+ *
* @var array $plugins_data.
*/
var $plugins_data;
* create - Create new group.
*
* This method should be called on empty Group object.
+ * It will add an entry for a pending group/project (status 'P')
*
* @param object The User object.
* @param string The full name of the user.
} else if (strlen($description)<10) {
$this->setError(_('Describe in a more comprehensive manner your project.'));
return false;
- } else if (strlen($description)>255) {
- $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
- return false;
} else {
+
+ // Check if sys_use_project_vhost for homepage
+ if (forge_get_config('use_project_vhost')) {
+ $homepage = $unix_name.".".forge_get_config('web_host');
+ } else {
+ $homepage = forge_get_config('web_host')."/www/".$unix_name."/";
+ }
+
db_begin();
$res = db_query_params('
INSERT INTO groups(
group_name,
- is_public,
unix_group_name,
short_description,
http_domain,
scm_box,
register_purpose,
register_time,
- enable_anonscm,
rand_hash,
built_from_template
)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)',
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)',
array (htmlspecialchars ($group_name),
- $is_public,
$unix_name,
htmlspecialchars($description),
- $unix_name.".".forge_get_config('web_host'),
- $unix_name.".".forge_get_config('web_host'),
+ $homepage,
+ $homepage,
'P',
$unix_box,
$scm_box,
htmlspecialchars($purpose),
time(),
- $is_public,
md5(util_randbytes()),
$built_from_template));
if (!$res || db_affected_rows($res) < 1) {
return false;
}
- if (USE_PFO_RBAC) {
- $gjr = new GroupJoinRequest($this);
- $gjr->create($user->getID(),
- 'Fake GroupJoinRequest to store the creator of a project',
- false);
- } else {
- //
- // Now, make the user an admin
- //
- $res=db_query_params('INSERT INTO user_group (user_id, group_id, admin_flags,
- cvs_flags, artifact_flags, forum_flags, role_id)
- VALUES ($1, $2, $3, $4, $5, $6, $7)',
- array($user->getID(),
- $id,
- 'A',
- 1,
- 2,
- 2,
- 1));
- if (!$res || db_affected_rows($res) < 1) {
- $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
- db_rollback();
- return false;
- }
- }
+ $gjr = new GroupJoinRequest($this);
+ $gjr->create($user->getID(),
+ 'Fake GroupJoinRequest to store the creator of a project',
+ false);
$hook_params = array();
$hook_params['group'] = $this;
$res = db_query_params('
UPDATE groups
- SET is_public=$1, type_id=$2,
- unix_box=$3, http_domain=$4
- WHERE group_id=$5',
- array($is_public,
- $type_id,
+ SET type_id=$1, unix_box=$2, http_domain=$3
+ WHERE group_id=$4',
+ array($type_id,
$unix_box,
$http_domain,
$this->getID()));
}
// Log the audit trail
- if ($is_public != $this->isPublic()) {
- $this->addHistory('is_public', $this->isPublic());
- }
if ($type_id != $this->data_array['type_id']) {
$this->addHistory('type_id', $this->data_array['type_id']);
}
function update(&$user, $group_name, $homepage, $short_description, $use_mail, $use_survey, $use_forum,
$use_pm, $use_pm_depend_box, $use_scm, $use_news, $use_docman,
$new_doc_address, $send_all_docs, $logo_image_id,
- $use_ftp, $use_tracker, $use_frs, $use_stats, $tags, $is_public) {
+ $use_ftp, $use_tracker, $use_frs, $use_stats, $tags, $use_activity, $is_public) {
$perm =& $this->getPermission();
if (!$use_stats) {
$use_stats = 0;
}
+ if (!$use_activity) {
+ $use_activity = 0;
+ }
if (!$send_all_docs) {
$send_all_docs = 0;
}
db_begin();
- //XXX not yet actived logo_image_id='$logo_image_id',
+ //XXX not yet actived logo_image_id='$logo_image_id',
$res = db_query_params('UPDATE groups
SET group_name=$1,
homepage=$2,
use_pm_depend_box=$8,
use_scm=$9,
use_news=$10,
- is_public=$11,
- new_doc_address=$12,
- send_all_docs=$13,
- use_ftp=$14,
- use_tracker=$15,
- use_frs=$16,
- use_stats=$17
+ new_doc_address=$11,
+ send_all_docs=$12,
+ use_ftp=$13,
+ use_tracker=$14,
+ use_frs=$15,
+ use_stats=$16,
+ use_activity=$17
WHERE group_id=$18',
- array(htmlspecialchars($group_name),
- $homepage,
- htmlspecialchars($short_description),
- $use_mail,
- $use_survey,
- $use_forum,
- $use_pm,
- $use_pm_depend_box,
- $use_scm,
- $use_news,
- $is_public,
- $new_doc_address,
- $send_all_docs,
- $use_ftp,
- $use_tracker,
- $use_frs,
- $use_stats,
- $this->getID()));
+ array(htmlspecialchars($group_name),
+ $homepage,
+ htmlspecialchars($short_description),
+ $use_mail,
+ $use_survey,
+ $use_forum,
+ $use_pm,
+ $use_pm_depend_box,
+ $use_scm,
+ $use_news,
+ $new_doc_address,
+ $send_all_docs,
+ $use_ftp,
+ $use_tracker,
+ $use_frs,
+ $use_stats,
+ $use_activity,
+ $this->getID()));
- if (!$res) {
+ if (!$res || db_affected_rows($res) < 1) {
$this->setError(sprintf(_('Error updating project information: %s'), db_error()));
db_rollback();
return false;
/**
* getStatus - the status code.
*
- * Statuses char include I,H,A,D.
+ * Statuses char include I,H,A,D,P.
+ * TODO : document what these mean :
+ * A: Active
+ * H: Hold
+ * P: Pending
+ * I: Incomplete
+ * D: ?
*/
function getStatus() {
return $this->data_array['status'];
/**
* setStatus - set the status code.
*
- * Statuses include I,H,A,D.
+ * Statuses include I,H,A,D,P.
+ * TODO : document what these mean :
+ * A: Active
+ * H: Hold
+ * P: Pending
+ * I: Incomplete
+ * D: ?
*
* @param object User requesting operation (for access control).
* @param string Status value.
// Check that status transition is valid
if ($this->getStatus() != $status
- && !$allowed_status_changes[$this->getStatus().$status]) {
- $this->setError(_('Invalid Status Change'));
+ && !array_key_exists($this->getStatus(). $status, $allowed_status_changes)) {
+ $this->setError(_('Invalid Status Change From: ').$this->getStatus(). _(' To: '.$status));
return false;
}
}
/**
- * isPublic - Simply returns the is_public flag from the database.
+ * isPublic - Wrapper around RBAC to check if a project is anonymously readable
*
* @return boolean is_public.
*/
function isPublic() {
- return $this->data_array['is_public'];
+ $ra = RoleAnonymous::getInstance() ;
+ return $ra->hasPermission('project_read', $this->getID());
}
/**
*/
function &getAdmins() {
$roles = RBACEngine::getInstance()->getRolesByAllowedAction ('project_admin', $this->getID());
-
+
$user_ids = array();
foreach ($roles as $role) {
|| $role->getHomeProject()->getID() != $this->getID()) {
continue;
}
-
+
foreach ($role->getUsers() as $u) {
$user_ids[] = $u->getID();
}
* @return boolean enable_scm.
*/
function enableAnonSCM() {
- if (USE_PFO_RBAC) {
- $r = RoleAnonymous::getInstance();
- return $r->hasPermission('scm', $this->getID(), 'read');
- } else {
- if ($this->isPublic() && $this->usesSCM()) {
- return $this->data_array['enable_anonscm'];
- } else {
- return false;
- }
- }
+ $r = RoleAnonymous::getInstance();
+ return $r->hasPermission('scm', $this->getID(), 'read');
}
function SetUsesAnonSCM($booleanparam) {
db_begin();
$booleanparam = $booleanparam ? 1 : 0;
- if (USE_PFO_RBAC) {
- $r = RoleAnonymous::getInstance();
- $r->setSetting('scm', $this->getID(), $booleanparam);
- db_commit();
- } else {
- $res = db_query_params('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
- array($booleanparam, $this->getID()));
- if ($res) {
- $this->data_array['enable_anonscm'] = $booleanparam;
- db_commit();
- } else {
- db_rollback();
- return false;
- }
- }
+ $r = RoleAnonymous::getInstance();
+ $r->setSetting('scm', $this->getID(), $booleanparam);
+ db_commit();
}
/**
}
}
+ /**
+ * usesActivity - whether or not this group has opted to display Project Activities.
+ *
+ * @return boolean uses_activities.
+ */
+ function usesActivity() {
+ if (forge_get_config('use_activity')) {
+ return $this->data_array['use_activity'];
+ } else {
+ return false;
+ }
+ }
+
/**
* usesForum - whether or not this group has opted to use discussion forums.
*
}
/**
- * usesPlugin - returns true if the group uses a particular plugin
+ * usesPlugin - returns true if the group uses a particular plugin
*
* @param string name of the plugin
* @return boolean whether plugin is being used or not
*
* @param string name of the plugin
* @param boolean the new state
- * @return string database result
+ * @return string database result
*/
function setPluginUse($pluginname, $val=true) {
if ($val == $this->usesPlugin($pluginname)) {
$plugin_id));
return $res;
}
+ $this->normalizeAllRoles () ;
}
/**
* @return string homepage URL.
*/
function getHomePage() {
+ if (!preg_match("/^[a-zA-Z][a-zA-Z0-9+.-]*:/",
+ $this->data_array['homepage'])) {
+ $this->data_array['homepage'] = util_url_prefix() .
+ $this->data_array['homepage'];
+ }
return $this->data_array['homepage'];
}
$sql = 'INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
$res = db_query_params($sql, array($this->getID(), $tag));
if (!$res) {
- $this->setError(_('Setting tags: ').db_error());
+ $this->setError(_('Setting tags:') . ' ' .
+ db_error());
db_rollback();
return false;
}
$this->setError(_('Cannot Delete System Group'));
return false;
}
- $perm =& $this->getPermission();
+ $perm = $this->getPermission();
if (!$perm || !is_object($perm)) {
$this->setPermissionDeniedError();
return false;
return false;
}
- //db_begin();
+ db_begin();
//
// Remove all the members
//
- $members =& $this->getMembers();
+ $members = $this->getMembers();
foreach ($members as $i) {
if(!$this->removeUser($i->getID())) {
$this->setError(_('Could not properly remove member:').' '.$i->getID());
return false;
}
}
- // Failsafe until user_group table is gone
- $res = db_query_params('DELETE FROM user_group WHERE group_id=$1',
- array($this->getID()));
- // unlink roles to this project
- if ($this->isPublic()) {
- $ra = RoleAnonymous::getInstance();
- $rl = RoleLoggedIn::getInstance();
- $ra->unlinkProject($this);
- $rl->unlinkProject($this);
- }
+ // unlink roles from this project
+ $ra = RoleAnonymous::getInstance();
+ $rl = RoleLoggedIn::getInstance();
+ $ra->unlinkProject($this);
+ $rl->unlinkProject($this);
// @todo : unlink all the other roles created in the project...
//
// Delete Trackers
//
$atf = new ArtifactTypeFactory($this);
- $at_arr =& $atf->getArtifactTypes();
+ $at_arr = $atf->getArtifactTypes();
foreach ($at_arr as $i) {
if (!is_object($i)) {
continue;
// Delete Forums
//
$ff = new ForumFactory($this);
- $f_arr =& $ff->getForums();
+ $f_arr = $ff->getForums();
foreach ($f_arr as $i) {
if (!is_object($i)) {
continue;
// Delete Subprojects
//
$pgf = new ProjectGroupFactory($this);
- $pg_arr =& $pgf->getProjectGroups();
+ $pg_arr = $pgf->getProjectGroups();
foreach ($pg_arr as $i) {
if (!is_object($i)) {
continue;
//
$res = db_query_params('SELECT * FROM frs_package WHERE group_id=$1',
array($this->getID()));
+ if (!$res) {
+ $this->setError(_('Error FRS Packages: ').db_error());
+ db_rollback();
+ return false;
+ }
+
while ($arr = db_fetch_array($res)) {
$frsp=new FRSPackage($this, $arr['package_id'], $arr);
if (!$frsp->delete(1, 1)) {
db_rollback();
return false;
}
-
+
//
// Delete group history
//
}
if (!$i->delete()) {
$this->setError(_('Could not properly delete the survey'));
+ db_rollback();
return false;
}
}
}
if (!$i->delete()) {
$this->setError(_('Could not properly delete the survey questions'));
+ db_rollback();
return false;
}
}
// Delete Mailing List Factory
//
$mlf = new MailingListFactory($this);
- $ml_arr =& $mlf->getMailingLists();
+ $ml_arr = $mlf->getMailingLists();
foreach ($ml_arr as $i) {
if (!is_object($i)) {
continue;
}
if (!$i->delete(1,1)) {
$this->setError(_('Could not properly delete the mailing list'));
+ db_rollback();
return false;
}
}
return false;
}
+ // Delete entry in groups.
$res = db_query_params('DELETE FROM groups WHERE group_id=$1',
array($this->getID()));
if (!$res) {
$hook_params['group'] = $this;
$hook_params['group_id'] = $this->getID();
plugin_hook("group_delete", $hook_params);
-
+
if (forge_get_config('upload_dir') != '' && $this->getUnixName()) {
exec('/bin/rm -rf '.forge_get_config('upload_dir').'/'.$this->getUnixName().'/');
}
// Delete reporting
//
$res = db_query_params('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
- array ($this->getID()));
-//echo 'rep_group_act_monthly'.db_error();
+ array ($this->getID()));
+ //echo 'rep_group_act_monthly'.db_error();
$res = db_query_params('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
- array ($this->getID()));
-//echo 'rep_group_act_weekly'.db_error();
+ array ($this->getID()));
+ //echo 'rep_group_act_weekly'.db_error();
$res = db_query_params('DELETE FROM rep_group_act_daily WHERE group_id=$1',
- array ($this->getID()));
-//echo 'rep_group_act_daily'.db_error();
+ array ($this->getID()));
+ //echo 'rep_group_act_daily'.db_error();
unset($this->data_array);
return true;
}
//
$user_id = db_result($res_newuser,0,'user_id');
- $role = new Role($this,$role_id);
+ $role = new Role($this, $role_id);
if (!$role || !is_object($role)) {
$this->setError(_('Error Getting Role Object'));
db_rollback();
db_rollback();
return false;
}
-
- if (USE_PFO_RBAC) {
- $role->addUser(user_get_object ($user_id)) ;
- if (!$SYS->sysCheckCreateGroup($this->getID())){
- $this->setError($SYS->getErrorMessage());
- db_rollback();
- return false;
- }
- if (!$SYS->sysCheckCreateUser($user_id)) {
- $this->setError($SYS->getErrorMessage());
- db_rollback();
- return false;
- }
- } else {
- //
- // if not already a member, add them
- //
- $res_member = db_query_params('SELECT user_id
- FROM user_group
- WHERE user_id=$1 AND group_id=$2',
- array($user_id, $this->getID()));
-
- if (db_numrows($res_member) < 1) {
- //
- // Create this user's row in the user_group table
- //
- $res = db_query_params('INSERT INTO user_group
- (user_id,group_id,admin_flags,forum_flags,project_flags,
- doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
- array($user_id,
- $this->getID(),
- '',
- 0,
- 0,
- 0,
- 1,
- 100,
- 0,
- 0));
-
- //verify the insert worked
- if (!$res || db_affected_rows($res) < 1) {
- $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
- db_rollback();
- return false;
- }
- //
- // check and create if group doesn't exists
- //
-//echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
- if (!$SYS->sysCheckCreateGroup($this->getID())){
- $this->setError($SYS->getErrorMessage());
- db_rollback();
- return false;
- }
- //
- // check and create if user doesn't exists
- //
-//echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
- if (!$SYS->sysCheckCreateUser($user_id)) {
- $this->setError($SYS->getErrorMessage());
- db_rollback();
- return false;
- }
- //
- // Role setup
- //
-//echo "<h2>Group::addUser role->setUser($user_id)</h2>";
- if (!$role->setUser($user_id)) {
- $this->setError('addUser::role::setUser'.$role->getErrorMessage());
- db_rollback();
- return false;
- }
- } else {
- //
- // user was already a member
- // make sure they are set up
- //
- $user= user_get_object($user_id,$res_newuser);
- $user->fetchData($user->getID());
- $role = new Role($this,$role_id);
- if (!$role || !is_object($role)) {
- $this->setError(_('Error Getting Role Object'));
- db_rollback();
- return false;
- } elseif ($role->isError()) {
- $this->setError('addUser::roleget::'.$role->getErrorMessage());
- db_rollback();
- return false;
- }
-//echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
- if (!$role->setUser($user_id)) {
- $this->setError('addUser::role::setUser'.$role->getErrorMessage());
- db_rollback();
- return false;
- }
- //
- // set up their system info
- //
-//echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
- if (!$SYS->sysCheckCreateUser($user_id)) {
- $this->setError($SYS->getErrorMessage());
- db_rollback();
- return false;
- }
+ $role->addUser(user_get_object($user_id)) ;
+ if (!$SYS->sysCheckCreateGroup($this->getID())){
+ $this->setError($SYS->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+ if (!$SYS->sysCheckCreateUser($user_id)) {
+ $this->setError($SYS->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+ if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
+ $this->setError($SYS->getErrorMessage());
+ db_rollback();
+ return false;
}
- } // USE_PFO_RBAC
} else {
//
// user doesn't exist
$hook_params['group'] = $this;
$hook_params['group_id'] = $this->getID();
- $hook_params['user'] = &user_get_object($user_id);
+ $hook_params['user'] = user_get_object($user_id);
$hook_params['user_id'] = $user_id;
plugin_hook ("group_adduser", $hook_params);
-
+
//
// audit trail
//
/**
* removeUser - controls removing a user from a group.
- *
+ *
* Users can remove themselves.
*
* @param int The ID of the user to remove.
global $SYS;
if ($user_id != user_getid()
- || !forge_check_perm('project_admin', $this->getID())) {
+ && !forge_check_perm('project_admin', $this->getID())) {
$this->setPermissionDeniedError();
return false;
}
db_begin();
- if (USE_PFO_RBAC) {
- $user = user_get_object($user_id);
- $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user);
- $found_role = NULL;
- foreach ($roles as $role) {
- if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
- $found_role = $role;
- break;
- }
- }
- if ($found_role == NULL) {
- $this->setError(sprintf(_('ERROR: User not removed: %s')));
- db_rollback();
- return false;
- }
- $found_role->removeUser($user);
- if (!$SYS->sysGroupCheckUser($this->getID(), $user_id)) {
- $this->setError($SYS->getErrorMessage());
- db_rollback();
- return false;
- }
-
- } else {
- $res = db_query_params('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
- array($this->getID(),
- $user_id));
- if (!$res || db_affected_rows($res) < 1) {
- $this->setError(_('ERROR: User not removed:').' '.db_error());
- db_rollback();
- return false;
+ $user = user_get_object($user_id);
+ $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user);
+ $found_role = NULL;
+ foreach ($roles as $role) {
+ if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
+ $found_role = $role;
+ break;
}
}
-
+ if ($found_role == NULL) {
+ $this->setError(sprintf(_('ERROR: User not removed: %s')));
+ db_rollback();
+ return false;
+ }
+ $found_role->removeUser($user);
+ if (!$SYS->sysGroupCheckUser($this->getID(), $user_id)) {
+ $this->setError($SYS->getErrorMessage());
+ db_rollback();
+ return false;
+ }
+
//
// reassign open artifacts to id=100
//
$res = db_query_params('UPDATE artifact SET assigned_to=100
- WHERE group_artifact_id
- IN (SELECT group_artifact_id
- FROM artifact_group_list
+ WHERE group_artifact_id
+ IN (SELECT group_artifact_id
+ FROM artifact_group_list
WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
array($this->getID(),
$user_id));
//
// reassign open tasks to id=100
- // first have to purge any assignments that would cause
+ // first have to purge any assignments that would cause
// conflict with existing assignment to 100
//
$res = db_query_params('DELETE FROM project_assigned_to
- WHERE project_task_id IN (SELECT pt.project_task_id
- FROM project_task pt, project_group_list pgl, project_assigned_to pat
- WHERE pt.group_project_id = pgl.group_project_id
+ WHERE project_task_id IN (SELECT pt.project_task_id
+ FROM project_task pt, project_group_list pgl, project_assigned_to pat
+ WHERE pt.group_project_id = pgl.group_project_id
AND pat.project_task_id=pt.project_task_id
AND pt.status_id=1 AND pgl.group_id=$1
AND pat.assigned_to_id=$2)
return false;
}
$res = db_query_params('UPDATE project_assigned_to SET assigned_to_id=100
- WHERE project_task_id IN (SELECT pt.project_task_id
- FROM project_task pt, project_group_list pgl
- WHERE pt.group_project_id = pgl.group_project_id
- AND pt.status_id=1 AND pgl.group_id=$1)
+ WHERE project_task_id IN (SELECT pt.project_task_id
+ FROM project_task pt, project_group_list pgl
+ WHERE pt.group_project_id = pgl.group_project_id
+ AND pt.status_id=1 AND pgl.group_id=$1)
AND assigned_to_id=$2',
array($this->getID(),
$user_id));
//audit trail
$this->addHistory('Removed User',$user_id);
-
+
db_commit();
return true;
}
* @return boolean success.
*/
function updateUser($user_id,$role_id) {
- global $SYS;
if (!forge_check_perm ('project_admin', $this->getID())) {
$this->setPermissionDeniedError();
return false;
}
- if (USE_PFO_RBAC) {
- $newrole = RBACEngine::getInstance()->getRoleById ($role_id) ;
- if (!$newrole || !is_object($newrole)) {
- $this->setError(_('Could Not Get Role'));
- return false;
- } elseif ($newrole->isError()) {
- $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
- return false;
- } elseif ($newrole->getHomeProject() == NULL
- || $newrole->getHomeProject()->getID() != $this->getID()) {
- $this->setError(_('Wrong destination role'));
- return false;
- }
- $user = user_get_object ($user_id) ;
- $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
- $found_role = NULL ;
- foreach ($roles as $role) {
- if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
- $found_role = $role ;
- break ;
- }
- }
- if ($found_role == NULL) {
- $this->setError(sprintf(_('ERROR: User not removed: %s')));
- db_rollback();
- return false;
- }
- $found_role->removeUser ($user) ;
- $newrole->addUser ($user) ;
- } else {
- $role = new Role($this,$role_id);
- if (!$role || !is_object($role)) {
+ $newrole = RBACEngine::getInstance()->getRoleById ($role_id) ;
+ if (!$newrole || !is_object($newrole)) {
$this->setError(_('Could Not Get Role'));
return false;
- } elseif ($role->isError()) {
+ } elseif ($newrole->isError()) {
$this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
return false;
- }
-//echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
- if (!$role->setUser($user_id)) {
- $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
+ } elseif ($newrole->getHomeProject() == NULL
+ || $newrole->getHomeProject()->getID() != $this->getID()) {
+ $this->setError(_('Wrong destination role'));
return false;
}
+ $user = user_get_object ($user_id) ;
+ $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
+ $found_role = NULL ;
+ foreach ($roles as $role) {
+ if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
+ $found_role = $role ;
+ break ;
+ }
}
+ if ($found_role == NULL) {
+ $this->setError(sprintf(_('ERROR: User not removed: %s')));
+ db_rollback();
+ return false;
+ }
+ $found_role->removeUser ($user) ;
+ $newrole->addUser ($user) ;
$this->addHistory('Updated User',$user_id);
return true;
* @access public
*/
function addHistory($field_name, $old_value) {
- return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
+ return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
VALUES ($1,$2,$3,$4,$5)',
array ($this->getID(),
$field_name,
* activateUsers - Make sure that group members have unix accounts.
*
* Setup unix accounts for group members. Can be called even
- * if members are already active.
+ * if members are already active.
*
* @access private
*/
/*
Activate member(s) of the project
*/
-
- if (USE_PFO_RBAC) {
+
$members = $this->getUsers (true) ;
foreach ($members as $member) {
return false;
}
}
-
- }
- } else {
- $res_member = db_query_params('SELECT user_id,role_id FROM user_group WHERE group_id=$1',
- array ($this->getID()));
- while ($row_member = db_fetch_array($res_member)) {
- $u = user_get_object($row_member['user_id']);
- if (!$this->addUser($u->getUnixName(),$row_member['role_id'])) {
- return false;
- }
- }
+
}
return true;
* @access public
*/
function approve(&$user) {
- global $gfcommon;
+ global $gfcommon,$gfwww;
require_once $gfcommon.'widget/WidgetLayoutManager.class.php';
if ($this->getStatus()=='A') {
$this->setError(_("Group already active"));
return false;
}
-
+
db_begin();
// Step 1: Activate group and create LDAP entries
setup_gettext_from_sys_lang();
// Create default roles
- if (USE_PFO_RBAC) {
- $idadmin_group = NULL;
- foreach (get_group_join_requests ($this) as $gjr) {
- $idadmin_group = $gjr->getUserID();
- break ;
- }
- if ($idadmin_group == NULL) {
- $idadmin_group = $user->getID();
- }
- } else {
- $admin_group = db_query_params('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
- array($this->getID(),
- 'A'));
- if (db_numrows($admin_group) > 0) {
- $idadmin_group = db_result($admin_group,0,'user_id');
- } else {
- $idadmin_group = $user->getID();
- db_query_params('INSERT INTO user_group (user_id, group_id, admin_flags) VALUES ($1, $2, $3)',
- array($idadmin_group,
- $this->getID(),
- 'A')) ;
- }
+ $idadmin_group = NULL;
+ foreach (get_group_join_requests ($this) as $gjr) {
+ $idadmin_group = $gjr->getUserID();
+ break ;
+ }
+ if ($idadmin_group == NULL) {
+ $idadmin_group = $user->getID();
}
$template = $this->getTemplateProject();
$id_mappings = array();
- $seen_local_roles = false;
+ $seen_admin_role = false;
if ($template) {
// Copy roles from template project
foreach($template->getRoles() as $oldrole) {
// Need to use a different role name so that the permissions aren't set from the hardcoded defaults
$role->create('TEMPORARY ROLE NAME', $data, true);
$role->setName($oldrole->getName());
- $seen_local_roles = true;
+ if ($oldrole->getSetting ('project_admin', $template->getID())) {
+ $seen_admin_role = true;
+ }
} else {
$role = $oldrole;
$role->linkProject($this);
}
}
- if (!$seen_local_roles) {
+ if (!$seen_admin_role) {
$role = new Role($this);
$adminperms = array ('project_admin' => array ($this->getID() => 1)) ;
$role_id = $role->create ('Admin', $adminperms, true) ;
}
-
- if (USE_PFO_RBAC) {
- $roles = $this->getRoles() ;
- foreach ($roles as $r) {
- if ($r->getSetting ('project_admin', $this->getID())) {
- $r->addUser(user_get_object ($idadmin_group));
- }
+
+ $roles = $this->getRoles() ;
+ foreach ($roles as $r) {
+ if ($r->getHomeProject() == NULL) {
+ continue;
+ }
+ if ($r->getSetting ('project_admin', $this->getID())) {
+ $r->addUser(user_get_object ($idadmin_group));
}
}
$oldatf = new ArtifactTypeFactory($template);
foreach ($oldatf->getArtifactTypes() as $o) {
$t = new ArtifactType ($this) ;
- $t->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->allowsAnon(),$o->emailAll(),$o->getEmailAddress(),$o->getDuePeriod()/86400,0,$o->getSubmitInstructions(),$o->getBrowseInstructions()) ;
+ $t->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->emailAll(),$o->getEmailAddress(),$o->getDuePeriod()/86400,0,$o->getSubmitInstructions(),$o->getBrowseInstructions()) ;
$id_mappings['tracker'][$o->getID()] = $t->getID();
$t->cloneFieldsFrom ($o->getID());
}
$oldpgf = new ProjectGroupFactory($template);
foreach ($oldpgf->getProjectGroups() as $o) {
$pg = new ProjectGroup($this);
- $pg->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo());
+ $pg->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->getSendAllPostsTo());
$id_mappings['pm'][$o->getID()] = $pg->getID();
}
}
$oldff = new ForumFactory($template) ;
foreach ($oldff->getForums() as $o) {
$f = new Forum($this);
- $f->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo(),1,$o->allowAnonymous(),$o->getModerationLevel());
+ $f->create($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->getSendAllPostsTo(),1);
$id_mappings['forum'][$o->getID()] = $f->getID();
}
}
}
-
+
if (forge_get_config('use_docman')) {
$this->setUseDocman($template->usesDocman());
if ($template->usesDocman()) {
}
}
}
-
+
if (forge_get_config('use_frs')) {
$this->setUseFRS ($template->usesFRS());
if ($template->usesFRS()) {
}
}
- $this->setUseSCM ($template->usesSCM()) ;
+ if (0) {
+ /* use SCM plugin from template group */
+ $this->setUseSCM($template->usesSCM());
- foreach ($template->getPlugins() as $plugin_id => $plugin_name) {
- $this->setPluginUse ($plugin_name) ;
+ foreach ($template->getPlugins() as
+ $plugin_id => $plugin_name) {
+ $this->setPluginUse($plugin_name);
+ }
+ } else {
+ /* use SCM choice from registration page */
+
+ foreach ($template->getPlugins() as
+ $plugin_id => $plugin_name) {
+ if (substr($plugin_name, 3) == 'scm' &&
+ $plugin_name != 'scmhook') {
+ /* skip copying scm plugins */
+ continue;
+ }
+ /* enable other plugins though */
+ $this->setPluginUse($plugin_name);
+ }
}
foreach ($template->getRoles() as $oldrole) {
$newrole->setPublic ($oldrole->isPublic()) ;
}
$oldsettings = $oldrole->getSettingsForProject ($template) ;
-
+
$sections = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm') ;
foreach ($sections as $section) {
$newrole->setSetting ($section, $this->getID(), $oldsettings[$section][$template->getID()]) ;
}
}
}
- }
+ }
$lm = new WidgetLayoutManager();
$lm->createDefaultLayoutForProject ($this->getID(), $template->getID()) ;
plugin_hook_by_reference ('clone_project_from_template', $params) ;
} else {
// Disable everything
- $res = db_query_params ('UPDATE groups SET use_mail=0, use_survey=0, use_forum=0, use_pm=0, use_pm_depend_box=0, use_scm=0, use_news=0, use_docman=0, is_public=0, use_ftp=0, use_tracker=0, use_frs=0, use_stats=0 WHERE group_id=$1',
-
- array ($this->getID())) ;
+ db_query_params ('UPDATE groups SET use_mail=0, use_survey=0, use_forum=0, use_pm=0, use_pm_depend_box=0, use_scm=0, use_news=0, use_docman=0, use_ftp=0, use_tracker=0, use_frs=0, use_stats=0 WHERE group_id=$1',
+ array ($this->getID())) ;
}
$this->normalizeAllRoles();
+ $this->activateUsers();
+
+ // Delete fake join request
+ foreach (get_group_join_requests ($this) as $gjr) {
+ $gjr->delete(true) ;
+ }
// Switch back to user preference
session_set_internal($saved_session->getID());
$this->sendApprovalEmail();
$this->addHistory('Approved', 'x');
-
+
//
// Plugin can make approve operation there
//
Enjoy the system, and please tell others about %4$s. Let us know
if there is anything we can do to help you.
--- the %4$s crew'),
+-- the %4$s crew'),
htmlspecialchars_decode($this->getPublicName()),
- $this->getUnixName(),
+ $this->getUnixName(),
util_make_url ('/project/admin/?group_id='.$this->getID()),
forge_get_config ('forge_name'));
-
+
util_send_message($admin->getEmail(), sprintf(_('%1$s Project Approved'), forge_get_config ('forge_name')), $message);
setup_gettext_from_context();
*/
function sendRejectionEmail($response_id, $message="zxcv") {
$submitters = array () ;
- if (USE_PFO_RBAC) {
- foreach (get_group_join_requests ($this) as $gjr) {
- $submitters[] = user_get_object($gjr->getUserID());
- }
- } else {
- $res = db_query_params("SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND u.user_id=ug.user_id",
- $this->getID());
- while ($arr = db_fetch_array($res)) {
- $submitter[] = user_get_object($arr['user_id']);
- }
+ foreach (get_group_join_requests ($this) as $gjr) {
+ $submitters[] = user_get_object($gjr->getUserID());
}
if (count ($submitters) < 1) {
function sendNewProjectNotificationEmail() {
// Get the user who wants to register the project
$submitters = array();
- if (USE_PFO_RBAC) {
- foreach (get_group_join_requests ($this) as $gjr) {
- $submitters[] = user_get_object($gjr->getUserID());
- }
- } else {
- $res = db_query_params("SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND u.user_id=ug.user_id",
- $this->getID());
- while ($arr = db_fetch_array ($res)) {
- $submitter[] = user_get_object($arr['user_id']);
- }
+ foreach (get_group_join_requests ($this) as $gjr) {
+ $submitters[] = user_get_object($gjr->getUserID());
}
if (count ($submitters) < 1) {
$this->setError(_("Could not find user who has submitted the project."));
return false;
}
-
+
$admins = RBACEngine::getInstance()->getUsersByAllowedAction ('approve_projects', -1) ;
if (count($admins) < 1) {
$admin_email = $admin->getEmail () ;
setup_gettext_for_user ($admin) ;
- foreach ($submitters as $u) {
- $submitter_names[] = $u->getRealName() ;
- }
-
$message = sprintf(_('New %1$s Project Submitted
Project Full Name: %2$s
forge_get_config ('forge_name'),
htmlspecialchars_decode($this->getPublicName()),
htmlspecialchars_decode($this->getRegistrationPurpose()));
-
+
foreach ($submitters as $submitter) {
$message .= sprintf(_('Submitter: %1$s (%2$s)
'),
- $submitter->getRealName(),
+ $submitter->getRealName(),
$submitter->getUnixName());
}
util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
setup_gettext_from_context();
}
-
+
$email = $submitter->getEmail() ;
setup_gettext_for_user ($submitter) ;
-
+
$message=sprintf(_('New %1$s Project Submitted
Project Full Name: %2$s
Submitted Description: %3$s
The %1$s admin team will now examine your project submission. You will be notified of their decision.'), forge_get_config ('forge_name'), $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), forge_get_config('web_host'));
-
+
util_send_message($email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
setup_gettext_from_context();
-
+
return true;
}
} else if (strlen(htmlspecialchars($group_name))>50) {
$this->setError(_('Group name is too long'));
return false;
- } else if ($group=group_get_object_by_publicname($group_name)) {
+ } else if (group_get_object_by_publicname($group_name)) {
$this->setError(_('Group name already taken'));
return false;
}
/**
- * getRoles - Get the roles of the group.
+ * getRolesId - Get Ids of the roles of the group.
*
* @return array Role ids of this group.
*/
function getRolesId() {
$role_ids = array();
-
- if (USE_PFO_RBAC) {
- $res = db_query_params('SELECT role_id FROM pfo_role WHERE home_group_id=$1',
- array($this->getID()));
- while ($arr = db_fetch_array($res)) {
- $role_ids[] = $arr['role_id'];
- }
- $res = db_query_params('SELECT role_id FROM role_project_refs WHERE group_id=$1',
- array($this->getID()));
- while ($arr = db_fetch_array($res)) {
- $role_ids[] = $arr['role_id'];
- }
- } else {
- $res = db_query_params('SELECT role_id FROM role WHERE group_id=$1',
- array($this->getID()));
- while ($arr = db_fetch_array($res)) {
- $role_ids[] = $arr['role_id'];
- }
+
+ $res = db_query_params('SELECT role_id FROM pfo_role WHERE home_group_id=$1',
+ array($this->getID()));
+ while ($arr = db_fetch_array($res)) {
+ $role_ids[] = $arr['role_id'];
}
-
+ $res = db_query_params('SELECT role_id FROM role_project_refs WHERE group_id=$1',
+ array($this->getID()));
+ while ($arr = db_fetch_array($res)) {
+ $role_ids[] = $arr['role_id'];
+ }
+
return array_unique($role_ids);
}
$result = array();
$roles = $this->getRolesId();
- if (USE_PFO_RBAC) {
- $engine = RBACEngine::getInstance();
- foreach ($roles as $role_id) {
- $result[] = $engine->getRoleById ($role_id);
- }
- } else {
- foreach ($roles as $role_id) {
- $result[] = new Role ($this, $role_id);
- }
+ $engine = RBACEngine::getInstance();
+ foreach ($roles as $role_id) {
+ $result[] = $engine->getRoleById ($role_id);
}
return $result;
function normalizeAllRoles() {
$roles = $this->getRoles();
-
+
foreach ($roles as $r) {
$r->normalizeData();
}
function getUnixStatus() {
return $this->data_array['unix_status'];
}
-
+
/**
* setUnixStatus - Sets status of activation of unix account.
*
$res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
array ($status,
$this->getID())) ;
-
+
if (!$res) {
$this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
db_rollback();
}
}
}
-
+
$this->data_array['unix_status']=$status;
db_commit();
return true;
}
}
-
+
/**
* getUsers - Get the users of a group
*
function getUsers($onlylocal = true) {
if (!isset($this->membersArr)) {
$this->membersArr = array () ;
-
- if (USE_PFO_RBAC) {
- $ids = array () ;
- foreach ($this->getRoles() as $role) {
- if ($onlylocal
- && ($role->getHomeProject() == NULL || $role->getHomeProject()->getID() != $this->getID())) {
- continue ;
- }
- foreach ($role->getUsers() as $user) {
- $ids[] = $user->getID() ;
- }
- }
- $ids = array_unique ($ids) ;
- foreach ($ids as $id) {
- $u = user_get_object ($id) ;
- if ($u->isActive()) {
- $this->membersArr[] = $u ;
- }
+
+ $ids = array () ;
+ foreach ($this->getRoles() as $role) {
+ if ($onlylocal
+ && ($role->getHomeProject() == NULL || $role->getHomeProject()->getID() != $this->getID())) {
+ continue ;
}
- } else {
-
- $users_group_res = db_query_params ('SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND ug.user_id=u.user_id AND u.status=$2',
- array ($this->getID(),
- 'A'));
- if (!$users_group_res) {
- $this->setError(_('Error: Enable to get users from group'). ' ' . $this->getID() . ' ' .db_error());
- return false;
+ foreach ($role->getUsers() as $user) {
+ $ids[] = $user->getID() ;
}
-
- for ($i=0; $i<db_numrows($users_group_res); $i++) {
- $this->membersArr[$i] = new GFUser(db_result($users_group_res,$i,'user_id'),false);
+ }
+ $ids = array_unique ($ids) ;
+ foreach ($ids as $id) {
+ $u = user_get_object ($id) ;
+ if ($u->isActive()) {
+ $this->membersArr[] = $u ;
}
-
}
}
return $this->membersArr;
/* if we activate search engine, we probably want to reindex */
$res = db_query_params('UPDATE groups SET use_docman_create_online=$1 WHERE group_id=$2',
array($status, $this->getID()));
-
+
if (!$res) {
$this->setError(sprintf(_('ERROR - Could Not Update Group DocmanCreateOnline Status: %s'),db_error()));
db_rollback();
$res = db_query_params('UPDATE groups SET use_webdav=$1 WHERE group_id=$2',
array($status,
$this->getID()));
-
+
if (!$res) {
$this->setError(sprintf(_('ERROR - Could Not Update Group UseWebdab Status: %s'),db_error()));
db_rollback();
$res = db_query_params('UPDATE groups SET use_docman_search=$1, force_docman_reindex=$1 WHERE group_id=$2',
array($status,
$this->getID()));
-
+
if (!$res) {
$this->setError(sprintf(_('ERROR - Could Not Update Group UseDocmanSearch Status: %s'),db_error()));
db_rollback();
$res = db_query_params('UPDATE groups SET force_docman_reindex=$1 WHERE group_id=$2',
array($status,
$this->getID()));
-
+
if (!$res) {
$this->setError(sprintf(_('ERROR - Could Not Update Group force_docman_reindex %s'),db_error()));
db_rollback();
}
}
- function setStorageAPI($type) {
- return true;
- }
-
- function getStorageAPI() {
- return 'DB';
- }
}
/**
return $result;
}
+/**
+ * Utility class to compare project based in various criteria (names, unixnames, id, ...)
+ *
+ */
class ProjectComparator {
var $criterion = 'name' ;