modify group actions so they use Local_group to look up by nickname
This commit is contained in:
parent
ddc3671b6a
commit
e6858d7203
@ -123,7 +123,9 @@ class ApiGroupCreateAction extends ApiAuthAction
|
|||||||
'description' => $this->description,
|
'description' => $this->description,
|
||||||
'location' => $this->location,
|
'location' => $this->location,
|
||||||
'aliases' => $this->aliases,
|
'aliases' => $this->aliases,
|
||||||
'userid' => $this->user->id));
|
'userid' => $this->user->id,
|
||||||
|
'local' => true));
|
||||||
|
|
||||||
switch($this->format) {
|
switch($this->format) {
|
||||||
case 'xml':
|
case 'xml':
|
||||||
$this->showSingleXmlGroup($group);
|
$this->showSingleXmlGroup($group);
|
||||||
@ -306,9 +308,9 @@ class ApiGroupCreateAction extends ApiAuthAction
|
|||||||
|
|
||||||
function groupNicknameExists($nickname)
|
function groupNicknameExists($nickname)
|
||||||
{
|
{
|
||||||
$group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
if (!empty($group)) {
|
if (!empty($local)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,13 +134,13 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
|
|||||||
|
|
||||||
function getGroups()
|
function getGroups()
|
||||||
{
|
{
|
||||||
$groups = array();
|
$qry = 'SELECT user_group.* '.
|
||||||
|
'from user_group join local_group on user_group.id = local_group.group_id '.
|
||||||
// XXX: Use the $page, $count, $max_id, $since_id, and $since parameters
|
'order by created desc ';
|
||||||
|
|
||||||
$group = new User_group();
|
$group = new User_group();
|
||||||
$group->orderBy('created DESC');
|
|
||||||
$group->find();
|
$group->query($qry);
|
||||||
|
|
||||||
while ($group->fetch()) {
|
while ($group->fetch()) {
|
||||||
$groups[] = clone($group);
|
$groups[] = clone($group);
|
||||||
|
@ -74,7 +74,14 @@ class BlockedfromgroupAction extends GroupDesignAction
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
|
if (!$local) {
|
||||||
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
$this->clientError(_('No such group.'), 404);
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
@ -86,10 +86,14 @@ class EditgroupAction extends GroupDesignAction
|
|||||||
}
|
}
|
||||||
|
|
||||||
$groupid = $this->trimmed('groupid');
|
$groupid = $this->trimmed('groupid');
|
||||||
|
|
||||||
if ($groupid) {
|
if ($groupid) {
|
||||||
$this->group = User_group::staticGet('id', $groupid);
|
$this->group = User_group::staticGet('id', $groupid);
|
||||||
} else {
|
} else {
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
if ($local) {
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
@ -259,6 +263,12 @@ class EditgroupAction extends GroupDesignAction
|
|||||||
$this->serverError(_('Could not create aliases.'));
|
$this->serverError(_('Could not create aliases.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($nickname != $orig->nickname) {
|
||||||
|
common_log(LOG_INFO, "Saving local group info.");
|
||||||
|
$local = Local_group::staticGet('group_id', $this->group->id);
|
||||||
|
$local->setNickname($nickname);
|
||||||
|
}
|
||||||
|
|
||||||
$this->group->query('COMMIT');
|
$this->group->query('COMMIT');
|
||||||
|
|
||||||
if ($this->group->nickname != $orig->nickname) {
|
if ($this->group->nickname != $orig->nickname) {
|
||||||
@ -272,7 +282,7 @@ class EditgroupAction extends GroupDesignAction
|
|||||||
|
|
||||||
function nicknameExists($nickname)
|
function nicknameExists($nickname)
|
||||||
{
|
{
|
||||||
$group = User_group::staticGet('nickname', $nickname);
|
$group = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
if (!empty($group) &&
|
if (!empty($group) &&
|
||||||
$group->id != $this->group->id) {
|
$group->id != $this->group->id) {
|
||||||
|
@ -56,7 +56,14 @@ class FoafGroupAction extends Action
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->group = User_group::staticGet('nickname', $this->nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
|
if (!$local) {
|
||||||
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
$this->clientError(_('No such group.'), 404);
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
@ -90,7 +90,10 @@ class GroupDesignSettingsAction extends DesignSettingsAction
|
|||||||
if ($groupid) {
|
if ($groupid) {
|
||||||
$this->group = User_group::staticGet('id', $groupid);
|
$this->group = User_group::staticGet('id', $groupid);
|
||||||
} else {
|
} else {
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
if ($local) {
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
|
@ -92,7 +92,10 @@ class GrouplogoAction extends GroupDesignAction
|
|||||||
if ($groupid) {
|
if ($groupid) {
|
||||||
$this->group = User_group::staticGet('id', $groupid);
|
$this->group = User_group::staticGet('id', $groupid);
|
||||||
} else {
|
} else {
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
if ($local) {
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
|
@ -77,7 +77,14 @@ class GroupmembersAction extends GroupDesignAction
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
|
if (!$local) {
|
||||||
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
$this->clientError(_('No such group.'), 404);
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
@ -92,7 +92,14 @@ class groupRssAction extends Rss10Action
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
|
if (!$local) {
|
||||||
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
$this->clientError(_('No such group.'), 404);
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
@ -111,15 +111,19 @@ class GroupsAction extends Action
|
|||||||
$offset = ($this->page-1) * GROUPS_PER_PAGE;
|
$offset = ($this->page-1) * GROUPS_PER_PAGE;
|
||||||
$limit = GROUPS_PER_PAGE + 1;
|
$limit = GROUPS_PER_PAGE + 1;
|
||||||
|
|
||||||
|
$qry = 'SELECT user_group.* '.
|
||||||
|
'from user_group join local_group on user_group.id = local_group.group_id '.
|
||||||
|
'order by user_group.created desc '.
|
||||||
|
'limit ' . $limit . ' offset ' . $offset;
|
||||||
|
|
||||||
$groups = new User_group();
|
$groups = new User_group();
|
||||||
$groups->orderBy('created DESC');
|
|
||||||
$groups->limit($offset, $limit);
|
|
||||||
|
|
||||||
$cnt = 0;
|
$cnt = 0;
|
||||||
if ($groups->find()) {
|
|
||||||
|
$groups->query($qry);
|
||||||
|
|
||||||
$gl = new GroupList($groups, null, $this);
|
$gl = new GroupList($groups, null, $this);
|
||||||
$cnt = $gl->show();
|
$cnt = $gl->show();
|
||||||
}
|
|
||||||
|
|
||||||
$this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
|
$this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE,
|
||||||
$this->page, 'groups');
|
$this->page, 'groups');
|
||||||
|
@ -77,7 +77,14 @@ class JoingroupAction extends Action
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
|
if (!$local) {
|
||||||
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
$this->clientError(_('No such group.'), 404);
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
@ -77,7 +77,14 @@ class LeavegroupAction extends Action
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
|
if (!$local) {
|
||||||
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
$this->clientError(_('No such group.'), 404);
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
@ -192,16 +192,17 @@ class NewgroupAction extends Action
|
|||||||
'description' => $description,
|
'description' => $description,
|
||||||
'location' => $location,
|
'location' => $location,
|
||||||
'aliases' => $aliases,
|
'aliases' => $aliases,
|
||||||
'userid' => $cur->id));
|
'userid' => $cur->id,
|
||||||
|
'local' => true));
|
||||||
|
|
||||||
common_redirect($group->homeUrl(), 303);
|
common_redirect($group->homeUrl(), 303);
|
||||||
}
|
}
|
||||||
|
|
||||||
function nicknameExists($nickname)
|
function nicknameExists($nickname)
|
||||||
{
|
{
|
||||||
$group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
if (!empty($group)) {
|
if (!empty($local)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,15 @@ class ShowgroupAction extends GroupDesignAction
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->group = User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
|
||||||
|
if (!$local) {
|
||||||
|
common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
|
||||||
|
$this->clientError(_('No such group.'), 404);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->group = User_group::staticGet('id', $local->group_id);
|
||||||
|
|
||||||
if (!$this->group) {
|
if (!$this->group) {
|
||||||
$alias = Group_alias::staticGet('alias', $nickname);
|
$alias = Group_alias::staticGet('alias', $nickname);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
/**
|
/**
|
||||||
* Table Definition for local_group
|
* Table Definition for local_group
|
||||||
*/
|
*/
|
||||||
require_once 'classes/Memcached_DataObject.php';
|
|
||||||
|
|
||||||
class Local_group extends Memcached_DataObject
|
class Local_group extends Memcached_DataObject
|
||||||
{
|
{
|
||||||
@ -16,8 +15,32 @@ class Local_group extends Memcached_DataObject
|
|||||||
public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
|
public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
|
||||||
|
|
||||||
/* Static get */
|
/* Static get */
|
||||||
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Local_group',$k,$v); }
|
function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Local_group',$k,$v); }
|
||||||
|
|
||||||
/* the code above is auto generated do not remove the tag below */
|
/* the code above is auto generated do not remove the tag below */
|
||||||
###END_AUTOCODE
|
###END_AUTOCODE
|
||||||
|
|
||||||
|
function sequenceKey()
|
||||||
|
{
|
||||||
|
return array(false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setNickname($nickname)
|
||||||
|
{
|
||||||
|
$this->decache();
|
||||||
|
$qry = 'UPDATE local_group set nickname = "'.$nickname.'" where group_id = ' . $this->group_id;
|
||||||
|
|
||||||
|
$result = $this->query($qry);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$this->nickname = $nickname;
|
||||||
|
$this->fixupTimestamps();
|
||||||
|
$this->encache();
|
||||||
|
} else {
|
||||||
|
common_log_db_error($local, 'UPDATE', __FILE__);
|
||||||
|
throw new ServerException(_('Could not update local group.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,28 +414,30 @@ class User_group extends Memcached_DataObject
|
|||||||
$group->homepage = $homepage;
|
$group->homepage = $homepage;
|
||||||
$group->description = $description;
|
$group->description = $description;
|
||||||
$group->location = $location;
|
$group->location = $location;
|
||||||
|
$group->uri = $uri;
|
||||||
$group->created = common_sql_now();
|
$group->created = common_sql_now();
|
||||||
|
|
||||||
$result = $group->insert();
|
$result = $group->insert();
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
common_log_db_error($group, 'INSERT', __FILE__);
|
common_log_db_error($group, 'INSERT', __FILE__);
|
||||||
$this->serverError(
|
throw new ServerException(_('Could not create group.'));
|
||||||
_('Could not create group.'),
|
|
||||||
500,
|
|
||||||
$this->format
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($uri) || empty($uri)) {
|
||||||
|
$orig = clone($group);
|
||||||
|
$group->uri = common_local_url('groupbyid', array('id' => $group->id));
|
||||||
|
$result = $group->update($orig);
|
||||||
|
if (!$result) {
|
||||||
|
common_log_db_error($group, 'UPDATE', __FILE__);
|
||||||
|
throw new ServerException(_('Could not set group uri.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$result = $group->setAliases($aliases);
|
$result = $group->setAliases($aliases);
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$this->serverError(
|
throw new ServerException(_('Could not create aliases.'));
|
||||||
_('Could not create aliases.'),
|
|
||||||
500,
|
|
||||||
$this->format
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$member = new Group_member();
|
$member = new Group_member();
|
||||||
@ -449,12 +451,22 @@ class User_group extends Memcached_DataObject
|
|||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
common_log_db_error($member, 'INSERT', __FILE__);
|
common_log_db_error($member, 'INSERT', __FILE__);
|
||||||
$this->serverError(
|
throw new ServerException(_('Could not set group membership.'));
|
||||||
_('Could not set group membership.'),
|
}
|
||||||
500,
|
|
||||||
$this->format
|
if ($local) {
|
||||||
);
|
$local_group = new Local_group();
|
||||||
return;
|
|
||||||
|
$local_group->group_id = $group->id;
|
||||||
|
$local_group->nickname = $nickname;
|
||||||
|
$local_group->created = common_sql_now();
|
||||||
|
|
||||||
|
$result = $local_group->insert();
|
||||||
|
|
||||||
|
if (!$result) {
|
||||||
|
common_log_db_error($local_group, 'INSERT', __FILE__);
|
||||||
|
throw new ServerException(_('Could not save local group info.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$group->query('COMMIT');
|
$group->query('COMMIT');
|
||||||
|
21
lib/api.php
21
lib/api.php
@ -1218,7 +1218,12 @@ class ApiAction extends Action
|
|||||||
return User_group::staticGet($this->arg('id'));
|
return User_group::staticGet($this->arg('id'));
|
||||||
} else if ($this->arg('id')) {
|
} else if ($this->arg('id')) {
|
||||||
$nickname = common_canonical_nickname($this->arg('id'));
|
$nickname = common_canonical_nickname($this->arg('id'));
|
||||||
return User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
if (empty($local)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return User_group::staticGet('id', $local->id);
|
||||||
|
}
|
||||||
} else if ($this->arg('group_id')) {
|
} else if ($this->arg('group_id')) {
|
||||||
// This is to ensure that a non-numeric user_id still
|
// This is to ensure that a non-numeric user_id still
|
||||||
// overrides screen_name even if it doesn't get used
|
// overrides screen_name even if it doesn't get used
|
||||||
@ -1227,14 +1232,24 @@ class ApiAction extends Action
|
|||||||
}
|
}
|
||||||
} else if ($this->arg('group_name')) {
|
} else if ($this->arg('group_name')) {
|
||||||
$nickname = common_canonical_nickname($this->arg('group_name'));
|
$nickname = common_canonical_nickname($this->arg('group_name'));
|
||||||
return User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
if (empty($local)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return User_group::staticGet('id', $local->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (is_numeric($id)) {
|
} else if (is_numeric($id)) {
|
||||||
return User_group::staticGet($id);
|
return User_group::staticGet($id);
|
||||||
} else {
|
} else {
|
||||||
$nickname = common_canonical_nickname($id);
|
$nickname = common_canonical_nickname($id);
|
||||||
return User_group::staticGet('nickname', $nickname);
|
$local = Local_group::staticGet('nickname', $nickname);
|
||||||
|
if (empty($local)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return User_group::staticGet('id', $local->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user