1 | <?php |
||
2 | /****************************************************************************** |
||
3 | * Wikipedia Account Creation Assistance tool * |
||
4 | * * |
||
5 | * All code in this file is released into the public domain by the ACC * |
||
6 | * Development Team. Please see team.json for a list of contributors. * |
||
7 | ******************************************************************************/ |
||
8 | |||
9 | namespace Waca\Fragments; |
||
10 | |||
11 | use Waca\DataObjects\Comment; |
||
12 | use Waca\DataObjects\JobQueue; |
||
13 | use Waca\DataObjects\User; |
||
14 | use Waca\Helpers\SearchHelpers\JobQueueSearchHelper; |
||
15 | use Waca\Pages\PageBan; |
||
16 | use Waca\Pages\PageDomainManagement; |
||
17 | use Waca\Pages\PageEmailManagement; |
||
18 | use Waca\Pages\PageErrorLogViewer; |
||
19 | use Waca\Pages\PageJobQueue; |
||
20 | use Waca\Pages\PageListFlaggedComments; |
||
21 | use Waca\Pages\PageLog; |
||
22 | use Waca\Pages\PageMain; |
||
23 | use Waca\Pages\PageQueueManagement; |
||
24 | use Waca\Pages\PageSearch; |
||
25 | use Waca\Pages\PageSiteNotice; |
||
26 | use Waca\Pages\PageUserManagement; |
||
27 | use Waca\Pages\PageViewRequest; |
||
28 | use Waca\Pages\PageWelcomeTemplateManagement; |
||
29 | use Waca\Pages\Statistics\StatsMain; |
||
30 | use Waca\Pages\Statistics\StatsUsers; |
||
31 | use Waca\PdoDatabase; |
||
32 | use Waca\Security\DomainAccessManager; |
||
33 | use Waca\Security\RoleConfiguration; |
||
34 | use Waca\Security\SecurityManager; |
||
35 | |||
36 | trait NavigationMenuAccessControl |
||
37 | { |
||
38 | protected abstract function assign($name, $value); |
||
39 | |||
40 | /** |
||
41 | * @return SecurityManager |
||
42 | */ |
||
43 | protected abstract function getSecurityManager(); |
||
44 | |||
45 | public abstract function getDomainAccessManager(): DomainAccessManager; |
||
46 | |||
47 | /** |
||
48 | * @param $currentUser |
||
49 | */ |
||
50 | protected function setupNavMenuAccess($currentUser) |
||
51 | { |
||
52 | $this->assign('nav__canRequests', $this->getSecurityManager() |
||
53 | ->allows(PageMain::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
54 | |||
55 | $this->assign('nav__canLogs', $this->getSecurityManager() |
||
56 | ->allows(PageLog::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
57 | $this->assign('nav__canUsers', $this->getSecurityManager() |
||
58 | ->allows(StatsUsers::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
59 | $this->assign('nav__canSearch', $this->getSecurityManager() |
||
60 | ->allows(PageSearch::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
61 | $this->assign('nav__canStats', $this->getSecurityManager() |
||
62 | ->allows(StatsMain::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
63 | |||
64 | $this->assign('nav__canBan', $this->getSecurityManager() |
||
65 | ->allows(PageBan::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
66 | $this->assign('nav__canEmailMgmt', $this->getSecurityManager() |
||
67 | ->allows(PageEmailManagement::class, RoleConfiguration::MAIN, |
||
68 | $currentUser) === SecurityManager::ALLOWED); |
||
69 | $this->assign('nav__canWelcomeMgmt', $this->getSecurityManager() |
||
70 | ->allows(PageWelcomeTemplateManagement::class, RoleConfiguration::MAIN, |
||
71 | $currentUser) === SecurityManager::ALLOWED); |
||
72 | $this->assign('nav__canSiteNoticeMgmt', $this->getSecurityManager() |
||
73 | ->allows(PageSiteNotice::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
74 | $this->assign('nav__canUserMgmt', $this->getSecurityManager() |
||
75 | ->allows(PageUserManagement::class, RoleConfiguration::MAIN, |
||
76 | $currentUser) === SecurityManager::ALLOWED); |
||
77 | $this->assign('nav__canJobQueue', $this->getSecurityManager() |
||
78 | ->allows(PageJobQueue::class, RoleConfiguration::MAIN, |
||
79 | $currentUser) === SecurityManager::ALLOWED); |
||
80 | $this->assign('nav__canDomainMgmt', $this->getSecurityManager() |
||
81 | ->allows(PageDomainManagement::class, RoleConfiguration::MAIN, |
||
82 | $currentUser) === SecurityManager::ALLOWED); |
||
83 | $this->assign('nav__canFlaggedComments', $this->getSecurityManager() |
||
84 | ->allows(PageListFlaggedComments::class, RoleConfiguration::MAIN, |
||
85 | $currentUser) === SecurityManager::ALLOWED); |
||
86 | $this->assign('nav__canQueueMgmt', $this->getSecurityManager() |
||
87 | ->allows(PageQueueManagement::class, RoleConfiguration::MAIN, |
||
88 | $currentUser) === SecurityManager::ALLOWED); |
||
89 | $this->assign('nav__canErrorLog', $this->getSecurityManager() |
||
90 | ->allows(PageErrorLogViewer::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
91 | |||
92 | $this->assign('nav__canViewRequest', $this->getSecurityManager() |
||
93 | ->allows(PageViewRequest::class, RoleConfiguration::MAIN, $currentUser) === SecurityManager::ALLOWED); |
||
94 | |||
95 | $this->assign('nav__domainList', []); |
||
96 | if ($this->getDomainAccessManager() !== null) { |
||
97 | $this->assign('nav__domainList', $this->getDomainAccessManager()->getAllowedDomains($currentUser)); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Sets up the badges to draw attention to issues on various admin pages. |
||
103 | * |
||
104 | * This function checks to see if a user can access the pages, and if so checks the count of problem areas. |
||
105 | * If problem areas are found, a number greater than 0 will cause the badge to show up. |
||
106 | * |
||
107 | * @param User $currentUser The current user |
||
108 | * @param PdoDatabase $database Database instance |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | public function setUpNavBarBadges($currentUser, $database) { |
||
113 | // Set up some variables. |
||
114 | // A size of 0 causes nothing to show up on the page (checked on navigation-menu.tpl) so leaving it 0 here is fine. |
||
115 | $countOfFlagged = 0; |
||
116 | $countOfJobQueue = 0; |
||
117 | |||
118 | // Count of flagged comments: |
||
119 | if($this->barrierTest(RoleConfiguration::MAIN, $currentUser, PageListFlaggedComments::class)) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
120 | // We want all flagged comments that haven't been acknowledged if we can visit the page. |
||
121 | $countOfFlagged = sizeof(Comment::getFlaggedComments($database)); |
||
122 | } |
||
123 | |||
124 | // Count of failed job queue changes: |
||
125 | if($this->barrierTest(RoleConfiguration::MAIN, $currentUser, PageJobQueue::class)) { |
||
126 | // We want all failed jobs that haven't been acknowledged if we can visit the page. |
||
127 | JobQueueSearchHelper::get($database) |
||
128 | ->statusIn([JobQueue::STATUS_FAILED]) |
||
129 | ->notAcknowledged() |
||
130 | ->getRecordCount($countOfJobQueue); |
||
131 | } |
||
132 | |||
133 | // To generate the main badge, add both up. |
||
134 | // If we add more badges in the future, don't forget to add them here! |
||
135 | $countOfAll = $countOfFlagged + $countOfJobQueue; |
||
136 | |||
137 | // Set badge variables |
||
138 | $this->assign("nav__numFlaggedComments", $countOfFlagged); |
||
139 | $this->assign("nav__numJobQueueFailed", $countOfJobQueue); |
||
140 | $this->assign("nav__numAdmin", $countOfAll); |
||
141 | } |
||
142 | } |
||
143 |