X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapiblockcreate.php;h=c26485f591b23196917eb07f3fcc8b65e6ab72d3;hb=6d73fc1d5439439cca5a6af3f05b39bdf4ef20aa;hp=1cab2df5d0d9584ebf9d982aa69eb0dc1ccb622d;hpb=61419038e5747886357964a7eb3f814761482891;p=quix0rs-gnu-social.git diff --git a/actions/apiblockcreate.php b/actions/apiblockcreate.php index 1cab2df5d0..c26485f591 100644 --- a/actions/apiblockcreate.php +++ b/actions/apiblockcreate.php @@ -94,13 +94,31 @@ class ApiBlockCreateAction extends ApiAuthAction } if (empty($this->user) || empty($this->other)) { - $this->clientError(_('No such user!'), 404, $this->format); + $this->clientError(_('No such user.'), 404, $this->format); return; } - if ($this->user->hasBlocked($this->other) - || $this->user->block($this->other) - ) { + // Don't allow blocking yourself! + + if ($this->user->id == $this->other->id) { + $this->clientError( + _("You cannot block yourself!"), + 403, + $this->format + ); + return; + } + + if (!$this->user->hasBlocked($this->other)) { + if (Event::handle('StartBlockProfile', array($this->user, $this->other))) { + $result = $this->user->block($this->other); + if ($result) { + Event::handle('EndBlockProfile', array($this->user, $this->other)); + } + } + } + + if ($this->user->hasBlocked($this->other)) { $this->initDocument($this->format); $this->showProfile($this->other, $this->format); $this->endDocument($this->format);