Replace args call with parameter from router in Module\Group
This commit is contained in:
parent
3d77fd5e29
commit
a26322b4c2
|
@ -34,10 +34,8 @@ class Group extends BaseModule
|
||||||
{
|
{
|
||||||
public function post()
|
public function post()
|
||||||
{
|
{
|
||||||
$a = DI::app();
|
|
||||||
|
|
||||||
if (DI::mode()->isAjax()) {
|
if (DI::mode()->isAjax()) {
|
||||||
self::ajaxPost();
|
$this->ajaxPost();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!local_user()) {
|
if (!local_user()) {
|
||||||
|
@ -80,20 +78,16 @@ class Group extends BaseModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function ajaxPost()
|
public function ajaxPost()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$a = DI::app();
|
|
||||||
|
|
||||||
if (!local_user()) {
|
if (!local_user()) {
|
||||||
throw new \Exception(DI::l10n()->t('Permission denied.'), 403);
|
throw new \Exception(DI::l10n()->t('Permission denied.'), 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /group/123/add/123
|
if (isset($this->parameters['command'])) {
|
||||||
// POST /group/123/remove/123
|
$group_id = $this->parameters['group'];
|
||||||
// @TODO: Replace with parameter from router
|
$contact_id = $this->parameters['contact'];
|
||||||
if (DI::args()->getArgc() == 4) {
|
|
||||||
list($group_id, $command, $contact_id) = array_slice(DI::args()->getArgv(), 1);
|
|
||||||
|
|
||||||
if (!Model\Group::exists($group_id, local_user())) {
|
if (!Model\Group::exists($group_id, local_user())) {
|
||||||
throw new \Exception(DI::l10n()->t('Unknown group.'), 404);
|
throw new \Exception(DI::l10n()->t('Unknown group.'), 404);
|
||||||
|
@ -108,7 +102,7 @@ class Group extends BaseModule
|
||||||
throw new \Exception(DI::l10n()->t('Contact is deleted.'), 410);
|
throw new \Exception(DI::l10n()->t('Contact is deleted.'), 410);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($command) {
|
switch($this->parameters['command']) {
|
||||||
case 'add':
|
case 'add':
|
||||||
if (!Model\Group::addMember($group_id, $contact_id)) {
|
if (!Model\Group::addMember($group_id, $contact_id)) {
|
||||||
throw new \Exception(DI::l10n()->t('Unable to add the contact to the group.'), 500);
|
throw new \Exception(DI::l10n()->t('Unable to add the contact to the group.'), 500);
|
||||||
|
@ -123,8 +117,6 @@ class Group extends BaseModule
|
||||||
|
|
||||||
$message = DI::l10n()->t('Contact successfully removed from group.');
|
$message = DI::l10n()->t('Contact successfully removed from group.');
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
throw new \Exception(DI::l10n()->t('Unknown group command.'), 400);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception(DI::l10n()->t('Bad request.'), 400);
|
throw new \Exception(DI::l10n()->t('Bad request.'), 400);
|
||||||
|
|
|
@ -389,9 +389,7 @@ return [
|
||||||
'/new' => [Module\Group::class, [R::GET, R::POST]],
|
'/new' => [Module\Group::class, [R::GET, R::POST]],
|
||||||
'/drop/{group:\d+}' => [Module\Group::class, [R::GET, R::POST]],
|
'/drop/{group:\d+}' => [Module\Group::class, [R::GET, R::POST]],
|
||||||
'/{group:\d+}/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
|
'/{group:\d+}/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
|
||||||
|
'/{group:\d+}/{command:add|remove}/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
|
||||||
'/{group:\d+}/add/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
|
|
||||||
'/{group:\d+}/remove/{contact:\d+}' => [Module\Group::class, [R::GET, R::POST]],
|
|
||||||
],
|
],
|
||||||
'/hashtag' => [Module\Hashtag::class, [R::GET]],
|
'/hashtag' => [Module\Hashtag::class, [R::GET]],
|
||||||
'/help[/{doc:.+}]' => [Module\Help::class, [R::GET]],
|
'/help[/{doc:.+}]' => [Module\Help::class, [R::GET]],
|
||||||
|
|
Loading…
Reference in a new issue