Users.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Rules;
  10. use ForkBB\Models\Model;
  11. use ForkBB\Models\Rules;
  12. use ForkBB\Models\User\User;
  13. use ForkBB\Models\Rules\Profile as ProfileRules;
  14. class Users extends Rules
  15. {
  16. /**
  17. * Инициализирует
  18. */
  19. public function init(): Users
  20. {
  21. $this->setAttrs([]);
  22. $this->ready = true;
  23. $this->user = $this->c->user;
  24. return $this;
  25. }
  26. protected function getviewIP(): bool
  27. {
  28. return $this->user->isAdmin;
  29. }
  30. protected function getdeleteUsers(): bool
  31. {
  32. return $this->user->isAdmin;
  33. }
  34. protected function getbanUsers(): bool
  35. {
  36. return $this->user->isAdmin || ($this->user->isAdmMod && 1 === $this->user->g_mod_ban_users);
  37. }
  38. protected function getchangeGroup(): bool
  39. {
  40. return $this->user->isAdmin;
  41. }
  42. public function canDeleteUser(User $user): bool
  43. {
  44. if (! $this->profileRules instanceof ProfileRules) {
  45. $this->profileRules = $this->c->ProfileRules;
  46. }
  47. return $this->profileRules->setUser($user)->deleteUser;
  48. }
  49. public function canBanUser(User $user): bool
  50. {
  51. if (! $this->profileRules instanceof ProfileRules) {
  52. $this->profileRules = $this->c->ProfileRules;
  53. }
  54. return $this->profileRules->setUser($user)->banUser;
  55. }
  56. public function canChangeGroup(User $user, bool $profile = false): bool
  57. {
  58. if (! $this->profileRules instanceof ProfileRules) {
  59. $this->profileRules = $this->c->ProfileRules;
  60. }
  61. if (
  62. $profile
  63. && $this->user->isAdmin
  64. ) {
  65. return true;
  66. } elseif (
  67. ! $profile
  68. && $user->isAdmin
  69. ) {
  70. return false;
  71. }
  72. return $this->profileRules->setUser($user)->changeGroup;
  73. }
  74. }