silence&sandbox api

This commit is contained in:
Hannes Mannerheim 2016-02-29 19:37:06 +01:00
parent 9f24af8a02
commit 876b15a5cd
7 changed files with 314 additions and 8 deletions

View File

@ -159,8 +159,14 @@ class QvitterPlugin extends Plugin {
$m->connect('api/qvitter/silenced.:format',
array('action' => 'ApiQvitterSilenced',
'format' => '(xml|json)'));
$m->connect('api/qvitter/sandbox/create.json',
array('action' => 'ApiQvitterSandboxCreate'));
$m->connect('api/qvitter/sandbox/destroy.json',
array('action' => 'ApiQvitterSandboxDestroy'));
$m->connect('api/qvitter/silence/create.json',
array('action' => 'ApiQvitterSilenceCreate'));
$m->connect('api/qvitter/silence/destroy.json',
array('action' => 'ApiQvitterSilenceDestroy'));
$m->connect('services/oembed.:format',
array('action' => 'apiqvitteroembednotice',
'format' => '(xml|json)'));

View File

@ -0,0 +1,104 @@
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
· ·
· Sandbox a user ·
· ·
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
· ·
· ·
· Q V I T T E R ·
· ·
· https://git.gnu.io/h2p/Qvitter ·
· ·
· ·
· <o) ·
· /_//// ·
· (____/ ·
· (o< ·
· o> \\\\_\ ·
· \\) \____) ·
· ·
· ·
· ·
· Qvitter is free software: you can redistribute it and / or modify it ·
· under the terms of the GNU Affero General Public License as published by ·
· the Free Software Foundation, either version three of the License or (at ·
· your option) any later version. ·
· ·
· Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
· WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
· FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
· more details. ·
· ·
· You should have received a copy of the GNU Affero General Public License ·
· along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
· ·
· Contact h@nnesmannerhe.im if you have any questions. ·
· ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
if (!defined('GNUSOCIAL')) { exit(1); }
class ApiQvitterSandboxCreateAction extends ApiAuthAction
{
/**
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*/
protected function prepare(array $args=array())
{
parent::prepare($args);
$this->other = $this->getTargetProfile($this->arg('id'));
return true;
}
/**
* Handle the request
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
protected function handle()
{
parent::handle();
if (!$this->other instanceof Profile) {
$this->clientError(_('No such user.'), 404);
}
if ($this->scoped->id == $this->other->id) {
$this->clientError(_("You cannot sandbox yourself!"), 403);
}
if (!$this->scoped->hasRight(Right::SANDBOXUSER)) {
$this->clientError(_('You cannot sandbox users on this site.'), 403);
}
// Only administrators can sandbox other privileged users (such as others who have the right to sandbox).
if ($this->scoped->isPrivileged() && !$this->scoped->hasRole(Profile_role::ADMINISTRATOR)) {
$this->clientError(_('You cannot sandbox other privileged users.'), 403);
}
// only sandbox of the user isn't sandboxed
if (!$this->isSandboxed()) {
try {
$this->other->sandbox();
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode());
}
}
$this->initDocument('json');
$this->showJsonObjects($this->twitterUserArray($this->other));
$this->endDocument('json');
}
}

View File

@ -0,0 +1,100 @@
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
· ·
· Unsandbox a user ·
· ·
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
· ·
· ·
· Q V I T T E R ·
· ·
· https://git.gnu.io/h2p/Qvitter ·
· ·
· ·
· <o) ·
· /_//// ·
· (____/ ·
· (o< ·
· o> \\\\_\ ·
· \\) \____) ·
· ·
· ·
· ·
· Qvitter is free software: you can redistribute it and / or modify it ·
· under the terms of the GNU Affero General Public License as published by ·
· the Free Software Foundation, either version three of the License or (at ·
· your option) any later version. ·
· ·
· Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
· WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
· FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
· more details. ·
· ·
· You should have received a copy of the GNU Affero General Public License ·
· along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
· ·
· Contact h@nnesmannerhe.im if you have any questions. ·
· ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
if (!defined('GNUSOCIAL')) { exit(1); }
class ApiQvitterSandboxDestroyAction extends ApiAuthAction
{
/**
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*/
protected function prepare(array $args=array())
{
parent::prepare($args);
$this->other = $this->getTargetProfile($this->arg('id'));
return true;
}
/**
* Handle the request
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
protected function handle()
{
parent::handle();
if (!$this->other instanceof Profile) {
$this->clientError(_('No such user.'), 404);
}
if ($this->scoped->id == $this->other->id) {
$this->clientError(_("You cannot unsandbox yourself!"), 403);
}
if (!$this->scoped->hasRight(Right::SANDBOXUSER)) {
$this->clientError(_('You cannot unsandbox users on this site.'), 403);
}
// only unsandbox if the user is sandboxed
if ($this->isSandboxed()) {
try {
$this->other->sandbox();
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode());
}
}
$this->initDocument('json');
$this->showJsonObjects($this->twitterUserArray($this->other));
$this->endDocument('json');
}
}

View File

@ -110,10 +110,7 @@ class ApiQvitterSandboxedAction extends ApiPrivateAuthAction
$profile = $this->getSandboxed(
($this->page - 1) * $this->count,
$this->count,
$this->since_id,
$this->max_id
);
$this->count);
while ($profile->fetch()) {
$profiles[] = clone($profile);
@ -130,6 +127,7 @@ class ApiQvitterSandboxedAction extends ApiPrivateAuthAction
function getSandboxed($offset=null, $limit=null) // offset is null because DataObject wants it, 0 would mean no results
{
$profiles = new Profile();
$profiles->joinAdd(array('id', 'profile_role:profile_id'));
$profiles->whereAdd(sprintf('profile_role.role = \'%s\'', Profile_role::SANDBOXED));

View File

@ -82,6 +82,10 @@ class ApiQvitterSilenceCreateAction extends ApiAuthAction
try {
$this->other->silenceAs($this->scoped);
} catch (AlreadyFulfilledException $e) {
// don't throw client error here, just return the user array like
// if we successfully silenced the user. the client is only interested
// in making sure the user is silenced.
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode());
}

View File

@ -110,10 +110,7 @@ class ApiQvitterSilencedAction extends ApiPrivateAuthAction
$profile = $this->getSilenced(
($this->page - 1) * $this->count,
$this->count,
$this->since_id,
$this->max_id
);
$this->count);
while ($profile->fetch()) {
$profiles[] = clone($profile);

View File

@ -0,0 +1,97 @@
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
· ·
· Unsilence a user ·
· ·
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
· ·
· ·
· Q V I T T E R ·
· ·
· https://git.gnu.io/h2p/Qvitter ·
· ·
· ·
· <o) ·
· /_//// ·
· (____/ ·
· (o< ·
· o> \\\\_\ ·
· \\) \____) ·
· ·
· ·
· ·
· Qvitter is free software: you can redistribute it and / or modify it ·
· under the terms of the GNU Affero General Public License as published by ·
· the Free Software Foundation, either version three of the License or (at ·
· your option) any later version. ·
· ·
· Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
· WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
· FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
· more details. ·
· ·
· You should have received a copy of the GNU Affero General Public License ·
· along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
· ·
· Contact h@nnesmannerhe.im if you have any questions. ·
· ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
if (!defined('GNUSOCIAL')) { exit(1); }
class ApiQvitterSilenceDestroyAction extends ApiAuthAction
{
/**
* Take arguments for running
*
* @param array $args $_REQUEST args
*
* @return boolean success flag
*/
protected function prepare(array $args=array())
{
parent::prepare($args);
$this->other = $this->getTargetProfile($this->arg('id'));
return true;
}
/**
* Handle the request
*
* @param array $args $_REQUEST data (unused)
*
* @return void
*/
protected function handle()
{
parent::handle();
if (!$this->other instanceof Profile) {
$this->clientError(_('No such user.'), 404);
}
if ($this->scoped->id == $this->other->id) {
$this->clientError(_("You cannot unsilence yourself!"), 403);
}
try {
$this->other->unsilenceAs($this->scoped);
} catch (AlreadyFulfilledException $e) {
// don't throw client error here, just return the user array like
// if we successfully unsilenced the user. the client is only interested
// in making sure the user is unsilenced.
} catch (Exception $e) {
$this->clientError($e->getMessage(), $e->getCode());
}
$this->initDocument('json');
$this->showJsonObjects($this->twitterUserArray($this->other));
$this->endDocument('json');
}
}