apiqvittersandboxdestroy.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3. · ·
  4. · Unsandbox a user ·
  5. · ·
  6. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7. · ·
  8. · ·
  9. · Q V I T T E R ·
  10. · ·
  11. · https://git.gnu.io/h2p/Qvitter ·
  12. · ·
  13. · ·
  14. · <o) ·
  15. · /_//// ·
  16. · (____/ ·
  17. · (o< ·
  18. · o> \\\\_\ ·
  19. · \\) \____) ·
  20. · ·
  21. · ·
  22. · ·
  23. · Qvitter is free software: you can redistribute it and / or modify it ·
  24. · under the terms of the GNU Affero General Public License as published by ·
  25. · the Free Software Foundation, either version three of the License or (at ·
  26. · your option) any later version. ·
  27. · ·
  28. · Qvitter is distributed in hope that it will be useful but WITHOUT ANY ·
  29. · WARRANTY; without even the implied warranty of MERCHANTABILTY or FITNESS ·
  30. · FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for ·
  31. · more details. ·
  32. · ·
  33. · You should have received a copy of the GNU Affero General Public License ·
  34. · along with Qvitter. If not, see <http://www.gnu.org/licenses/>. ·
  35. · ·
  36. · Contact h@nnesmannerhe.im if you have any questions. ·
  37. · ·
  38. · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
  39. if (!defined('GNUSOCIAL')) { exit(1); }
  40. class ApiQvitterSandboxDestroyAction extends ApiAuthAction
  41. {
  42. protected $needPost = true;
  43. /**
  44. * Take arguments for running
  45. *
  46. * @param array $args $_REQUEST args
  47. *
  48. * @return boolean success flag
  49. */
  50. protected function prepare(array $args=array())
  51. {
  52. parent::prepare($args);
  53. $this->format = 'json';
  54. $this->other = $this->getTargetProfile($this->arg('id'));
  55. return true;
  56. }
  57. /**
  58. * Handle the request
  59. *
  60. * @param array $args $_REQUEST data (unused)
  61. *
  62. * @return void
  63. */
  64. protected function handle()
  65. {
  66. parent::handle();
  67. if (!$this->other instanceof Profile) {
  68. $this->clientError(_('No such user.'), 404);
  69. }
  70. if ($this->scoped->id == $this->other->id) {
  71. $this->clientError(_("You cannot unsandbox yourself!"), 403);
  72. }
  73. if (!$this->scoped->hasRight(Right::SANDBOXUSER)) {
  74. $this->clientError(_('You cannot unsandbox users on this site.'), 403);
  75. }
  76. // only unsandbox if the user is sandboxed
  77. if ($this->other->isSandboxed()) {
  78. try {
  79. $this->other->unsandbox();
  80. } catch (Exception $e) {
  81. $this->clientError($e->getMessage(), $e->getCode());
  82. }
  83. }
  84. $this->initDocument('json');
  85. $this->showJsonObjects($this->twitterUserArray($this->other));
  86. $this->endDocument('json');
  87. }
  88. }