Skip to content

Commit 2410d34

Browse files
authored
Fix#164 - Permissions not working at Group level (#189)
* Fix#164 - Permissions not working at Group level * Fixing php-cs-fixer audit issue
1 parent 5c6a7dd commit 2410d34

3 files changed

Lines changed: 27 additions & 25 deletions

File tree

lib/WeatherMap.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ function ReadData() {
10631063
if ($target[0] != '') {
10641064
$matched_by = $target[5];
10651065

1066-
[$in,$out,$datatime] = $this->plugins['data'][$target[5]]->ReadData($targetstring, $this, $myobj);
1066+
[$in, $out, $datatime] = $this->plugins['data'][$target[5]]->ReadData($targetstring, $this, $myobj);
10671067
}
10681068

10691069
if (($in === null) && ($out === null)) {

lib/WeatherMap.functions.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,49 +78,49 @@ function get_allowed_weathermaps($userid, $group_id = null) {
7878
return $maps;
7979
}
8080

81-
function is_weathermap_allowed($mapid, $userid, $group_id = null) {
81+
function is_weathermap_allowed($mapid, $userid) {
8282
// Special Group Limiter
8383
$sql_where = '';
84-
85-
if ($group_id !== null) {
86-
$sql_where = 'AND group_id = ' . $group_id;
87-
}
84+
$params = [$mapid];
8885

8986
// Try all users first
90-
$allowed = db_fetch_cell_prepared("SELECT mapid
87+
$allowed = db_fetch_cell_prepared('SELECT mapid
9188
FROM weathermap_auth
9289
WHERE userid = 0
93-
$sql_where
94-
AND mapid = ?",
95-
[$mapid]);
90+
AND mapid = ?',
91+
$params);
9692

97-
// Try user first
9893
if ($allowed) {
9994
return true;
10095
}
10196

102-
$allowed = db_fetch_cell_prepared("SELECT mapid
97+
$params[] = $userid;
98+
99+
// Try specific user second
100+
$allowed = db_fetch_cell_prepared('SELECT mapid
103101
FROM weathermap_auth
104-
WHERE userid = ?
105-
$sql_where
106-
AND mapid = ?",
107-
[$userid, $mapid]);
102+
WHERE mapid = ?
103+
AND userid = ?',
104+
$params);
108105

109-
// Try user second
110106
if ($allowed) {
111107
return true;
112108
}
113109

114-
$allowed - db_fetch_cell_prepared("SELECT mapid
110+
// Try user group last
111+
$allowed = db_fetch_cell_prepared('SELECT mapid
115112
FROM weathermap_auth AS wa
116113
INNER JOIN user_auth_group AS uag
117-
ON uag.id = -wa.userid
118-
WHERE uag.id = ?
119-
$sql_where
120-
AND mapid = ?",
121-
[-$userid, $mapid]);
114+
ON wa.userid < 0
115+
AND uag.id = ABS(wa.userid)
116+
INNER JOIN user_auth_group_members AS uagm
117+
ON uag.id = uagm.group_id
118+
WHERE wa.mapid = ?
119+
AND uagm.user_id = ?
120+
AND uag.enabled = "on"
121+
AND uagm.group_id > 0',
122+
$params);
122123

123-
// Try user second
124124
if ($allowed) {
125125
return true;
126126
}

weathermap-cacti-plugin-mgmt.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ function maplist() {
10681068

10691069
if ($ulist['groups'] > 0) {
10701070
$url .= ($found ? ', ' : '') . ($ulist['groups'] == 1 ? __('1 Group', 'weathermap') : __('%d Groups', $ulist['groups'], 'weathermap'));
1071+
$found = true;
10711072
}
10721073

10731074
if ($ulist['users'] > 0) {
@@ -2010,7 +2011,8 @@ function perms_get_records(&$total_rows, $rows = 30, $apply_limits = true) {
20102011
SELECT id, name, description, 'group' AS type, wa.mapid AS allowed, 'N/A' AS realm
20112012
FROM user_auth_group AS uag
20122013
$join JOIN (SELECT * FROM weathermap_auth WHERE mapid = ?) AS wa
2013-
ON uag.id = -wa.userid
2014+
ON wa.userid < 0
2015+
AND uag.id = ABS(wa.userid)
20142016
AND uag.enabled = 'on'
20152017
WHERE (wa.mapid = ? OR (wa.mapid IS NULL AND uag.enabled = 'on'))
20162018
$sql_where2

0 commit comments

Comments
 (0)