Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
violinist_teams
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
violinist_teams
Commits
0c81adc1
Commit
0c81adc1
authored
10 months ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3440494
by eiriksm: Ensure the user gets their team when they ended up having to log in
parent
0e68d2ac
No related branches found
Branches containing commit
No related tags found
1 merge request
!46
Add a subscriber to fix that
Pipeline
#144971
passed with warnings
10 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/EventSubscriber/ResponseInviteSubscriber.php
+79
-0
79 additions, 0 deletions
src/EventSubscriber/ResponseInviteSubscriber.php
violinist_teams.services.yml
+9
-0
9 additions, 0 deletions
violinist_teams.services.yml
with
88 additions
and
0 deletions
src/EventSubscriber/ResponseInviteSubscriber.php
0 → 100644
+
79
−
0
View file @
0c81adc1
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\violinist_teams\EventSubscriber
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Session\AccountProxyInterface
;
use
Drupal\user\UserInterface
;
use
Drupal\violinist_teams
\Controller\InviteController
;
use
Drupal\violinist_teams
\TeamNode
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
use
Symfony\Component\HttpFoundation\Session\SessionInterface
;
use
Symfony\Component\HttpKernel\Event\ResponseEvent
;
use
Symfony\Component\HttpKernel\KernelEvents
;
/**
* A response subscriber to check if we have outstanding invites.
*/
final
class
ResponseInviteSubscriber
implements
EventSubscriberInterface
{
/**
* Constructs a ResponseInviteSubscriber object.
*/
public
function
__construct
(
private
readonly
SessionInterface
$session
,
private
readonly
EntityTypeManagerInterface
$entityTypeManager
,
private
AccountProxyInterface
$currentUser
,
)
{}
/**
* Kernel response event handler.
*/
public
function
onKernelResponse
(
ResponseEvent
$event
):
void
{
if
(
!
$this
->
currentUser
->
id
())
{
return
;
}
$request
=
$event
->
getRequest
();
$data
=
$request
->
getSession
()
->
get
(
InviteController
::
INVITE_DATA
);
if
(
!
$data
)
{
return
;
}
// No matter what the result is here, we want to remove the session data at
// this point.
$request
->
getSession
()
->
remove
(
InviteController
::
INVITE_DATA
);
if
(
empty
(
$data
[
'team_id'
]))
{
return
;
}
if
(
empty
(
$data
[
'membership_type'
]))
{
return
;
}
$team
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
load
(
$data
[
'team_id'
]);
if
(
!
$team
instanceof
TeamNode
)
{
return
;
}
$actual_user_object
=
$this
->
entityTypeManager
->
getStorage
(
'user'
)
->
load
(
$this
->
currentUser
->
id
());
if
(
!
$actual_user_object
instanceof
UserInterface
)
{
return
;
}
$membership_type
=
$data
[
'membership_type'
];
// Add them to the team. Based on what role we have in the parameter.
if
(
$membership_type
===
'admin'
)
{
$team
->
appendAdmin
(
$actual_user_object
)
->
save
();
}
else
{
$team
->
appendMember
(
$actual_user_object
)
->
save
();
}
}
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
():
array
{
return
[
KernelEvents
::
RESPONSE
=>
[
'onKernelResponse'
],
];
}
}
This diff is collapsed.
Click to expand it.
violinist_teams.services.yml
+
9
−
0
View file @
0c81adc1
...
...
@@ -11,3 +11,12 @@ services:
autowire
:
true
tags
:
-
{
name
:
access_check
,
applies_to
:
_violinist_teams_access
}
violinist_teams.event_subscriber
:
class
:
Drupal\violinist_teams\EventSubscriber\ResponseInviteSubscriber
arguments
:
-
'
@session'
-
'
@entity_type.manager'
-
'
@current_user'
tags
:
-
{
name
:
event_subscriber
}
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