groupunblock.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Block a user from a group action class.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@status.net>
  10. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  11. * @link http://status.net/
  12. *
  13. * StatusNet - the distributed open-source microblogging tool
  14. * Copyright (C) 2008, 2009, StatusNet, Inc.
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Unblock a user from a group
  34. *
  35. * @category Action
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  39. * @link http://status.net/
  40. */
  41. class GroupunblockAction extends Action
  42. {
  43. var $profile = null;
  44. var $group = null;
  45. /**
  46. * Take arguments for running
  47. *
  48. * @param array $args $_REQUEST args
  49. *
  50. * @return boolean success flag
  51. */
  52. function prepare(array $args = array())
  53. {
  54. parent::prepare($args);
  55. if (!common_logged_in()) {
  56. // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
  57. $this->clientError(_('Not logged in.'));
  58. }
  59. $token = $this->trimmed('token');
  60. if (empty($token) || $token != common_session_token()) {
  61. // TRANS: Client error displayed when the session token does not match or is not given.
  62. $this->clientError(_('There was a problem with your session token. Try again, please.'));
  63. }
  64. $id = $this->trimmed('unblockto');
  65. if (empty($id)) {
  66. // TRANS: Client error displayed when trying to unblock a user from a group without providing a profile.
  67. $this->clientError(_('No profile specified.'));
  68. }
  69. $this->profile = Profile::getKV('id', $id);
  70. if (empty($this->profile)) {
  71. // TRANS: Client error displayed when trying to unblock a user from a group without providing an existing profile.
  72. $this->clientError(_('No profile with that ID.'));
  73. }
  74. $group_id = $this->trimmed('unblockgroup');
  75. if (empty($group_id)) {
  76. // TRANS: Client error displayed when trying to unblock a user from a group without providing a group.
  77. $this->clientError(_('No group specified.'));
  78. }
  79. $this->group = User_group::getKV('id', $group_id);
  80. if (empty($this->group)) {
  81. // TRANS: Client error displayed when trying to unblock a user from a non-existing group.
  82. $this->clientError(_('No such group.'));
  83. }
  84. $user = common_current_user();
  85. if (!$user->isAdmin($this->group)) {
  86. // TRANS: Client error displayed when trying to unblock a user from a group without being an administrator for the group.
  87. $this->clientError(_('Only an admin can unblock group members.'), 401);
  88. }
  89. if (!Group_block::isBlocked($this->group, $this->profile)) {
  90. // TRANS: Client error displayed when trying to unblock a non-blocked user from a group.
  91. $this->clientError(_('User is not blocked from group.'));
  92. }
  93. return true;
  94. }
  95. /**
  96. * Handle request
  97. *
  98. * @param array $args $_REQUEST args; handled in prepare()
  99. *
  100. * @return void
  101. */
  102. function handle()
  103. {
  104. parent::handle();
  105. if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  106. $this->unblockProfile();
  107. }
  108. }
  109. /**
  110. * Unblock a user.
  111. *
  112. * @return void
  113. */
  114. function unblockProfile()
  115. {
  116. $result = Group_block::unblockProfile($this->group, $this->profile);
  117. if (!$result) {
  118. // TRANS: Server error displayed when unblocking a user from a group fails because of an unknown error.
  119. $this->serverError(_('Error removing the block.'));
  120. }
  121. foreach ($this->args as $k => $v) {
  122. if ($k == 'returnto-action') {
  123. $action = $v;
  124. } else if (substr($k, 0, 9) == 'returnto-') {
  125. $args[substr($k, 9)] = $v;
  126. }
  127. }
  128. if ($action) {
  129. common_redirect(common_local_url($action, $args), 303);
  130. } else {
  131. common_redirect(common_local_url('blockedfromgroup', array('nickname' => $this->group->nickname)), 303);
  132. }
  133. }
  134. }