Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
ginvite
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ginvite
Commits
73596daa
Commit
73596daa
authored
1 year ago
by
Philip Curley
Committed by
Nikolay Lobachev
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3393973
by ikphilip, LOBsTerr: User Accept/Decline invitation access denied
parent
6f1430b8
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
ginvite.routing.yml
+6
-6
6 additions, 6 deletions
ginvite.routing.yml
src/Controller/InvitationOperations.php
+40
-10
40 additions, 10 deletions
src/Controller/InvitationOperations.php
with
46 additions
and
16 deletions
ginvite.routing.yml
+
6
−
6
View file @
73596daa
ginvite.invitation.accept
:
path
:
'
/ginvite/{group_
relationship
}/accept'
path
:
'
/ginvite/{group_
content
}/accept'
defaults
:
_controller
:
'
\Drupal\ginvite\Controller\InvitationOperations::accept'
_title
:
'
Accept
invitation
and
join
group'
requirements
:
_
group_installed_content
:
'
group_invitation
'
_
custom_access
:
'
\Drupal\ginvite\Controller\InvitationOperations::checkAccess
'
options
:
parameters
:
group_
relationship
:
group_
content
:
type
:
entity:group_content
ginvite.invitation.decline
:
path
:
'
/ginvite/{group_
relationship
}/decline'
path
:
'
/ginvite/{group_
content
}/decline'
defaults
:
_controller
:
'
\Drupal\ginvite\Controller\InvitationOperations::decline'
_title
:
'
Decline
invitation'
requirements
:
_
group_installed_content
:
'
group_invitation
'
_
custom_access
:
'
\Drupal\ginvite\Controller\InvitationOperations::checkAccess
'
options
:
parameters
:
group_
relationship
:
group_
content
:
type
:
entity:group_content
ginvite.invitation.bulk
:
...
...
This diff is collapsed.
Click to expand it.
src/Controller/InvitationOperations.php
+
40
−
10
View file @
73596daa
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\ginvite\Controller
;
use
Drupal\Core\Access\AccessResult
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Entity\EntityFormBuilderInterface
;
use
Drupal\Core\Messenger\MessengerInterface
;
...
...
@@ -73,14 +74,14 @@ class InvitationOperations extends ControllerBase {
*
* @param \Symfony\Component\HttpFoundation\Request $request
* HTTP request.
* @param \Drupal\group\Entity\GroupRelationshipInterface $group_
relationship
* @param \Drupal\group\Entity\GroupRelationshipInterface $group_
content
* Invitation entity.
*
* @return array
* The processed form for the given entity and operation.
*/
public
function
accept
(
Request
$request
,
GroupRelationshipInterface
$group_
relationship
)
{
$group
=
$group_
relationship
->
getGroup
();
public
function
accept
(
Request
$request
,
GroupRelationshipInterface
$group_
content
)
{
$group
=
$group_
content
->
getGroup
();
$group_id
=
$group
->
id
();
$group_type
=
$group
->
getGroupType
();
...
...
@@ -94,11 +95,11 @@ class InvitationOperations extends ControllerBase {
// Pre-populate a group membership with the current user.
$group_membership
=
GroupRelationship
::
create
([
'type'
=>
$relation_type_id
,
'entity_id'
=>
$group_
relationship
->
getEntityId
(),
'entity_id'
=>
$group_
content
->
getEntityId
(),
'content_plugin'
=>
'group_membership'
,
'gid'
=>
$group_id
,
'uid'
=>
$group_
relationship
->
getOwnerId
(),
'group_roles'
=>
$group_
relationship
->
get
(
'group_roles'
)
->
getValue
(),
'uid'
=>
$group_
content
->
getOwnerId
(),
'group_roles'
=>
$group_
content
->
get
(
'group_roles'
)
->
getValue
(),
]);
if
(
!
empty
(
$invitation_plugin_configuration
[
'invitation_bypass_form'
])
&&
$invitation_plugin_configuration
[
'invitation_bypass_form'
]
===
TRUE
)
{
...
...
@@ -135,7 +136,7 @@ class InvitationOperations extends ControllerBase {
*
* @param \Symfony\Component\HttpFoundation\Request $request
* HTTP request.
* @param \Drupal\group\Entity\GroupRelationshipInterface $group_
relationship
* @param \Drupal\group\Entity\GroupRelationshipInterface $group_
content
* Invitation entity.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
...
...
@@ -143,9 +144,9 @@ class InvitationOperations extends ControllerBase {
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
decline
(
Request
$request
,
GroupRelationshipInterface
$group_
relationship
)
{
$group_
relationship
->
set
(
'invitation_status'
,
GroupInvitation
::
INVITATION_REJECTED
)
->
save
();
$group_bundle
=
$group_
relationship
->
getGroup
()
->
getGroupType
()
->
label
();
public
function
decline
(
Request
$request
,
GroupRelationshipInterface
$group_
content
)
{
$group_
content
->
set
(
'invitation_status'
,
GroupInvitation
::
INVITATION_REJECTED
)
->
save
();
$group_bundle
=
$group_
content
->
getGroup
()
->
getGroupType
()
->
label
();
$this
->
messenger
->
addMessage
(
$this
->
t
(
'You have declined the @group_bundle invitation.'
,
[
'@group_bundle'
=>
$group_bundle
]));
if
(
$request
->
query
->
has
(
'destination'
))
{
...
...
@@ -181,4 +182,33 @@ class InvitationOperations extends ControllerBase {
return
$title
;
}
/**
* Checks if this current has access to update invitation.
*
* @param \Drupal\group\Entity\GroupRelationshipInterface $group_content
* Invitation entity.
*
* @return \Drupal\Core\Access\AccessResult
* Access check result.
*/
public
function
checkAccess
(
GroupRelationshipInterface
$group_content
)
{
$invited_user_id
=
$group_content
->
getEntityId
();
$group
=
$group_content
->
getGroup
();
// Plugin is not installed.
if
(
!
$group
->
getGroupType
()
->
hasPlugin
(
'group_invitation'
))
{
return
AccessResult
::
forbidden
();
}
$membership
=
$this
->
membershipLoader
->
load
(
$group
,
$this
->
currentUser
());
$current_state
=
$group_content
->
get
(
'invitation_status'
)
->
value
;
// Only allow user accept/decline own invitations.
if
(
$invited_user_id
==
$this
->
currentUser
()
->
id
()
&&
!
$membership
&&
(
int
)
$current_state
===
GroupInvitation
::
INVITATION_PENDING
)
{
return
AccessResult
::
allowed
();
}
return
AccessResult
::
forbidden
();
}
}
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