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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
2b2bd402
Commit
2b2bd402
authored
Apr 10, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track who created a group or project member.
parent
1e978649
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
35 additions
and
31 deletions
+35
-31
app/controllers/admin/groups_controller.rb
app/controllers/admin/groups_controller.rb
+1
-1
app/controllers/groups/group_members_controller.rb
app/controllers/groups/group_members_controller.rb
+1
-1
app/controllers/projects/project_members_controller.rb
app/controllers/projects/project_members_controller.rb
+1
-1
app/models/group.rb
app/models/group.rb
+9
-7
app/models/member.rb
app/models/member.rb
+5
-0
app/models/members/project_member.rb
app/models/members/project_member.rb
+2
-1
app/models/project_team.rb
app/models/project_team.rb
+13
-15
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+1
-1
app/services/projects/fork_service.rb
app/services/projects/fork_service.rb
+1
-1
lib/api/group_members.rb
lib/api/group_members.rb
+1
-1
spec/requests/api/repositories_spec.rb
spec/requests/api/repositories_spec.rb
+0
-2
No files found.
app/controllers/admin/groups_controller.rb
View file @
2b2bd402
...
@@ -41,7 +41,7 @@ class Admin::GroupsController < Admin::ApplicationController
...
@@ -41,7 +41,7 @@ class Admin::GroupsController < Admin::ApplicationController
end
end
def
members_update
def
members_update
@group
.
add_users
(
params
[
:user_ids
].
split
(
','
),
params
[
:access_level
])
@group
.
add_users
(
params
[
:user_ids
].
split
(
','
),
params
[
:access_level
]
,
current_user
)
redirect_to
[
:admin
,
@group
],
notice:
'Users were successfully added.'
redirect_to
[
:admin
,
@group
],
notice:
'Users were successfully added.'
end
end
...
...
app/controllers/groups/group_members_controller.rb
View file @
2b2bd402
...
@@ -22,7 +22,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
...
@@ -22,7 +22,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
end
end
def
create
def
create
@group
.
add_users
(
params
[
:user_ids
].
split
(
','
),
params
[
:access_level
])
@group
.
add_users
(
params
[
:user_ids
].
split
(
','
),
params
[
:access_level
]
,
current_user
)
redirect_to
group_group_members_path
(
@group
),
notice:
'Users were successfully added.'
redirect_to
group_group_members_path
(
@group
),
notice:
'Users were successfully added.'
end
end
...
...
app/controllers/projects/project_members_controller.rb
View file @
2b2bd402
...
@@ -69,7 +69,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
...
@@ -69,7 +69,7 @@ class Projects::ProjectMembersController < Projects::ApplicationController
def
apply_import
def
apply_import
giver
=
Project
.
find
(
params
[
:source_project_id
])
giver
=
Project
.
find
(
params
[
:source_project_id
])
status
=
@project
.
team
.
import
(
giver
)
status
=
@project
.
team
.
import
(
giver
,
current_user
)
notice
=
status
?
"Successfully imported"
:
"Import failed"
notice
=
status
?
"Successfully imported"
:
"Import failed"
redirect_to
(
namespace_project_project_members_path
(
project
.
namespace
,
project
),
redirect_to
(
namespace_project_project_members_path
(
project
.
namespace
,
project
),
...
...
app/models/group.rb
View file @
2b2bd402
...
@@ -46,19 +46,21 @@ class Group < Namespace
...
@@ -46,19 +46,21 @@ class Group < Namespace
@owners
||=
group_members
.
owners
.
map
(
&
:user
)
@owners
||=
group_members
.
owners
.
map
(
&
:user
)
end
end
def
add_users
(
user_ids
,
access_level
)
def
add_users
(
user_ids
,
access_level
,
current_user
=
nil
)
user_ids
.
compact
.
each
do
|
user_id
|
user_ids
.
compact
.
each
do
|
user_id
|
user
=
self
.
group_members
.
find_or_initialize_by
(
user_id:
user_id
)
member
=
self
.
group_members
.
find_or_initialize_by
(
user_id:
user_id
)
user
.
update_attributes
(
access_level:
access_level
)
member
.
access_level
=
access_level
member
.
created_by
||=
current_user
member
.
save
end
end
end
end
def
add_user
(
user
,
access_level
)
def
add_user
(
user
,
access_level
,
current_user
=
nil
)
self
.
group_members
.
create
(
user_id:
user
.
id
,
access_level:
access_level
)
add_users
([
user
],
access_level
,
current_user
)
end
end
def
add_owner
(
user
)
def
add_owner
(
user
,
current_user
=
nil
)
self
.
add_user
(
user
,
Gitlab
::
Access
::
OWNER
)
self
.
add_user
(
user
,
Gitlab
::
Access
::
OWNER
,
current_user
)
end
end
def
has_owner?
(
user
)
def
has_owner?
(
user
)
...
...
app/models/member.rb
View file @
2b2bd402
...
@@ -11,6 +11,10 @@
...
@@ -11,6 +11,10 @@
# type :string(255)
# type :string(255)
# created_at :datetime
# created_at :datetime
# updated_at :datetime
# updated_at :datetime
# created_by_id :integer
# invite_email :string
# invite_token :string
# invite_accepted_at :datetime
#
#
class
Member
<
ActiveRecord
::
Base
class
Member
<
ActiveRecord
::
Base
...
@@ -18,6 +22,7 @@ class Member < ActiveRecord::Base
...
@@ -18,6 +22,7 @@ class Member < ActiveRecord::Base
include
Notifiable
include
Notifiable
include
Gitlab
::
Access
include
Gitlab
::
Access
belongs_to
:created_by
,
class_name:
"User"
belongs_to
:user
belongs_to
:user
belongs_to
:source
,
polymorphic:
true
belongs_to
:source
,
polymorphic:
true
...
...
app/models/members/project_member.rb
View file @
2b2bd402
...
@@ -55,7 +55,7 @@ class ProjectMember < Member
...
@@ -55,7 +55,7 @@ class ProjectMember < Member
# :master
# :master
# )
# )
#
#
def
add_users_into_projects
(
project_ids
,
user_ids
,
access
)
def
add_users_into_projects
(
project_ids
,
user_ids
,
access
,
current_user
=
nil
)
access_level
=
if
roles_hash
.
has_key?
(
access
)
access_level
=
if
roles_hash
.
has_key?
(
access
)
roles_hash
[
access
]
roles_hash
[
access
]
elsif
roles_hash
.
values
.
include?
(
access
.
to_i
)
elsif
roles_hash
.
values
.
include?
(
access
.
to_i
)
...
@@ -69,6 +69,7 @@ class ProjectMember < Member
...
@@ -69,6 +69,7 @@ class ProjectMember < Member
user_ids
.
each
do
|
user_id
|
user_ids
.
each
do
|
user_id
|
member
=
ProjectMember
.
new
(
access_level:
access_level
,
user_id:
user_id
)
member
=
ProjectMember
.
new
(
access_level:
access_level
,
user_id:
user_id
)
member
.
source_id
=
project_id
member
.
source_id
=
project_id
member
.
created_by
||=
current_user
member
.
save
member
.
save
end
end
end
end
...
...
app/models/project_team.rb
View file @
2b2bd402
...
@@ -12,12 +12,12 @@ class ProjectTeam
...
@@ -12,12 +12,12 @@ class ProjectTeam
# @team << [@users, :master]
# @team << [@users, :master]
#
#
def
<<
(
args
)
def
<<
(
args
)
users
=
args
.
first
users
,
access
,
current_user
=
*
args
if
users
.
respond_to?
(
:each
)
if
users
.
respond_to?
(
:each
)
add_users
(
users
,
a
rgs
.
second
)
add_users
(
users
,
a
ccess
,
current_user
)
else
else
add_user
(
users
,
a
rgs
.
second
)
add_user
(
users
,
a
ccess
,
current_user
)
end
end
end
end
...
@@ -43,22 +43,19 @@ class ProjectTeam
...
@@ -43,22 +43,19 @@ class ProjectTeam
member
member
end
end
def
add_user
(
user
,
access
)
def
add_users
(
users
,
access
,
current_user
=
nil
)
add_users_ids
([
user
.
id
],
access
)
end
def
add_users
(
users
,
access
)
add_users_ids
(
users
.
map
(
&
:id
),
access
)
end
def
add_users_ids
(
user_ids
,
access
)
ProjectMember
.
add_users_into_projects
(
ProjectMember
.
add_users_into_projects
(
[
project
.
id
],
[
project
.
id
],
user_ids
,
users
,
access
access
,
current_user
)
)
end
end
def
add_user
(
user
,
access
,
current_user
=
nil
)
add_users
([
user
],
access
,
current_user
)
end
# Remove all users from project team
# Remove all users from project team
def
truncate
def
truncate
ProjectMember
.
truncate_team
(
project
)
ProjectMember
.
truncate_team
(
project
)
...
@@ -88,7 +85,7 @@ class ProjectTeam
...
@@ -88,7 +85,7 @@ class ProjectTeam
@masters
||=
fetch_members
(
:masters
)
@masters
||=
fetch_members
(
:masters
)
end
end
def
import
(
source_project
)
def
import
(
source_project
,
current_user
=
nil
)
target_project
=
project
target_project
=
project
source_members
=
source_project
.
project_members
.
to_a
source_members
=
source_project
.
project_members
.
to_a
...
@@ -103,6 +100,7 @@ class ProjectTeam
...
@@ -103,6 +100,7 @@ class ProjectTeam
new_member
=
member
.
dup
new_member
=
member
.
dup
new_member
.
id
=
nil
new_member
.
id
=
nil
new_member
.
source
=
target_project
new_member
.
source
=
target_project
new_member
.
created_by
=
current_user
new_member
new_member
end
end
...
...
app/services/projects/create_service.rb
View file @
2b2bd402
...
@@ -83,7 +83,7 @@ module Projects
...
@@ -83,7 +83,7 @@ module Projects
system_hook_service
.
execute_hooks_for
(
@project
,
:create
)
system_hook_service
.
execute_hooks_for
(
@project
,
:create
)
unless
@project
.
group
unless
@project
.
group
@project
.
team
<<
[
current_user
,
:master
]
@project
.
team
<<
[
current_user
,
:master
,
current_user
]
end
end
@project
.
update_column
(
:last_activity_at
,
@project
.
created_at
)
@project
.
update_column
(
:last_activity_at
,
@project
.
created_at
)
...
...
app/services/projects/fork_service.rb
View file @
2b2bd402
...
@@ -38,7 +38,7 @@ module Projects
...
@@ -38,7 +38,7 @@ module Projects
#First save the DB entries as they can be rolled back if the repo fork fails
#First save the DB entries as they can be rolled back if the repo fork fails
project
.
build_forked_project_link
(
forked_to_project_id:
project
.
id
,
forked_from_project_id:
@from_project
.
id
)
project
.
build_forked_project_link
(
forked_to_project_id:
project
.
id
,
forked_from_project_id:
@from_project
.
id
)
if
project
.
save
if
project
.
save
project
.
team
<<
[
@current_user
,
:master
]
project
.
team
<<
[
@current_user
,
:master
,
@current_user
]
end
end
#Now fork the repo
#Now fork the repo
...
...
lib/api/group_members.rb
View file @
2b2bd402
...
@@ -34,7 +34,7 @@ module API
...
@@ -34,7 +34,7 @@ module API
render_api_error!
(
"Already exists"
,
409
)
render_api_error!
(
"Already exists"
,
409
)
end
end
group
.
add_users
([
params
[
:user_id
]],
params
[
:access_level
])
group
.
add_users
([
params
[
:user_id
]],
params
[
:access_level
]
,
current_user
)
member
=
group
.
group_members
.
find_by
(
user_id:
params
[
:user_id
])
member
=
group
.
group_members
.
find_by
(
user_id:
params
[
:user_id
])
present
member
.
user
,
with:
Entities
::
GroupMember
,
group:
group
present
member
.
user
,
with:
Entities
::
GroupMember
,
group:
group
end
end
...
...
spec/requests/api/repositories_spec.rb
View file @
2b2bd402
...
@@ -11,8 +11,6 @@ describe API::API, api: true do
...
@@ -11,8 +11,6 @@ describe API::API, api: true do
let!
(
:master
)
{
create
(
:project_member
,
user:
user
,
project:
project
,
access_level:
ProjectMember
::
MASTER
)
}
let!
(
:master
)
{
create
(
:project_member
,
user:
user
,
project:
project
,
access_level:
ProjectMember
::
MASTER
)
}
let!
(
:guest
)
{
create
(
:project_member
,
user:
user2
,
project:
project
,
access_level:
ProjectMember
::
GUEST
)
}
let!
(
:guest
)
{
create
(
:project_member
,
user:
user2
,
project:
project
,
access_level:
ProjectMember
::
GUEST
)
}
before
{
project
.
team
<<
[
user
,
:reporter
]
}
describe
"GET /projects/:id/repository/tags"
do
describe
"GET /projects/:id/repository/tags"
do
it
"should return an array of project tags"
do
it
"should return an array of project tags"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
)
...
...
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