Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcus Eibrink-Lunzenauer
Stud.IP
Commits
b79d2015
Commit
b79d2015
authored
2 years ago
by
Jan-Hendrik Willms
Committed by
Elmar Ludwig
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix query that manages inherited roles from a faculty role assignment, fixes #1180
Closes #1180 Merge request
studip/studip!699
parent
4b468ca5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/plugins/db/RolePersistence.class.php
+20
-20
20 additions, 20 deletions
lib/plugins/db/RolePersistence.class.php
with
20 additions
and
20 deletions
lib/plugins/db/RolePersistence.class.php
+
20
−
20
View file @
b79d2015
...
@@ -13,7 +13,9 @@
...
@@ -13,7 +13,9 @@
*/
*/
class
RolePersistence
class
RolePersistence
{
{
const
ROLES_CACHE_KEY
=
'plugins/rolepersistence/roles'
;
const
ROLES_CACHE_KEY
=
'roles'
;
const
USER_ROLES_CACHE_KEY
=
'roles/user'
;
const
PLUGIN_ROLES_CACHE_KEY
=
'roles/plugin'
;
/**
/**
* Returns all available roles.
* Returns all available roles.
...
@@ -181,9 +183,7 @@ class RolePersistence
...
@@ -181,9 +183,7 @@ class RolePersistence
public
static
function
getAssignedRoleInstitutes
(
$user_id
,
$role_id
)
public
static
function
getAssignedRoleInstitutes
(
$user_id
,
$role_id
)
{
{
$roles
=
self
::
loadUserRoles
(
$user_id
);
$roles
=
self
::
loadUserRoles
(
$user_id
);
return
isset
(
$roles
[
$role_id
])
return
$roles
[
$role_id
]
??
[];
?
$roles
[
$role_id
][
'institutes'
]
:
[];
}
}
/**
/**
...
@@ -209,11 +209,11 @@ class RolePersistence
...
@@ -209,11 +209,11 @@ class RolePersistence
$user_roles
=
self
::
loadUserRoles
(
$userid
,
true
);
$user_roles
=
self
::
loadUserRoles
(
$userid
,
true
);
return
isset
(
$user_roles
[
$role_id
])
return
isset
(
$user_roles
[
$role_id
])
?
(
&&
(
in_array
(
$institut_id
,
$user_roles
[
$role_id
][
'institutes'
])
!
$institut_id
||
in_array
(
$
faculty
_id
,
$user_roles
[
$role_id
]
[
'institutes'
]
)
||
in_array
(
$
institut
_id
,
$user_roles
[
$role_id
])
)
||
in_array
(
$faculty_id
,
$user_roles
[
$role_id
]
)
:
false
;
)
;
}
}
private
static
function
loadUserRoles
(
$user_id
,
$implicit
=
false
)
private
static
function
loadUserRoles
(
$user_id
,
$implicit
=
false
)
...
@@ -229,13 +229,6 @@ class RolePersistence
...
@@ -229,13 +229,6 @@ class RolePersistence
UNION
UNION
SELECT `roleid`, `fakultaets_id` AS `institut_id`, 1 AS explicit
FROM `roles_user`
JOIN `Institute` USING (`institut_id`)
WHERE `userid` = :user_id
UNION
SELECT `roleid`, '' AS institut_id, 0 AS explicit
SELECT `roleid`, '' AS institut_id, 0 AS explicit
FROM `roles_studipperms`
FROM `roles_studipperms`
WHERE `permname` = :perm
WHERE `permname` = :perm
...
@@ -250,21 +243,28 @@ class RolePersistence
...
@@ -250,21 +243,28 @@ class RolePersistence
foreach
(
$statement
as
$row
)
{
foreach
(
$statement
as
$row
)
{
if
(
!
isset
(
$roles
[
$row
[
'roleid'
]]))
{
if
(
!
isset
(
$roles
[
$row
[
'roleid'
]]))
{
$roles
[
$row
[
'roleid'
]]
=
[
$roles
[
$row
[
'roleid'
]]
=
[
'id'
=>
$row
[
'roleid'
],
'institutes'
=>
[],
'institutes'
=>
[],
'explicit'
=>
(
bool
)
$row
[
'explicit'
],
'explicit'
=>
(
bool
)
$row
[
'explicit'
],
];
];
}
}
$roles
[
$row
[
'roleid'
]][
'institutes'
][]
=
$row
[
'institut_id'
];
if
(
$row
[
'institut_id'
])
{
$roles
[
$row
[
'roleid'
]][
'institutes'
][]
=
$row
[
'institut_id'
];
}
}
}
$cache
[
$user_id
]
=
$roles
;
$cache
[
$user_id
]
=
$roles
;
}
}
return
array_filter
(
// Filter implicit roles away if necessary
$roles
=
array_filter
(
$cache
[
$user_id
],
$cache
[
$user_id
],
function
(
$role
)
use
(
$implicit
)
{
function
(
$role
)
use
(
$implicit
)
{
return
$implicit
||
$role
[
'explicit'
];
return
$implicit
||
$role
[
'explicit'
];
}
}
);
);
return
array_column
(
$roles
,
'institutes'
,
'id'
);
}
}
/**
/**
...
@@ -484,7 +484,7 @@ class RolePersistence
...
@@ -484,7 +484,7 @@ class RolePersistence
private
static
function
getUserRolesCache
()
private
static
function
getUserRolesCache
()
{
{
if
(
self
::
$user_roles_cache
===
null
)
{
if
(
self
::
$user_roles_cache
===
null
)
{
self
::
$user_roles_cache
=
new
StudipCachedArray
(
'UserRoles'
);
self
::
$user_roles_cache
=
new
StudipCachedArray
(
self
::
USER_ROLES_CACHE_KEY
);
}
}
return
self
::
$user_roles_cache
;
return
self
::
$user_roles_cache
;
}
}
...
@@ -492,7 +492,7 @@ class RolePersistence
...
@@ -492,7 +492,7 @@ class RolePersistence
private
static
function
getPluginRolesCache
()
private
static
function
getPluginRolesCache
()
{
{
if
(
self
::
$plugin_roles_cache
===
null
)
{
if
(
self
::
$plugin_roles_cache
===
null
)
{
self
::
$plugin_roles_cache
=
new
StudipCachedArray
(
'PluginRoles'
);
self
::
$plugin_roles_cache
=
new
StudipCachedArray
(
self
::
PLUGIN_ROLES_CACHE_KEY
);
}
}
return
self
::
$plugin_roles_cache
;
return
self
::
$plugin_roles_cache
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment