Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a02973bb
Commit
a02973bb
authored
Mar 23, 2021
by
Doug Stull
Committed by
Arturo Herrero
Mar 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add daily limit logic to invite service
- bring inline with create_service.rb.
parent
2701da3d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
1 deletion
+123
-1
app/services/members/invite_service.rb
app/services/members/invite_service.rb
+3
-1
ee/app/services/ee/members/invite_service.rb
ee/app/services/ee/members/invite_service.rb
+30
-0
ee/changelogs/unreleased/323078-combine-concepts-in-inviting-member-service-classes.yml
...8-combine-concepts-in-inviting-member-service-classes.yml
+5
-0
ee/spec/services/ee/members/invite_service_spec.rb
ee/spec/services/ee/members/invite_service_spec.rb
+85
-0
No files found.
app/services/members/invite_service.rb
View file @
a02973bb
...
@@ -13,9 +13,9 @@ module Members
...
@@ -13,9 +13,9 @@ module Members
end
end
def
execute
(
source
)
def
execute
(
source
)
@source
=
source
validate_emails!
validate_emails!
@source
=
source
emails
.
each
(
&
method
(
:process_email
))
emails
.
each
(
&
method
(
:process_email
))
result
result
rescue
BlankEmailsError
,
TooManyEmailsError
=>
e
rescue
BlankEmailsError
,
TooManyEmailsError
=>
e
...
@@ -96,3 +96,5 @@ module Members
...
@@ -96,3 +96,5 @@ module Members
end
end
end
end
end
end
Members
::
InviteService
.
prepend_if_ee
(
'EE::Members::InviteService'
)
ee/app/services/ee/members/invite_service.rb
0 → 100644
View file @
a02973bb
# frozen_string_literal: true
module
EE
module
Members
module
InviteService
extend
::
Gitlab
::
Utils
::
Override
private
override
:validate_emails!
def
validate_emails!
super
if
invite_quota_exceeded?
raise
::
Members
::
InviteService
::
TooManyEmailsError
,
s_
(
"AddMember|Invite limit of %{daily_invites} per day exceeded"
)
%
{
daily_invites:
source
.
actual_limits
.
daily_invites
}
end
end
def
invite_quota_exceeded?
return
unless
source
.
actual_limits
.
daily_invites
invite_count
=
::
Member
.
invite
.
created_today
.
in_hierarchy
(
source
).
count
source
.
actual_limits
.
exceeded?
(
:daily_invites
,
invite_count
+
emails
.
count
)
end
end
end
end
ee/changelogs/unreleased/323078-combine-concepts-in-inviting-member-service-classes.yml
0 → 100644
View file @
a02973bb
---
title
:
Add daily quota limit to invitations API endpoint
merge_request
:
56781
author
:
type
:
other
ee/spec/services/ee/members/invite_service_spec.rb
0 → 100644
View file @
a02973bb
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Members
::
InviteService
,
:aggregate_failures
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:root_ancestor
)
{
create
(
:group
)
}
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
group:
root_ancestor
)
}
let_it_be
(
:subgroup
)
{
create
(
:group
,
parent:
root_ancestor
)
}
let_it_be
(
:subgroup_project
)
{
create
(
:project
,
group:
subgroup
)
}
let
(
:params
)
{
{
email:
%w[email@example.org email2@example.org]
,
access_level:
Gitlab
::
Access
::
GUEST
}
}
subject
(
:result
)
{
described_class
.
new
(
user
,
params
).
execute
(
project
)
}
before_all
do
project
.
add_maintainer
(
user
)
create
(
:project_member
,
:invited
,
project:
subgroup_project
,
created_at:
2
.
days
.
ago
)
create
(
:project_member
,
:invited
,
project:
subgroup_project
)
create
(
:group_member
,
:invited
,
group:
subgroup
,
created_at:
2
.
days
.
ago
)
create
(
:group_member
,
:invited
,
group:
subgroup
)
end
describe
'#execute'
do
context
'with group plan'
do
let
(
:plan_limits
)
{
create
(
:plan_limits
,
daily_invites:
daily_invites
)
}
let
(
:plan
)
{
create
(
:plan
,
limits:
plan_limits
)
}
let!
(
:subscription
)
do
create
(
:gitlab_subscription
,
namespace:
root_ancestor
,
hosted_plan:
plan
)
end
shared_examples
'quota limit exceeded'
do
|
limit
|
it
'limits the number of daily invites allowed'
do
expect
{
result
}.
not_to
change
(
ProjectMember
,
:count
)
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:message
]).
to
eq
(
"Invite limit of
#{
limit
}
per day exceeded"
)
end
end
context
'already exceeded invite quota limit'
do
let
(
:daily_invites
)
{
2
}
it_behaves_like
'quota limit exceeded'
,
2
end
context
'will exceed invite quota limit'
do
let
(
:daily_invites
)
{
3
}
it_behaves_like
'quota limit exceeded'
,
3
end
context
'within invite quota limit'
do
let
(
:daily_invites
)
{
5
}
it
'successfully creates members'
do
expect
{
result
}.
to
change
(
ProjectMember
,
:count
).
by
(
2
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
end
end
context
'infinite invite quota limit'
do
let
(
:daily_invites
)
{
0
}
it
'successfully creates members'
do
expect
{
result
}.
to
change
(
ProjectMember
,
:count
).
by
(
2
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
end
end
end
context
'without a plan'
do
let
(
:plan
)
{
nil
}
it
'successfully creates members'
do
expect
{
result
}.
to
change
(
ProjectMember
,
:count
).
by
(
2
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment