/** * Check parameters * * @param array $args action arguments (URL, GET, POST) * * @return boolean success flag */ function prepare($args) { if (!parent::prepare($args)) { return false; } $this->role = $this->arg('role'); if (!Profile_role::isValid($this->role)) { $this->clientError(_('Invalid role.')); return false; } if (!Profile_role::isSettable($this->role)) { $this->clientError(_('This role is reserved and cannot be set.')); return false; } $cur = common_current_user(); assert(!empty($cur)); // checked by parent if (!$cur->hasRight(Right::REVOKEROLE)) { $this->clientError(_('You cannot revoke user roles on this site.')); return false; } assert(!empty($this->profile)); // checked by parent if (!$this->profile->hasRole($this->role)) { $this->clientError(_("User doesn't have this role.")); return false; } return true; }
/** * Check parameters * * @param array $args action arguments (URL, GET, POST) * * @return boolean success flag */ function prepare($args) { if (!parent::prepare($args)) { return false; } $this->role = $this->arg('role'); if (!Profile_role::isValid($this->role)) { // TRANS: Client error displayed when trying to assign an invalid role to a user. $this->clientError(_('Invalid role.')); return false; } if (!Profile_role::isSettable($this->role)) { // TRANS: Client error displayed when trying to assign an reserved role to a user. $this->clientError(_('This role is reserved and cannot be set.')); return false; } $cur = common_current_user(); assert(!empty($cur)); // checked by parent if (!$cur->hasRight(Right::GRANTROLE)) { // TRANS: Client error displayed when trying to assign a role to a user while not being allowed to set roles. $this->clientError(_('You cannot grant user roles on this site.')); return false; } assert(!empty($this->profile)); // checked by parent if ($this->profile->hasRole($this->role)) { // TRANS: Client error displayed when trying to assign a role to a user that already has that role. $this->clientError(_('User already has this role.')); return false; } return true; }
/** * Check parameters * * @param array $args action arguments (URL, GET, POST) * * @return boolean success flag */ function prepare($args) { if (!parent::prepare($args)) { return false; } $this->role = $this->arg('role'); if (!Profile_role::isValid($this->role)) { // TRANS: Client error displayed when trying to revoke an invalid role. $this->clientError(_('Invalid role.')); } if (!Profile_role::isSettable($this->role)) { // TRANS: Client error displayed when trying to revoke a reserved role. $this->clientError(_('This role is reserved and cannot be set.')); } $cur = common_current_user(); assert(!empty($cur)); // checked by parent if (!$cur->hasRight(Right::REVOKEROLE)) { // TRANS: Client error displayed when trying to revoke a role without having the right to do that. $this->clientError(_('You cannot revoke user roles on this site.')); } assert(!empty($this->profile)); // checked by parent if (!$this->profile->hasRole($this->role)) { // TRANS: Client error displayed when trying to revoke a role that is not set. $this->clientError(_('User does not have this role.')); } return true; }
function prefill($notices) { // XXX: this should probably only be in the scoping one. Notice::fillGroups($notices); Notice::fillReplies($notices); if (common_config('notice', 'hidespam')) { $profiles = Notice::getProfiles($notices); foreach ($profiles as $profile) { $pids[] = $profile->id; } Profile_role::pivotGet('profile_id', $pids, array('role' => Profile_role::SILENCED)); } }
static function siteOwner() { $owner = self::cacheGet('user:site_owner'); if ($owner === false) { // cache miss $pr = new Profile_role(); $pr->role = Profile_role::OWNER; $pr->orderBy('created'); $pr->limit(1); if ($pr->find(true)) { $owner = User::staticGet('id', $pr->profile_id); } else { $owner = null; } self::cacheSet('user:site_owner', $owner); } return $owner; }
function revokeRole($name) { if (Event::handle('StartRevokeRole', array($this, $name))) { $role = Profile_role::pkeyGet(array('profile_id' => $this->id, 'role' => $name)); if (empty($role)) { // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist. // TRANS: %1$s is the role name, %2$s is the user ID (number). throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'), $name, $this->id)); } $result = $role->delete(); if (!$result) { common_log_db_error($role, 'DELETE', __FILE__); // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query. // TRANS: %1$s is the role name, %2$s is the user ID (number). throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'), $name, $this->id)); } if ($name == 'owner') { User::blow('user:site_owner'); } Event::handle('EndRevokeRole', array($this, $name)); return true; } }
public static function siteOwner() { $owner = self::cacheGet('user:site_owner'); if ($owner === false) { // cache miss $pr = new Profile_role(); $pr->role = Profile_role::OWNER; $pr->orderBy('created'); $pr->limit(1); if (!$pr->find(true)) { throw new NoResultException($pr); } $owner = User::getKV('id', $pr->profile_id); self::cacheSet('user:site_owner', $owner); } if ($owner instanceof User) { return $owner; } throw new ServerException(_('No site owner configured.')); }
function revokeRole($name) { $role = Profile_role::pkeyGet(array('profile_id' => $this->id, 'role' => $name)); if (empty($role)) { throw new Exception('Cannot revoke role "' . $name . '" for user #' . $this->id . '; does not exist.'); } $result = $role->delete(); if (!$result) { common_log_db_error($role, 'DELETE', __FILE__); throw new Exception('Cannot revoke role "' . $name . '" for user #' . $this->id . '; database error.'); } return true; }
if (empty($fullname)) { echo 'username required'; exit; } if (empty($email)) { echo 'email required'; exit; } if (empty($password)) { echo 'password required'; exit; } $profile = new Profile(); $profile->fullname = $fullname; $profile->email = $email; $profile->created = common_sql_now(); $profile_id = $profile->insert(); if (!$profile_id) { common_log_db_error($profile, 'INSERT', __FILE__); exit; } $profile_role = new Profile_role(); $profile_role->profile_id = $profile_id; $profile_role->role = Profile_role::SUPERADMIN; $profile_role->created = common_sql_now(); $profile_role->insert(); $pnew = Profile::staticGet($profile_id); $orig = clone $pnew; $pnew->password = common_munge_password($password, $profile_id); $pnew->update($orig); echo "Done!";