mirror of
https://github.com/friendica/friendica
synced 2025-04-21 11:50:15 +00:00
Merge pull request #11030 from MrPetovan/bug/11029-add-remove-group
Add backward compatibility with user contacts in Module\Group
This commit is contained in:
commit
e852623c4f
4 changed files with 200 additions and 189 deletions
|
@ -34,10 +34,8 @@ class Group extends BaseModule
|
|||
{
|
||||
public function post()
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
if (DI::mode()->isAjax()) {
|
||||
self::ajaxPost();
|
||||
$this->ajaxPost();
|
||||
}
|
||||
|
||||
if (!local_user()) {
|
||||
|
@ -80,26 +78,32 @@ class Group extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
public static function ajaxPost()
|
||||
public function ajaxPost()
|
||||
{
|
||||
try {
|
||||
$a = DI::app();
|
||||
|
||||
if (!local_user()) {
|
||||
throw new \Exception(DI::l10n()->t('Permission denied.'), 403);
|
||||
}
|
||||
|
||||
// POST /group/123/add/123
|
||||
// POST /group/123/remove/123
|
||||
// @TODO: Replace with parameter from router
|
||||
if (DI::args()->getArgc() == 4) {
|
||||
list($group_id, $command, $contact_id) = array_slice(DI::args()->getArgv(), 1);
|
||||
if (isset($this->parameters['command'])) {
|
||||
$group_id = $this->parameters['group'];
|
||||
$contact_id = $this->parameters['contact'];
|
||||
|
||||
if (!Model\Group::exists($group_id, local_user())) {
|
||||
throw new \Exception(DI::l10n()->t('Unknown group.'), 404);
|
||||
}
|
||||
|
||||
$contact = DBA::selectFirst('contact', ['deleted'], ['id' => $contact_id, 'uid' => local_user()]);
|
||||
// @TODO Backward compatibility with user contacts, remove by version 2022.03
|
||||
$cdata = Model\Contact::getPublicAndUserContactID($contact_id, local_user());
|
||||
if (empty($cdata['public'])) {
|
||||
throw new \Exception(DI::l10n()->t('Contact not found.'), 404);
|
||||
}
|
||||
|
||||
if (empty($cdata['user'])) {
|
||||
throw new \Exception(DI::l10n()->t('Invalid contact.'), 404);
|
||||
}
|
||||
|
||||
$contact = Model\Contact::getById($cdata['user'], ['deleted']);
|
||||
if (!DBA::isResult($contact)) {
|
||||
throw new \Exception(DI::l10n()->t('Contact not found.'), 404);
|
||||
}
|
||||
|
@ -108,23 +112,21 @@ class Group extends BaseModule
|
|||
throw new \Exception(DI::l10n()->t('Contact is deleted.'), 410);
|
||||
}
|
||||
|
||||
switch($command) {
|
||||
switch($this->parameters['command']) {
|
||||
case 'add':
|
||||
if (!Model\Group::addMember($group_id, $contact_id)) {
|
||||
if (!Model\Group::addMember($group_id, $cdata['user'])) {
|
||||
throw new \Exception(DI::l10n()->t('Unable to add the contact to the group.'), 500);
|
||||
}
|
||||
|
||||
$message = DI::l10n()->t('Contact successfully added to group.');
|
||||
break;
|
||||
case 'remove':
|
||||
if (!Model\Group::removeMember($group_id, $contact_id)) {
|
||||
if (!Model\Group::removeMember($group_id, $cdata['user'])) {
|
||||
throw new \Exception(DI::l10n()->t('Unable to remove the contact from the group.'), 500);
|
||||
}
|
||||
|
||||
$message = DI::l10n()->t('Contact successfully removed from group.');
|
||||
break;
|
||||
default:
|
||||
throw new \Exception(DI::l10n()->t('Unknown group command.'), 400);
|
||||
}
|
||||
} else {
|
||||
throw new \Exception(DI::l10n()->t('Bad request.'), 400);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue