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
99f99575
Commit
99f99575
authored
Mar 13, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use `group_member` instead of `users_group` or `membership`.
parent
60df262c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
59 additions
and
59 deletions
+59
-59
app/controllers/groups/group_members_controller.rb
app/controllers/groups/group_members_controller.rb
+3
-3
app/controllers/profiles/notifications_controller.rb
app/controllers/profiles/notifications_controller.rb
+3
-3
app/mailers/emails/groups.rb
app/mailers/emails/groups.rb
+4
-4
app/models/ability.rb
app/models/ability.rb
+5
-5
app/services/notification_service.rb
app/services/notification_service.rb
+5
-5
app/views/admin/users/show.html.haml
app/views/admin/users/show.html.haml
+12
-12
app/views/dashboard/groups/index.html.haml
app/views/dashboard/groups/index.html.haml
+6
-6
app/views/groups/group_members/_group_member.html.haml
app/views/groups/group_members/_group_member.html.haml
+2
-2
app/views/notify/group_access_granted_email.html.haml
app/views/notify/group_access_granted_email.html.haml
+1
-1
app/views/notify/group_access_granted_email.text.erb
app/views/notify/group_access_granted_email.text.erb
+1
-1
app/views/profiles/notifications/show.html.haml
app/views/profiles/notifications/show.html.haml
+3
-3
lib/api/group_members.rb
lib/api/group_members.rb
+5
-5
spec/models/members/group_member_spec.rb
spec/models/members/group_member_spec.rb
+6
-6
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+3
-3
No files found.
app/controllers/groups/group_members_controller.rb
View file @
99f99575
...
@@ -18,10 +18,10 @@ class Groups::GroupMembersController < Groups::ApplicationController
...
@@ -18,10 +18,10 @@ class Groups::GroupMembersController < Groups::ApplicationController
end
end
def
destroy
def
destroy
@
users_group
=
@group
.
group_members
.
find
(
params
[
:id
])
@
group_member
=
@group
.
group_members
.
find
(
params
[
:id
])
if
can?
(
current_user
,
:destroy
,
@users_group
)
# May fail if last owner.
if
can?
(
current_user
,
:destroy
_group_member
,
@group_member
)
# May fail if last owner.
@
users_group
.
destroy
@
group_member
.
destroy
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
{
redirect_to
members_group_path
(
@group
),
notice:
'User was successfully removed from group.'
}
format
.
html
{
redirect_to
members_group_path
(
@group
),
notice:
'User was successfully removed from group.'
}
format
.
js
{
render
nothing:
true
}
format
.
js
{
render
nothing:
true
}
...
...
app/controllers/profiles/notifications_controller.rb
View file @
99f99575
...
@@ -14,9 +14,9 @@ class Profiles::NotificationsController < ApplicationController
...
@@ -14,9 +14,9 @@ class Profiles::NotificationsController < ApplicationController
@saved
=
if
type
==
'global'
@saved
=
if
type
==
'global'
current_user
.
update_attributes
(
user_params
)
current_user
.
update_attributes
(
user_params
)
elsif
type
==
'group'
elsif
type
==
'group'
users_group
=
current_user
.
group_members
.
find
(
params
[
:notification_id
])
group_member
=
current_user
.
group_members
.
find
(
params
[
:notification_id
])
users_group
.
notification_level
=
params
[
:notification_level
]
group_member
.
notification_level
=
params
[
:notification_level
]
users_group
.
save
group_member
.
save
else
else
project_member
=
current_user
.
project_members
.
find
(
params
[
:notification_id
])
project_member
=
current_user
.
project_members
.
find
(
params
[
:notification_id
])
project_member
.
notification_level
=
params
[
:notification_level
]
project_member
.
notification_level
=
params
[
:notification_level
]
...
...
app/mailers/emails/groups.rb
View file @
99f99575
module
Emails
module
Emails
module
Groups
module
Groups
def
group_access_granted_email
(
user_group
_id
)
def
group_access_granted_email
(
group_member
_id
)
@
membership
=
GroupMember
.
find
(
user_group
_id
)
@
group_member
=
GroupMember
.
find
(
group_member
_id
)
@group
=
@
membership
.
group
@group
=
@
group_member
.
group
@target_url
=
group_url
(
@group
)
@target_url
=
group_url
(
@group
)
mail
(
to:
@
membership
.
user
.
email
,
mail
(
to:
@
group_member
.
user
.
email
,
subject:
subject
(
"Access to group was granted"
))
subject:
subject
(
"Access to group was granted"
))
end
end
end
end
...
...
app/models/ability.rb
View file @
99f99575
...
@@ -14,7 +14,7 @@ class Ability
...
@@ -14,7 +14,7 @@ class Ability
when
"MergeRequest"
then
merge_request_abilities
(
user
,
subject
)
when
"MergeRequest"
then
merge_request_abilities
(
user
,
subject
)
when
"Group"
then
group_abilities
(
user
,
subject
)
when
"Group"
then
group_abilities
(
user
,
subject
)
when
"Namespace"
then
namespace_abilities
(
user
,
subject
)
when
"Namespace"
then
namespace_abilities
(
user
,
subject
)
when
"GroupMember"
then
users_group
_abilities
(
user
,
subject
)
when
"GroupMember"
then
group_member
_abilities
(
user
,
subject
)
else
[]
else
[]
end
.
concat
(
global_abilities
(
user
))
end
.
concat
(
global_abilities
(
user
))
end
end
...
@@ -248,17 +248,17 @@ class Ability
...
@@ -248,17 +248,17 @@ class Ability
end
end
end
end
def
users_group
_abilities
(
user
,
subject
)
def
group_member
_abilities
(
user
,
subject
)
rules
=
[]
rules
=
[]
target_user
=
subject
.
user
target_user
=
subject
.
user
group
=
subject
.
group
group
=
subject
.
group
can_manage
=
group_abilities
(
user
,
group
).
include?
(
:manage_group
)
can_manage
=
group_abilities
(
user
,
group
).
include?
(
:manage_group
)
if
can_manage
&&
(
user
!=
target_user
)
if
can_manage
&&
(
user
!=
target_user
)
rules
<<
:modify
rules
<<
:modify
_group_member
rules
<<
:destroy
rules
<<
:destroy
_group_member
end
end
if
!
group
.
last_owner?
(
user
)
&&
(
can_manage
||
(
user
==
target_user
))
if
!
group
.
last_owner?
(
user
)
&&
(
can_manage
||
(
user
==
target_user
))
rules
<<
:destroy
rules
<<
:destroy
_group_member
end
end
rules
rules
end
end
...
...
app/services/notification_service.rb
View file @
99f99575
...
@@ -194,11 +194,11 @@ class NotificationService
...
@@ -194,11 +194,11 @@ class NotificationService
project_members
=
project_member_notification
(
project
)
project_members
=
project_member_notification
(
project
)
users_with_project_level_global
=
project_member_notification
(
project
,
Notification
::
N_GLOBAL
)
users_with_project_level_global
=
project_member_notification
(
project
,
Notification
::
N_GLOBAL
)
users_with_group_level_global
=
users_group
_notification
(
project
,
Notification
::
N_GLOBAL
)
users_with_group_level_global
=
group_member
_notification
(
project
,
Notification
::
N_GLOBAL
)
users
=
users_with_global_level_watch
([
users_with_project_level_global
,
users_with_group_level_global
].
flatten
.
uniq
)
users
=
users_with_global_level_watch
([
users_with_project_level_global
,
users_with_group_level_global
].
flatten
.
uniq
)
users_with_project_setting
=
select_project_member_setting
(
project
,
users_with_project_level_global
,
users
)
users_with_project_setting
=
select_project_member_setting
(
project
,
users_with_project_level_global
,
users
)
users_with_group_setting
=
select_
users_group
_setting
(
project
,
project_members
,
users_with_group_level_global
,
users
)
users_with_group_setting
=
select_
group_member
_setting
(
project
,
project_members
,
users_with_group_level_global
,
users
)
User
.
where
(
id:
users_with_project_setting
.
concat
(
users_with_group_setting
).
uniq
).
to_a
User
.
where
(
id:
users_with_project_setting
.
concat
(
users_with_group_setting
).
uniq
).
to_a
end
end
...
@@ -213,7 +213,7 @@ class NotificationService
...
@@ -213,7 +213,7 @@ class NotificationService
end
end
end
end
def
users_group
_notification
(
project
,
notification_level
)
def
group_member
_notification
(
project
,
notification_level
)
if
project
.
group
if
project
.
group
project
.
group
.
group_members
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
project
.
group
.
group_members
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
else
else
...
@@ -243,8 +243,8 @@ class NotificationService
...
@@ -243,8 +243,8 @@ class NotificationService
end
end
# Build a list of users based on group notification settings
# Build a list of users based on group notification settings
def
select_
users_group
_setting
(
project
,
project_members
,
global_setting
,
users_global_level_watch
)
def
select_
group_member
_setting
(
project
,
project_members
,
global_setting
,
users_global_level_watch
)
uids
=
users_group
_notification
(
project
,
Notification
::
N_WATCH
)
uids
=
group_member
_notification
(
project
,
Notification
::
N_WATCH
)
# Group setting is watch, add to users list if user is not project member
# Group setting is watch, add to users list if user is not project member
users
=
[]
users
=
[]
...
...
app/views/admin/users/show.html.haml
View file @
99f99575
...
@@ -174,15 +174,15 @@
...
@@ -174,15 +174,15 @@
.panel.panel-default
.panel.panel-default
.panel-heading
Groups:
.panel-heading
Groups:
%ul
.well-list
%ul
.well-list
-
@user
.
group_members
.
each
do
|
user_group
|
-
@user
.
group_members
.
each
do
|
group_member
|
-
group
=
user_group
.
group
-
group
=
group_member
.
group
%li
.group_member
%li
.group_member
%span
{
class:
(
"list-item-name"
unless
user_group
.
owner?
)}
%span
{
class:
(
"list-item-name"
unless
group_member
.
owner?
)}
%strong
=
link_to
group
.
name
,
admin_group_path
(
group
)
%strong
=
link_to
group
.
name
,
admin_group_path
(
group
)
.pull-right
.pull-right
%span
.light
=
user_group
.
human_access
%span
.light
=
group_member
.
human_access
-
unless
user_group
.
owner?
-
unless
group_member
.
owner?
=
link_to
group_group_member_path
(
group
,
user_group
),
data:
{
confirm:
remove_user_from_group_message
(
group
,
@user
)
},
method: :delete
,
remote:
true
,
class:
"btn-xs btn btn-remove"
,
title:
'Remove user from group'
do
=
link_to
group_group_member_path
(
group
,
group_member
),
data:
{
confirm:
remove_user_from_group_message
(
group
,
@user
)
},
method: :delete
,
remote:
true
,
class:
"btn-xs btn btn-remove"
,
title:
'Remove user from group'
do
%i
.fa.fa-times.fa-inverse
%i
.fa.fa-times.fa-inverse
-
else
-
else
.nothing-here-block
This user has no groups.
.nothing-here-block
This user has no groups.
...
@@ -207,21 +207,21 @@
...
@@ -207,21 +207,21 @@
.panel-heading
Joined projects (
#{
@joined_projects
.
count
}
)
.panel-heading
Joined projects (
#{
@joined_projects
.
count
}
)
%ul
.well-list
%ul
.well-list
-
@joined_projects
.
sort_by
(
&
:name_with_namespace
).
each
do
|
project
|
-
@joined_projects
.
sort_by
(
&
:name_with_namespace
).
each
do
|
project
|
-
tm
=
project
.
team
.
find_tm
(
@user
.
id
)
-
member
=
project
.
team
.
find_member
(
@user
.
id
)
%li
.project_member
%li
.project_member
.list-item-name
.list-item-name
=
link_to
admin_namespace_project_path
(
project
.
namespace
,
project
),
class:
dom_class
(
project
)
do
=
link_to
admin_namespace_project_path
(
project
.
namespace
,
project
),
class:
dom_class
(
project
)
do
=
project
.
name_with_namespace
=
project
.
name_with_namespace
-
if
tm
-
if
member
.pull-right
.pull-right
-
if
tm
.
owner?
-
if
member
.
owner?
%span
.light
Owner
%span
.light
Owner
-
else
-
else
%span
.light
=
tm
.
human_access
%span
.light
=
member
.
human_access
-
if
tm
.
respond_to?
:project
-
if
member
.
respond_to?
:project
=
link_to
namespace_project_
team
_member_path
(
project
.
namespace
,
project
,
@user
),
data:
{
confirm:
remove_from_project_team_message
(
project
,
@user
)
},
remote:
true
,
method: :delete
,
class:
"btn-xs btn btn-remove"
,
title:
'Remove user from project'
do
=
link_to
namespace_project_
project
_member_path
(
project
.
namespace
,
project
,
@user
),
data:
{
confirm:
remove_from_project_team_message
(
project
,
@user
)
},
remote:
true
,
method: :delete
,
class:
"btn-xs btn btn-remove"
,
title:
'Remove user from project'
do
%i
.fa.fa-times
%i
.fa.fa-times
#ssh-keys
.tab-pane
#ssh-keys
.tab-pane
=
render
'profiles/keys/key_table'
,
admin:
true
=
render
'profiles/keys/key_table'
,
admin:
true
app/views/dashboard/groups/index.html.haml
View file @
99f99575
...
@@ -11,10 +11,10 @@
...
@@ -11,10 +11,10 @@
.panel.panel-default
.panel.panel-default
.panel-heading
.panel-heading
%strong
Groups
%strong
Groups
(
#{
@
user_group
s
.
count
}
)
(
#{
@
group_member
s
.
count
}
)
%ul
.well-list
%ul
.well-list
-
@
user_groups
.
each
do
|
user_group
|
-
@
group_members
.
each
do
|
group_member
|
-
group
=
user_group
.
group
-
group
=
group_member
.
group
%li
%li
.pull-right
.pull-right
-
if
can?
(
current_user
,
:manage_group
,
group
)
-
if
can?
(
current_user
,
:manage_group
,
group
)
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
%i
.fa.fa-cogs
%i
.fa.fa-cogs
Settings
Settings
-
if
can?
(
current_user
,
:destroy
,
user_group
)
-
if
can?
(
current_user
,
:destroy
_group_member
,
group_member
)
=
link_to
leave_dashboard_group_path
(
group
),
data:
{
confirm:
leave_group_message
(
group
.
name
)
},
method: :delete
,
class:
"btn-sm btn btn-grouped"
,
title:
'Remove user from group'
do
=
link_to
leave_dashboard_group_path
(
group
),
data:
{
confirm:
leave_group_message
(
group
.
name
)
},
method: :delete
,
class:
"btn-sm btn btn-grouped"
,
title:
'Remove user from group'
do
%i
.fa.fa-sign-out
%i
.fa.fa-sign-out
Leave
Leave
...
@@ -32,9 +32,9 @@
...
@@ -32,9 +32,9 @@
%strong
=
group
.
name
%strong
=
group
.
name
as
as
%strong
#{
user_group
.
human_access
}
%strong
#{
group_member
.
human_access
}
%div
.light
%div
.light
#{
pluralize
(
group
.
projects
.
count
,
"project"
)
}
,
#{
pluralize
(
group
.
users
.
count
,
"user"
)
}
#{
pluralize
(
group
.
projects
.
count
,
"project"
)
}
,
#{
pluralize
(
group
.
users
.
count
,
"user"
)
}
=
paginate
@
user_group
s
=
paginate
@
group_member
s
app/views/groups/group_members/_group_member.html.haml
View file @
99f99575
...
@@ -16,11 +16,11 @@
...
@@ -16,11 +16,11 @@
%span
.pull-right
%span
.pull-right
%strong
=
member
.
human_access
%strong
=
member
.
human_access
-
if
show_controls
-
if
show_controls
-
if
can?
(
current_user
,
:modify
,
member
)
-
if
can?
(
current_user
,
:modify
_group_member
,
member
)
=
button_tag
class:
"btn-xs btn js-toggle-button"
,
=
button_tag
class:
"btn-xs btn js-toggle-button"
,
title:
'Edit access level'
,
type:
'button'
do
title:
'Edit access level'
,
type:
'button'
do
%i
.fa.fa-pencil-square-o
%i
.fa.fa-pencil-square-o
-
if
can?
(
current_user
,
:destroy
,
member
)
-
if
can?
(
current_user
,
:destroy
_group_member
,
member
)
-
if
current_user
==
member
.
user
-
if
current_user
==
member
.
user
=
link_to
leave_dashboard_group_path
(
@group
),
data:
{
confirm:
leave_group_message
(
@group
.
name
)},
method: :delete
,
class:
"btn-xs btn btn-remove"
,
title:
'Remove user from group'
do
=
link_to
leave_dashboard_group_path
(
@group
),
data:
{
confirm:
leave_group_message
(
@group
.
name
)},
method: :delete
,
class:
"btn-xs btn btn-remove"
,
title:
'Remove user from group'
do
%i
.fa.fa-minus.fa-inverse
%i
.fa.fa-minus.fa-inverse
...
...
app/views/notify/group_access_granted_email.html.haml
View file @
99f99575
%p
%p
=
"You have been granted
#{
@
membership
.
human_access
}
access to group"
=
"You have been granted
#{
@
group_member
.
human_access
}
access to group"
=
link_to
group_url
(
@group
)
do
=
link_to
group_url
(
@group
)
do
=
@group
.
name
=
@group
.
name
app/views/notify/group_access_granted_email.text.erb
View file @
99f99575
You have been granted
<%=
@
membership
.
human_access
%>
access to group
<%=
@group
.
name
%>
You have been granted
<%=
@
group_member
.
human_access
%>
access to group
<%=
@group
.
name
%>
<%=
url_for
(
group_url
(
@group
))
%>
<%=
url_for
(
group_url
(
@group
))
%>
app/views/profiles/notifications/show.html.haml
View file @
99f99575
...
@@ -62,9 +62,9 @@
...
@@ -62,9 +62,9 @@
By default, all projects and groups will use the notification level set above.
By default, all projects and groups will use the notification level set above.
%h4
Groups:
%h4
Groups:
%ul
.bordered-list
%ul
.bordered-list
-
@group_members
.
each
do
|
users_group
|
-
@group_members
.
each
do
|
group_member
|
-
notification
=
Notification
.
new
(
users_group
)
-
notification
=
Notification
.
new
(
group_member
)
=
render
'settings'
,
type:
'group'
,
membership:
users_group
,
notification:
notification
=
render
'settings'
,
type:
'group'
,
membership:
group_member
,
notification:
notification
.col-md-6
.col-md-6
%p
%p
...
...
lib/api/group_members.rb
View file @
99f99575
...
@@ -53,14 +53,14 @@ module API
...
@@ -53,14 +53,14 @@ module API
authorize!
:manage_group
,
group
authorize!
:manage_group
,
group
required_attributes!
[
:access_level
]
required_attributes!
[
:access_level
]
team
_member
=
group
.
group_members
.
find_by
(
user_id:
params
[
:user_id
])
group
_member
=
group
.
group_members
.
find_by
(
user_id:
params
[
:user_id
])
not_found!
(
'User can not be found'
)
if
team
_member
.
nil?
not_found!
(
'User can not be found'
)
if
group
_member
.
nil?
if
team
_member
.
update_attributes
(
access_level:
params
[
:access_level
])
if
group
_member
.
update_attributes
(
access_level:
params
[
:access_level
])
@member
=
team
_member
.
user
@member
=
group
_member
.
user
present
@member
,
with:
Entities
::
GroupMember
,
group:
group
present
@member
,
with:
Entities
::
GroupMember
,
group:
group
else
else
handle_member_errors
team
_member
.
errors
handle_member_errors
group
_member
.
errors
end
end
end
end
...
...
spec/models/members/group_member_spec.rb
View file @
99f99575
...
@@ -28,18 +28,18 @@ describe GroupMember do
...
@@ -28,18 +28,18 @@ describe GroupMember do
describe
"#after_update"
do
describe
"#after_update"
do
before
do
before
do
@
membership
=
create
:group_member
@
group_member
=
create
:group_member
@
membership
.
stub
(
notification_service:
double
(
'NotificationService'
).
as_null_object
)
@
group_member
.
stub
(
notification_service:
double
(
'NotificationService'
).
as_null_object
)
end
end
it
"should send email to user"
do
it
"should send email to user"
do
expect
(
@
membership
).
to
receive
(
:notification_service
)
expect
(
@
group_member
).
to
receive
(
:notification_service
)
@
membership
.
update_attribute
(
:access_level
,
GroupMember
::
MASTER
)
@
group_member
.
update_attribute
(
:access_level
,
GroupMember
::
MASTER
)
end
end
it
"does not send an email when the access level has not changed"
do
it
"does not send an email when the access level has not changed"
do
expect
(
@
membership
).
not_to
receive
(
:notification_service
)
expect
(
@
group_member
).
not_to
receive
(
:notification_service
)
@
membership
.
update_attribute
(
:access_level
,
GroupMember
::
OWNER
)
@
group_member
.
update_attribute
(
:access_level
,
GroupMember
::
OWNER
)
end
end
end
end
end
end
...
...
spec/services/notification_service_spec.rb
View file @
99f99575
...
@@ -69,9 +69,9 @@ describe NotificationService do
...
@@ -69,9 +69,9 @@ describe NotificationService do
user_project
=
note
.
project
.
project_members
.
find_by_user_id
(
@u_watcher
.
id
)
user_project
=
note
.
project
.
project_members
.
find_by_user_id
(
@u_watcher
.
id
)
user_project
.
notification_level
=
Notification
::
N_PARTICIPATING
user_project
.
notification_level
=
Notification
::
N_PARTICIPATING
user_project
.
save
user_project
.
save
user_group
=
note
.
project
.
group
.
group_members
.
find_by_user_id
(
@u_watcher
.
id
)
group_member
=
note
.
project
.
group
.
group_members
.
find_by_user_id
(
@u_watcher
.
id
)
user_group
.
notification_level
=
Notification
::
N_GLOBAL
group_member
.
notification_level
=
Notification
::
N_GLOBAL
user_group
.
save
group_member
.
save
end
end
it
do
it
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