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
dbb146fc
Commit
dbb146fc
authored
1 year ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3420060
by eiriksm: ::getTeamsByUser should give me teams they are admins on
parent
ebbbfaef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!31
Make sure teams are returned if user is only admin
Pipeline
#90474
passed
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/TeamManager.php
+8
-4
8 additions, 4 deletions
src/TeamManager.php
tests/src/Kernel/TeamManagerTest.php
+24
-0
24 additions, 0 deletions
tests/src/Kernel/TeamManagerTest.php
with
32 additions
and
4 deletions
src/TeamManager.php
+
8
−
4
View file @
dbb146fc
...
...
@@ -68,12 +68,16 @@ class TeamManager {
*/
public
function
getTeamsByUser
(
UserInterface
$user
)
:
array
{
$node_storage
=
$this
->
entityTypeManager
->
getStorage
(
'node'
);
$nids
=
$node_storage
$nids
_q
=
$node_storage
->
getQuery
()
->
accessCheck
(
FALSE
)
->
condition
(
'type'
,
TeamNode
::
NODE_TYPE
)
->
condition
(
TeamNode
::
MEMBERS_FIELD
,
$user
->
id
())
->
execute
();
->
condition
(
'type'
,
TeamNode
::
NODE_TYPE
);
$or
=
$nids_q
->
orConditionGroup
()
->
condition
(
'field_team_members'
,
$user
->
id
())
->
condition
(
'field_team_admins'
,
$user
->
id
());
$nids_q
->
condition
(
$or
);
$nids
=
$nids_q
->
execute
();
return
$node_storage
->
loadMultiple
(
$nids
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/TeamManagerTest.php
+
24
−
0
View file @
dbb146fc
...
...
@@ -52,6 +52,30 @@ class TeamManagerTest extends KernelTestBase {
self
::
assertEquals
(
$node
->
id
(),
$team_node_result
->
id
());
}
/**
* Test that we can get teams from user.
*/
public
function
testGetTeamsFromUserOnlyAdmin
()
{
/** @var \Drupal\violinist_teams\TeamNode $node */
$node
=
Node
::
create
([
'type'
=>
$this
->
nodeType
->
id
(),
'title'
=>
'test'
,
]);
$node
->
save
();
$user
=
User
::
create
([
'name'
=>
'test'
,
'mail'
=>
'test@example.com'
,
]);
$user
->
save
();
$node
->
setAdmins
([
$user
]);
$node
->
save
();
$teams
=
$this
->
teamManager
->
getTeamsByUser
(
$user
);
self
::
assertCount
(
1
,
$teams
);
/** @var \Drupal\violinist_teams\TeamNode $team_node_result */
$team_node_result
=
reset
(
$teams
);
self
::
assertEquals
(
$node
->
id
(),
$team_node_result
->
id
());
}
/**
* Test what happens when we delete a 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