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
020ba0b6
Commit
020ba0b6
authored
1 year ago
by
Eirik Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3419751
by eiriksm: Add support for team limit override option
parent
47969f52
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!29
Test all things related to team limits
Pipeline
#89658
passed
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/TeamNode.php
+46
-1
46 additions, 1 deletion
src/TeamNode.php
tests/src/Kernel/KernelTestBase.php
+48
-0
48 additions, 0 deletions
tests/src/Kernel/KernelTestBase.php
tests/src/Kernel/TeamNodeTest.php
+31
-0
31 additions, 0 deletions
tests/src/Kernel/TeamNodeTest.php
with
125 additions
and
1 deletion
src/TeamNode.php
+
46
−
1
View file @
020ba0b6
...
...
@@ -15,6 +15,7 @@ class TeamNode extends Node {
const
ADMIN_FIELD
=
'field_team_admins'
;
const
PLAN_FIELD
=
'field_plan'
;
const
PROJECT_LIMIT_FIELD
=
'field_project_limit'
;
const
PROJECT_LIMIT_OVERRIDE_FIELD
=
'field_team_allowed_override'
;
const
SLACK_NOTIFICATION_ENABLED_FIELD
=
'field_slack_notifications'
;
const
BILLING_ENABLED_FIELD
=
'field_send_receipts'
;
const
BILLING_EMAIL_FIELD
=
'field_billing_email'
;
...
...
@@ -119,11 +120,45 @@ class TeamNode extends Node {
* Get the max private repos a team can have, based on the field value.
*/
public
function
getMaxPrivateRepos
()
:
int
{
$return
=
$this
->
getMaxPrivateReposWithoutOverride
();
if
(
$this
->
hasProjectOverrideLimit
())
{
$return
=
$this
->
getProjectOverrideLimit
();
}
return
$return
;
}
/**
* Get the max private repos a team can have, based on the field value.
*
* This will discard the override field.
*/
public
function
getMaxPrivateReposWithoutOverride
()
:
int
{
$return
=
0
;
if
(
!
$this
->
hasField
(
self
::
PROJECT_LIMIT_FIELD
)
||
$this
->
get
(
self
::
PROJECT_LIMIT_FIELD
)
->
isEmpty
())
{
return
$return
;
}
return
(
int
)
$this
->
get
(
self
::
PROJECT_LIMIT_FIELD
)
->
first
()
->
getString
();
$return
=
(
int
)
$this
->
get
(
self
::
PROJECT_LIMIT_FIELD
)
->
first
()
->
getString
();
return
$return
;
}
/**
* Check if the team has a project override limit.
*/
public
function
hasProjectOverrideLimit
()
:
bool
{
if
(
!
$this
->
hasField
(
self
::
PROJECT_LIMIT_OVERRIDE_FIELD
)
||
$this
->
get
(
self
::
PROJECT_LIMIT_OVERRIDE_FIELD
)
->
isEmpty
())
{
return
FALSE
;
}
return
(
bool
)
$this
->
get
(
self
::
PROJECT_LIMIT_OVERRIDE_FIELD
)
->
first
()
->
getString
();
}
/**
* Get the project override limit.
*/
public
function
getProjectOverrideLimit
()
:
int
{
if
(
!
$this
->
hasProjectOverrideLimit
())
{
return
0
;
}
return
(
int
)
$this
->
get
(
self
::
PROJECT_LIMIT_OVERRIDE_FIELD
)
->
first
()
->
getString
();
}
/**
...
...
@@ -136,6 +171,16 @@ class TeamNode extends Node {
$this
->
set
(
self
::
PROJECT_LIMIT_FIELD
,
$number
);
}
/**
* Setter for max private repos.
*/
public
function
setMaxPrivateReposOverride
(
$number
)
{
if
(
!
$this
->
hasField
(
self
::
PROJECT_LIMIT_OVERRIDE_FIELD
))
{
return
;
}
$this
->
set
(
self
::
PROJECT_LIMIT_OVERRIDE_FIELD
,
$number
);
}
/**
* Setter for the plan.
*/
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/KernelTestBase.php
+
48
−
0
View file @
020ba0b6
...
...
@@ -178,6 +178,54 @@ abstract class KernelTestBase extends CoreKernelTestBase {
]);
$field
->
save
();
// Project limits.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_project_limit'
,
'entity_type'
=>
'node'
,
'type'
=>
'integer'
,
'cardinality'
=>
1
,
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
$this
->
nodeType
->
id
(),
'field_type'
=>
'integer'
,
'required'
=>
FALSE
,
]);
$field
->
save
();
// Projects override.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_team_allowed_override'
,
'entity_type'
=>
'node'
,
'type'
=>
'integer'
,
'cardinality'
=>
1
,
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
$this
->
nodeType
->
id
(),
'field_type'
=>
'integer'
,
'required'
=>
FALSE
,
]);
$field
->
save
();
// Plan field.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_plan'
,
'entity_type'
=>
'node'
,
'type'
=>
'string'
,
'cardinality'
=>
1
,
]);
$fieldStorage
->
save
();
$field
=
FieldConfig
::
create
([
'field_storage'
=>
$fieldStorage
,
'bundle'
=>
$this
->
nodeType
->
id
(),
'field_type'
=>
'string'
,
'required'
=>
FALSE
,
]);
$field
->
save
();
// Billing email.
$fieldStorage
=
FieldStorageConfig
::
create
([
'field_name'
=>
'field_billing_email'
,
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/TeamNodeTest.php
+
31
−
0
View file @
020ba0b6
...
...
@@ -4,6 +4,7 @@ namespace Drupal\Tests\violinist_teams\Kernel;
use
Drupal\node\Entity\Node
;
use
Drupal\user\Entity\User
;
use
Drupal\violinist_teams
\PlanInterface
;
use
Drupal\violinist_teams
\TeamNode
;
/**
...
...
@@ -134,6 +135,36 @@ class TeamNodeTest extends KernelTestBase {
self
::
assertEquals
(
'This is another test'
,
$node
->
getPullRequestInstructions
());
}
/**
* Test all the things with limits.
*/
public
function
testTeamLimits
()
{
/** @var \Drupal\violinist_teams\TeamNode $node */
$node
=
Node
::
create
([
'type'
=>
$this
->
nodeType
->
id
(),
]);
// Default is to have one. When using the plan, that is.
self
::
assertEquals
(
1
,
$node
->
getPlan
()
->
getMaxPrivateRepos
());
// The actual limit will be 0 now though.
self
::
assertEquals
(
0
,
$node
->
getMaxPrivateRepos
());
self
::
assertEquals
(
0
,
$node
->
getMaxPrivateReposWithoutOverride
());
// Let's set a value for it.
$node
->
setMaxPrivateRepos
(
2
);
self
::
assertEquals
(
2
,
$node
->
getMaxPrivateRepos
());
self
::
assertEquals
(
2
,
$node
->
getMaxPrivateReposWithoutOverride
());
// Still just the one on the plan, since they have not got a plan yet.
self
::
assertEquals
(
1
,
$node
->
getPlan
()
->
getMaxPrivateRepos
());
// Now let's set override.
$node
->
set
(
'field_team_allowed_override'
,
3
);
self
::
assertEquals
(
3
,
$node
->
getMaxPrivateRepos
());
self
::
assertEquals
(
2
,
$node
->
getMaxPrivateReposWithoutOverride
());
// Still just 1 on the plan.
self
::
assertEquals
(
1
,
$node
->
getPlan
()
->
getMaxPrivateRepos
());
// Now let's alter the plan, and make sure the override is used there.
$node
->
setPlan
(
PlanInterface
::
AGENCY_PLAN
);
self
::
assertEquals
(
3
,
$node
->
getPlan
()
->
getMaxPrivateRepos
());
}
/**
* Dataprovider for environment variables.
*/
...
...
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