Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchParapheur
Manage
Activity
Members
Plan
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
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
Maarch
MaarchParapheur
Commits
eb420fd4
Verified
Commit
eb420fd4
authored
5 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
FEAT Administrative privileges in token
parent
61d92792
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/group/controllers/PrivilegeController.php
+22
-20
22 additions, 20 deletions
src/app/group/controllers/PrivilegeController.php
src/app/user/controllers/UserController.php
+4
-3
4 additions, 3 deletions
src/app/user/controllers/UserController.php
with
26 additions
and
23 deletions
src/app/group/controllers/PrivilegeController.php
+
22
−
20
View file @
eb420fd4
...
@@ -30,6 +30,7 @@ class PrivilegeController
...
@@ -30,6 +30,7 @@ class PrivilegeController
[
'id'
=>
'manage_documents'
,
'type'
=>
'simple'
]
[
'id'
=>
'manage_documents'
,
'type'
=>
'simple'
]
];
];
//TODO remove after token
public
function
getAdministrativePrivilegesByUser
(
Request
$request
,
Response
$response
)
public
function
getAdministrativePrivilegesByUser
(
Request
$request
,
Response
$response
)
{
{
$groups
=
UserGroupModel
::
get
([
'select'
=>
[
'group_id'
],
'where'
=>
[
'user_id = ?'
],
'data'
=>
[
$GLOBALS
[
'id'
]]]);
$groups
=
UserGroupModel
::
get
([
'select'
=>
[
'group_id'
],
'where'
=>
[
'user_id = ?'
],
'data'
=>
[
$GLOBALS
[
'id'
]]]);
...
@@ -53,25 +54,7 @@ class PrivilegeController
...
@@ -53,25 +54,7 @@ class PrivilegeController
return
$response
->
withJson
([
'privileges'
=>
$administrativePrivileges
]);
return
$response
->
withJson
([
'privileges'
=>
$administrativePrivileges
]);
}
}
public
static
function
hasPrivilege
(
array
$args
)
public
static
function
getAdministrativePrivilegesByUserId
(
array
$args
)
{
ValidatorModel
::
notEmpty
(
$args
,
[
'userId'
,
'privilege'
]);
ValidatorModel
::
intVal
(
$args
,
[
'userId'
]);
ValidatorModel
::
stringType
(
$args
,
[
'privilege'
]);
$groups
=
UserGroupModel
::
get
([
'select'
=>
[
'group_id'
],
'where'
=>
[
'user_id = ?'
],
'data'
=>
[
$args
[
'userId'
]]]);
foreach
(
$groups
as
$group
)
{
$privilege
=
GroupPrivilegeModel
::
getPrivileges
([
'select'
=>
[
1
],
'where'
=>
[
'group_id = ?'
,
'privilege = ?'
],
'data'
=>
[
$group
[
'group_id'
],
$args
[
'privilege'
]]]);
if
(
!
empty
(
$privilege
))
{
return
true
;
}
}
return
false
;
}
public
static
function
hasAdmin
(
array
$args
)
{
{
ValidatorModel
::
notEmpty
(
$args
,
[
'userId'
]);
ValidatorModel
::
notEmpty
(
$args
,
[
'userId'
]);
ValidatorModel
::
intVal
(
$args
,
[
'userId'
]);
ValidatorModel
::
intVal
(
$args
,
[
'userId'
]);
...
@@ -80,6 +63,7 @@ class PrivilegeController
...
@@ -80,6 +63,7 @@ class PrivilegeController
$allGroups
=
array_column
(
$groups
,
'group_id'
);
$allGroups
=
array_column
(
$groups
,
'group_id'
);
$administrativePrivileges
=
[];
if
(
!
empty
(
$allGroups
))
{
if
(
!
empty
(
$allGroups
))
{
$privileges
=
GroupPrivilegeModel
::
getPrivileges
([
'select'
=>
[
'privilege'
],
'where'
=>
[
'group_id in (?)'
],
'data'
=>
[
$allGroups
]]);
$privileges
=
GroupPrivilegeModel
::
getPrivileges
([
'select'
=>
[
'privilege'
],
'where'
=>
[
'group_id in (?)'
],
'data'
=>
[
$allGroups
]]);
$privileges
=
array_column
(
$privileges
,
'privilege'
);
$privileges
=
array_column
(
$privileges
,
'privilege'
);
...
@@ -87,12 +71,30 @@ class PrivilegeController
...
@@ -87,12 +71,30 @@ class PrivilegeController
if
(
!
empty
(
$privileges
))
{
if
(
!
empty
(
$privileges
))
{
foreach
(
PrivilegeController
::
PRIVILEGES
as
$value
)
{
foreach
(
PrivilegeController
::
PRIVILEGES
as
$value
)
{
if
(
$value
[
'type'
]
==
'admin'
&&
in_array
(
$value
[
'id'
],
$privileges
))
{
if
(
$value
[
'type'
]
==
'admin'
&&
in_array
(
$value
[
'id'
],
$privileges
))
{
return
tr
ue
;
$administrativePrivileges
[]
=
$val
ue
;
}
}
}
}
}
}
}
}
return
$administrativePrivileges
;
}
public
static
function
hasPrivilege
(
array
$args
)
{
ValidatorModel
::
notEmpty
(
$args
,
[
'userId'
,
'privilege'
]);
ValidatorModel
::
intVal
(
$args
,
[
'userId'
]);
ValidatorModel
::
stringType
(
$args
,
[
'privilege'
]);
$groups
=
UserGroupModel
::
get
([
'select'
=>
[
'group_id'
],
'where'
=>
[
'user_id = ?'
],
'data'
=>
[
$args
[
'userId'
]]]);
foreach
(
$groups
as
$group
)
{
$privilege
=
GroupPrivilegeModel
::
getPrivileges
([
'select'
=>
[
1
],
'where'
=>
[
'group_id = ?'
,
'privilege = ?'
],
'data'
=>
[
$group
[
'group_id'
],
$args
[
'privilege'
]]]);
if
(
!
empty
(
$privilege
))
{
return
true
;
}
}
return
false
;
return
false
;
}
}
}
}
This diff is collapsed.
Click to expand it.
src/app/user/controllers/UserController.php
+
4
−
3
View file @
eb420fd4
...
@@ -531,9 +531,10 @@ class UserController
...
@@ -531,9 +531,10 @@ class UserController
}
}
if
(
$GLOBALS
[
'id'
]
==
$args
[
'id'
])
{
if
(
$GLOBALS
[
'id'
]
==
$args
[
'id'
])
{
$user
[
'preferences'
]
=
json_decode
(
$user
[
'preferences'
],
true
);
$user
[
'preferences'
]
=
json_decode
(
$user
[
'preferences'
],
true
);
$user
[
'availableLanguages'
]
=
LanguageController
::
getAvailableLanguages
();
$user
[
'availableLanguages'
]
=
LanguageController
::
getAvailableLanguages
();
$user
[
'hasAdmin'
]
=
PrivilegeController
::
hasAdmin
([
'userId'
=>
$args
[
'id'
]]);
$user
[
'administrativePrivileges'
]
=
PrivilegeController
::
getAdministrativePrivilegesByUserId
([
'userId'
=>
$args
[
'id'
]]);
$user
[
'hasAdmin'
]
=
!
empty
(
$user
[
'administrativePrivileges'
]);
}
}
return
$user
;
return
$user
;
...
...
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