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
0013ea51
Commit
0013ea51
authored
Apr 14, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplication between Group and ProjectMember.
parent
a8b462bb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
43 deletions
+75
-43
app/controllers/projects/project_members_controller.rb
app/controllers/projects/project_members_controller.rb
+1
-2
app/models/group.rb
app/models/group.rb
+2
-19
app/models/member.rb
app/models/member.rb
+33
-3
app/models/members/project_member.rb
app/models/members/project_member.rb
+2
-17
spec/models/member_spec.rb
spec/models/member_spec.rb
+37
-2
No files found.
app/controllers/projects/project_members_controller.rb
View file @
0013ea51
...
@@ -52,8 +52,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
...
@@ -52,8 +52,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
redirect_to
namespace_project_project_members_path
(
@project
.
namespace
,
redirect_to
namespace_project_project_members_path
(
@project
.
namespace
,
@project
)
@project
)
end
end
format
.
js
{
render
nothing:
true
}
format
.
js
{
render
nothing:
true
}
end
end
...
...
app/models/group.rb
View file @
0013ea51
...
@@ -47,25 +47,8 @@ class Group < Namespace
...
@@ -47,25 +47,8 @@ class Group < Namespace
end
end
def
add_users
(
user_ids
,
access_level
,
current_user
=
nil
)
def
add_users
(
user_ids
,
access_level
,
current_user
=
nil
)
users
=
user_ids
.
map
do
|
user_id
|
user_ids
.
each
do
|
user_id
|
(
user_id
if
user_id
.
is_a?
(
User
))
||
Member
.
add_user
(
self
.
group_members
,
user_id
,
access_level
,
current_user
)
User
.
find_by
(
id:
user_id
)
||
User
.
find_by
(
email:
user_id
)
||
user_id
end
users
.
compact
.
each
do
|
user
|
if
user
.
is_a?
(
User
)
member
=
self
.
group_members
.
find_or_initialize_by
(
user_id:
user
.
id
)
else
member
=
self
.
group_members
.
build
member
.
invite_email
=
user
end
member
.
created_by
||=
current_user
member
.
access_level
=
access_level
member
.
save
end
end
end
end
...
...
app/models/member.rb
View file @
0013ea51
...
@@ -52,11 +52,41 @@ class Member < ActiveRecord::Base
...
@@ -52,11 +52,41 @@ class Member < ActiveRecord::Base
delegate
:name
,
:username
,
:email
,
to: :user
,
prefix:
true
delegate
:name
,
:username
,
:email
,
to: :user
,
prefix:
true
def
self
.
find_by_invite_token
(
invite_token
)
class
<<
self
def
find_by_invite_token
(
invite_token
)
invite_token
=
Devise
.
token_generator
.
digest
(
self
,
:invite_token
,
invite_token
)
invite_token
=
Devise
.
token_generator
.
digest
(
self
,
:invite_token
,
invite_token
)
find_by
(
invite_token:
invite_token
)
find_by
(
invite_token:
invite_token
)
end
end
# This method is used to find users that have been entered into the "Add members" field.
# These can be the User objects directly, their IDs, their emails, or new emails to be invited.
def
user_for_id
(
user_id
)
return
user_id
if
user_id
.
is_a?
(
User
)
user
=
User
.
find_by
(
id:
user_id
)
user
||=
User
.
find_by
(
email:
user_id
)
user
||=
user_id
user
end
def
add_user
(
members
,
user_id
,
access_level
,
current_user
=
nil
)
user
=
user_for_id
(
user_id
)
# `user` can be either a User object or an email to be invited
if
user
.
is_a?
(
User
)
member
=
members
.
find_or_initialize_by
(
user_id:
user
.
id
)
else
member
=
members
.
build
member
.
invite_email
=
user
end
member
.
created_by
||=
current_user
member
.
access_level
=
access_level
member
.
save
end
end
def
invite?
def
invite?
self
.
invite_token
.
present?
self
.
invite_token
.
present?
end
end
...
...
app/models/members/project_member.rb
View file @
0013ea51
...
@@ -60,29 +60,14 @@ class ProjectMember < Member
...
@@ -60,29 +60,14 @@ class ProjectMember < Member
raise
"Non valid access"
raise
"Non valid access"
end
end
users
=
user_ids
.
map
do
|
user_id
|
users
=
user_ids
.
map
{
|
user_id
|
Member
.
user_for_id
(
user_id
)
}
(
user_id
if
user_id
.
is_a?
(
User
))
||
User
.
find_by
(
id:
user_id
)
||
User
.
find_by
(
email:
user_id
)
||
user_id
end
ProjectMember
.
transaction
do
ProjectMember
.
transaction
do
project_ids
.
each
do
|
project_id
|
project_ids
.
each
do
|
project_id
|
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
users
.
each
do
|
user
|
users
.
each
do
|
user
|
if
user
.
is_a?
(
User
)
Member
.
add_user
(
project
.
project_members
,
user
,
access_level
,
current_user
)
member
=
project
.
project_members
.
find_or_initialize_by
(
user_id:
user
.
id
)
else
member
=
project
.
project_members
.
build
member
.
invite_email
=
user
end
member
.
created_by
||=
current_user
member
.
access_level
=
access_level
member
.
save
end
end
end
end
end
end
...
...
spec/models/member
s
_spec.rb
→
spec/models/member_spec.rb
View file @
0013ea51
...
@@ -58,6 +58,43 @@ describe Member do
...
@@ -58,6 +58,43 @@ describe Member do
it
{
is_expected
.
to
respond_to
(
:user_email
)
}
it
{
is_expected
.
to
respond_to
(
:user_email
)
}
end
end
describe
".add_user"
do
let!
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
context
"when called with a user id"
do
it
"adds the user as a member"
do
Member
.
add_user
(
project
.
project_members
,
user
.
id
,
ProjectMember
::
MASTER
)
expect
(
project
.
users
).
to
include
(
user
)
end
end
context
"when called with a user object"
do
it
"adds the user as a member"
do
Member
.
add_user
(
project
.
project_members
,
user
,
ProjectMember
::
MASTER
)
expect
(
project
.
users
).
to
include
(
user
)
end
end
context
"when called with a known user email"
do
it
"adds the user as a member"
do
Member
.
add_user
(
project
.
project_members
,
user
.
email
,
ProjectMember
::
MASTER
)
expect
(
project
.
users
).
to
include
(
user
)
end
end
context
"when called with an unknown user email"
do
it
"adds a member invite"
do
Member
.
add_user
(
project
.
project_members
,
"user@example.com"
,
ProjectMember
::
MASTER
)
expect
(
project
.
project_members
.
invite
.
pluck
(
:invite_email
)).
to
include
(
"user@example.com"
)
end
end
end
describe
"#accept_invite!"
do
describe
"#accept_invite!"
do
let!
(
:member
)
{
create
(
:project_member
,
invite_email:
"user@example.com"
,
user:
nil
)
}
let!
(
:member
)
{
create
(
:project_member
,
invite_email:
"user@example.com"
,
user:
nil
)
}
...
@@ -89,7 +126,6 @@ describe Member do
...
@@ -89,7 +126,6 @@ describe Member do
end
end
describe
"#decline_invite!"
do
describe
"#decline_invite!"
do
let!
(
:member
)
{
create
(
:project_member
,
invite_email:
"user@example.com"
,
user:
nil
)
}
let!
(
:member
)
{
create
(
:project_member
,
invite_email:
"user@example.com"
,
user:
nil
)
}
it
"destroys the member"
do
it
"destroys the member"
do
...
@@ -106,7 +142,6 @@ describe Member do
...
@@ -106,7 +142,6 @@ describe Member do
end
end
describe
"#generate_invite_token"
do
describe
"#generate_invite_token"
do
let!
(
:member
)
{
create
(
:project_member
,
invite_email:
"user@example.com"
,
user:
nil
)
}
let!
(
:member
)
{
create
(
:project_member
,
invite_email:
"user@example.com"
,
user:
nil
)
}
it
"sets the invite token"
do
it
"sets the invite token"
do
...
...
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