Skip to content

Commit 26305e3

Browse files
committed
patch
1 parent 6a6d585 commit 26305e3

14 files changed

Lines changed: 63 additions & 42 deletions

File tree

documentation/docs/usage/hosts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ From the **HOSTS** tab:
7676

7777
[![Select host](https://assets.repomanager.net/repomanager/usage/hosts/select-host.png)](https://assets.repomanager.net/repomanager/usage/hosts/select-host.png)
7878

79-
**Step 2:** Use the `Request packages information` button.
79+
**Step 2:** Use the `Request package information` button.
8080

8181
It can take some minutes to be sent depending on the number of packages installed on the host.
8282

www/controllers/Group/Group.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ public function exists(string $name = '')
9595
*/
9696
public function new(string $name) : void
9797
{
98-
if (!IS_ADMIN) {
99-
throw new Exception('You are not allowed to perform this action');
100-
}
101-
10298
$name = Validate::string($name);
10399

104100
/**
@@ -141,10 +137,6 @@ public function new(string $name) : void
141137
*/
142138
public function edit(int $id, string $name, array $data) : void
143139
{
144-
if (!IS_ADMIN) {
145-
throw new Exception('You are not allowed to perform this action');
146-
}
147-
148140
/**
149141
* Check if group exists
150142
*/
@@ -197,10 +189,6 @@ public function edit(int $id, string $name, array $data) : void
197189
*/
198190
public function delete(array $groups) : void
199191
{
200-
if (!IS_ADMIN) {
201-
throw new Exception('You are not allowed to perform this action');
202-
}
203-
204192
foreach ($groups as $id) {
205193
// Check if group exists
206194
if (!$this->existsId($id)) {

www/controllers/Host.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Controllers;
44

5+
use Controllers\User\Permission\Host as HostPermission;
56
use Controllers\Host\Package\Package as HostPackage;
67
use Controllers\Host\Request as HostRequest;
78
use Controllers\Group\Host as HostGroup;
@@ -102,8 +103,12 @@ public function getHostWithProfile(string $profile) : array
102103
/**
103104
* Edit the display settings on the hosts page
104105
*/
105-
public function setSettings(string $packagesConsideredOutdated, string $packagesConsideredCritical) : void
106+
public function setSettings(int $packagesConsideredOutdated, int $packagesConsideredCritical) : void
106107
{
108+
if (!HostPermission::allowedAction('edit-settings')) {
109+
throw new Exception('You are not allowed to perform this action');
110+
}
111+
107112
if (!is_numeric($packagesConsideredOutdated) or !is_numeric($packagesConsideredCritical)) {
108113
throw new Exception('Parameters must be numeric');
109114
}

www/controllers/Layout/Panel/vars/hosts/groups/list.vars.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2-
if (!IS_ADMIN) {
2+
use Controllers\User\Permission\Host as HostPermission;
3+
4+
// If the user does not have permission to edit host groups, prevent access to this panel
5+
if (!HostPermission::allowedAction('edit-groups')) {
36
throw new Exception('You are not allowed to access this panel');
47
}
58

www/controllers/Layout/Panel/vars/hosts/settings.vars.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2-
if (!IS_ADMIN) {
2+
use \Controllers\User\Permission\Host as HostPermission;
3+
4+
if (!HostPermission::allowedAction('edit-settings')) {
35
throw new Exception('You are not allowed to access this panel');
46
}
57

www/controllers/Layout/Panel/vars/repos/groups/list.vars.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
2-
if (!IS_ADMIN) {
2+
use Controllers\User\Permission\Repo as RepoPermission;
3+
4+
// If the user does not have permission to edit repository groups, prevent access to this panel
5+
if (!RepoPermission::allowedAction('edit-groups')) {
36
throw new Exception('You are not allowed to access this panel');
47
}
58

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
use Controllers\User\Permission\Repo as RepoPermission;
3+
4+
// If the user does not have permission to edit source repositories, prevent access to this panel.
5+
if (!RepoPermission::allowedAction('edit-source')) {
6+
throw new Exception('You are not allowed to access this panel');
7+
}

www/controllers/Profile.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Controllers;
44

55
use Exception;
6+
use Controllers\User\Permission\Host as HostPermission;
67
use Controllers\History\Save as History;
78
use Controllers\Utils\Validate;
89

@@ -202,7 +203,7 @@ public function countHosts(string $profile)
202203
*/
203204
public function new(string $name)
204205
{
205-
if (!IS_ADMIN) {
206+
if (!HostPermission::allowedAction('edit-profiles')) {
206207
throw new Exception('You are not allowed to perform this action');
207208
}
208209

@@ -232,7 +233,7 @@ public function new(string $name)
232233
*/
233234
public function duplicate(string $id)
234235
{
235-
if (!IS_ADMIN) {
236+
if (!HostPermission::allowedAction('edit-profiles')) {
236237
throw new Exception('You are not allowed to perform this action');
237238
}
238239

@@ -303,7 +304,7 @@ public function duplicate(string $id)
303304
*/
304305
public function delete(array $profilesId) : void
305306
{
306-
if (!IS_ADMIN) {
307+
if (!HostPermission::allowedAction('edit-profiles')) {
307308
throw new Exception('You are not allowed to perform this action');
308309
}
309310

@@ -328,7 +329,7 @@ public function delete(array $profilesId) : void
328329
*/
329330
public function configure(int $id, string $name, array $reposIds, array $packagesExcluded, array $packagesMajorExcluded, array $serviceNeedReload, array $serviceNeedRestart, string $notes)
330331
{
331-
if (!IS_ADMIN) {
332+
if (!HostPermission::allowedAction('edit-profiles')) {
332333
throw new Exception('You are not allowed to perform this action');
333334
}
334335

www/controllers/User/Permission.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function set(int $id, array $reposView, array $reposActions, array $tasks
137137
if (!empty($reposActions)) {
138138
foreach (array_filter($reposActions) as $action) {
139139
// Check that action is valid
140-
if (!in_array($action, ['create', 'update', 'duplicate', 'rebuild', 'rename', 'edit', 'delete', 'env', 'removeEnv', 'browse', 'upload-package', 'delete-package', 'view-stats'])) {
140+
if (!in_array($action, ['create', 'update', 'duplicate', 'rebuild', 'rename', 'edit', 'delete', 'env', 'removeEnv', 'browse', 'edit-source', 'edit-groups', 'upload-package', 'delete-package', 'view-stats'])) {
141141
throw new Exception('Invalid action: ' . $action);
142142
}
143143

@@ -167,7 +167,7 @@ public function set(int $id, array $reposView, array $reposActions, array $tasks
167167
if (!empty($hostsActions)) {
168168
foreach (array_filter($hostsActions) as $action) {
169169
// Check that action is valid
170-
if (!in_array($action, ['request-general-infos', 'request-packages-infos', 'update-packages', 'reset', 'delete'])) {
170+
if (!in_array($action, ['request-general-infos', 'request-packages-infos', 'update-packages', 'reset', 'delete', 'edit-profiles', 'edit-groups', 'edit-settings'])) {
171171
throw new Exception('Invalid action: ' . $action);
172172
}
173173

www/public/resources/js/classes/Host.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Host
6161
if (allowedActions.includes('request-packages-infos')) {
6262
buttons.push(
6363
{
64-
'text': 'Request packages information',
64+
'text': 'Request package information',
6565
'color': 'blue-alt',
6666
'callback': function () {
6767
executeAction('request-packages-infos', hosts);

0 commit comments

Comments
 (0)