Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
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
WCMS
uw_cfg_common
Commits
dfb3ddd2
Commit
dfb3ddd2
authored
3 years ago
by
Liam Morland
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4907: Implement access control for Webforms
parent
890aae82
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!161
ISTWCMS-4907: Implement access control for Webforms
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_cfg_common.module
+50
-0
50 additions, 0 deletions
uw_cfg_common.module
with
50 additions
and
0 deletions
uw_cfg_common.module
+
50
−
0
View file @
dfb3ddd2
...
...
@@ -750,6 +750,56 @@ function uw_cfg_common_block_content_create_access(AccountInterface $account, ar
return
AccessResult
::
neutral
();
}
/**
* Implements hook_ENTITY_TYPE_access() for webform entities.
*/
function
uw_cfg_common_webform_access
(
WebformInterface
$webform
,
string
$operation
,
AccountInterface
$account
):
AccessResult
{
// Always allow access for Form editor so they can see the forms they create.
if
(
$account
->
hasPermission
(
'create webform'
))
{
return
AccessResult
::
neutral
();
}
// Allow access to submissions for Form results access.
if
(
$account
->
hasPermission
(
'view any webform submission'
)
&&
$operation
===
'submission_view_any'
)
{
return
AccessResult
::
neutral
();
}
switch
(
$webform
->
getThirdPartySetting
(
'uw_cfg_common'
,
'access_control_method'
))
{
case
'anon'
:
if
(
!
$account
->
isAnonymous
())
{
return
AccessResult
::
forbidden
();
}
break
;
case
'auth'
:
if
(
!
$account
->
isAuthenticated
())
{
return
AccessResult
::
forbidden
();
}
break
;
case
'group'
:
// Must be authenticated for group auth.
if
(
!
$account
->
isAuthenticated
())
{
return
AccessResult
::
forbidden
();
}
// Access control by Active Directory group.
$user_ad_groups
=
uw_cfg_common_get_user_ad_groups
()
?:
[];
// Required group. If at least one is provided, the user must be in it.
$ad_require_groups
=
$webform
->
getThirdPartySetting
(
'uw_cfg_common'
,
'ad_require_groups'
);
if
(
$ad_require_groups
&&
!
array_intersect
(
$ad_require_groups
,
$user_ad_groups
))
{
return
AccessResult
::
forbidden
();
}
// Deny group. If at least one is provided, the user must not be in it.
$ad_deny_groups
=
$webform
->
getThirdPartySetting
(
'uw_cfg_common'
,
'ad_deny_groups'
);
if
(
$ad_deny_groups
&&
array_intersect
(
$ad_deny_groups
,
$user_ad_groups
))
{
return
AccessResult
::
forbidden
();
}
break
;
}
return
AccessResult
::
neutral
();
}
/**
* Implements hook_views_plugins_field_alter().
*/
...
...
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