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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
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
end
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.
@
users_group
.
destroy
if
can?
(
current_user
,
:destroy
_group_member
,
@group_member
)
# May fail if last owner.
@
group_member
.
destroy
respond_to
do
|
format
|
format
.
html
{
redirect_to
members_group_path
(
@group
),
notice:
'User was successfully removed from group.'
}
format
.
js
{
render
nothing:
true
}
...
...
app/controllers/profiles/notifications_controller.rb
View file @
99f99575
...
...
@@ -14,9 +14,9 @@ class Profiles::NotificationsController < ApplicationController
@saved
=
if
type
==
'global'
current_user
.
update_attributes
(
user_params
)
elsif
type
==
'group'
users_group
=
current_user
.
group_members
.
find
(
params
[
:notification_id
])
users_group
.
notification_level
=
params
[
:notification_level
]
users_group
.
save
group_member
=
current_user
.
group_members
.
find
(
params
[
:notification_id
])
group_member
.
notification_level
=
params
[
:notification_level
]
group_member
.
save
else
project_member
=
current_user
.
project_members
.
find
(
params
[
:notification_id
])
project_member
.
notification_level
=
params
[
:notification_level
]
...
...
app/mailers/emails/groups.rb
View file @
99f99575
module
Emails
module
Groups
def
group_access_granted_email
(
user_group
_id
)
@
membership
=
GroupMember
.
find
(
user_group
_id
)
@group
=
@
membership
.
group
def
group_access_granted_email
(
group_member
_id
)
@
group_member
=
GroupMember
.
find
(
group_member
_id
)
@group
=
@
group_member
.
group
@target_url
=
group_url
(
@group
)
mail
(
to:
@
membership
.
user
.
email
,
mail
(
to:
@
group_member
.
user
.
email
,
subject:
subject
(
"Access to group was granted"
))
end
end
...
...
app/models/ability.rb
View file @
99f99575
...
...
@@ -14,7 +14,7 @@ class Ability
when
"MergeRequest"
then
merge_request_abilities
(
user
,
subject
)
when
"Group"
then
group_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
[]
end
.
concat
(
global_abilities
(
user
))
end
...
...
@@ -248,17 +248,17 @@ class Ability
end
end
def
users_group
_abilities
(
user
,
subject
)
def
group_member
_abilities
(
user
,
subject
)
rules
=
[]
target_user
=
subject
.
user
group
=
subject
.
group
can_manage
=
group_abilities
(
user
,
group
).
include?
(
:manage_group
)
if
can_manage
&&
(
user
!=
target_user
)
rules
<<
:modify
rules
<<
:destroy
rules
<<
:modify
_group_member
rules
<<
:destroy
_group_member
end
if
!
group
.
last_owner?
(
user
)
&&
(
can_manage
||
(
user
==
target_user
))
rules
<<
:destroy
rules
<<
:destroy
_group_member
end
rules
end
...
...
app/services/notification_service.rb
View file @
99f99575
...
...
@@ -194,11 +194,11 @@ class NotificationService
project_members
=
project_member_notification
(
project
)
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_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
end
...
...
@@ -213,7 +213,7 @@ class NotificationService
end
end
def
users_group
_notification
(
project
,
notification_level
)
def
group_member
_notification
(
project
,
notification_level
)
if
project
.
group
project
.
group
.
group_members
.
where
(
notification_level:
notification_level
).
pluck
(
:user_id
)
else
...
...
@@ -243,8 +243,8 @@ class NotificationService
end
# Build a list of users based on group notification settings
def
select_
users_group
_setting
(
project
,
project_members
,
global_setting
,
users_global_level_watch
)
uids
=
users_group
_notification
(
project
,
Notification
::
N_WATCH
)
def
select_
group_member
_setting
(
project
,
project_members
,
global_setting
,
users_global_level_watch
)
uids
=
group_member
_notification
(
project
,
Notification
::
N_WATCH
)
# Group setting is watch, add to users list if user is not project member
users
=
[]
...
...
app/views/admin/users/show.html.haml
View file @
99f99575
...
...
@@ -174,15 +174,15 @@
.panel.panel-default
.panel-heading
Groups:
%ul
.well-list
-
@user
.
group_members
.
each
do
|
user_group
|
-
group
=
user_group
.
group
-
@user
.
group_members
.
each
do
|
group_member
|
-
group
=
group_member
.
group
%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
)
.pull-right
%span
.light
=
user_group
.
human_access
-
unless
user_group
.
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
%span
.light
=
group_member
.
human_access
-
unless
group_member
.
owner?
=
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
-
else
.nothing-here-block
This user has no groups.
...
...
@@ -207,21 +207,21 @@
.panel-heading
Joined projects (
#{
@joined_projects
.
count
}
)
%ul
.well-list
-
@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
.list-item-name
=
link_to
admin_namespace_project_path
(
project
.
namespace
,
project
),
class:
dom_class
(
project
)
do
=
project
.
name_with_namespace
-
if
tm
-
if
member
.pull-right
-
if
tm
.
owner?
-
if
member
.
owner?
%span
.light
Owner
-
else
%span
.light
=
tm
.
human_access
%span
.light
=
member
.
human_access
-
if
tm
.
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
-
if
member
.
respond_to?
:project
=
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
#ssh-keys
.tab-pane
=
render
'profiles/keys/key_table'
,
admin:
true
app/views/dashboard/groups/index.html.haml
View file @
99f99575
...
...
@@ -11,10 +11,10 @@
.panel.panel-default
.panel-heading
%strong
Groups
(
#{
@
user_group
s
.
count
}
)
(
#{
@
group_member
s
.
count
}
)
%ul
.well-list
-
@
user_groups
.
each
do
|
user_group
|
-
group
=
user_group
.
group
-
@
group_members
.
each
do
|
group_member
|
-
group
=
group_member
.
group
%li
.pull-right
-
if
can?
(
current_user
,
:manage_group
,
group
)
...
...
@@ -22,7 +22,7 @@
%i
.fa.fa-cogs
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
%i
.fa.fa-sign-out
Leave
...
...
@@ -32,9 +32,9 @@
%strong
=
group
.
name
as
%strong
#{
user_group
.
human_access
}
%strong
#{
group_member
.
human_access
}
%div
.light
#{
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 @@
%span
.pull-right
%strong
=
member
.
human_access
-
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"
,
title:
'Edit access level'
,
type:
'button'
do
%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
=
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
...
...
app/views/notify/group_access_granted_email.html.haml
View file @
99f99575
%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
=
@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
))
%>
app/views/profiles/notifications/show.html.haml
View file @
99f99575
...
...
@@ -62,9 +62,9 @@
By default, all projects and groups will use the notification level set above.
%h4
Groups:
%ul
.bordered-list
-
@group_members
.
each
do
|
users_group
|
-
notification
=
Notification
.
new
(
users_group
)
=
render
'settings'
,
type:
'group'
,
membership:
users_group
,
notification:
notification
-
@group_members
.
each
do
|
group_member
|
-
notification
=
Notification
.
new
(
group_member
)
=
render
'settings'
,
type:
'group'
,
membership:
group_member
,
notification:
notification
.col-md-6
%p
...
...
lib/api/group_members.rb
View file @
99f99575
...
...
@@ -53,14 +53,14 @@ module API
authorize!
:manage_group
,
group
required_attributes!
[
:access_level
]
team
_member
=
group
.
group_members
.
find_by
(
user_id:
params
[
:user_id
])
not_found!
(
'User can not be found'
)
if
team
_member
.
nil?
group
_member
=
group
.
group_members
.
find_by
(
user_id:
params
[
:user_id
])
not_found!
(
'User can not be found'
)
if
group
_member
.
nil?
if
team
_member
.
update_attributes
(
access_level:
params
[
:access_level
])
@member
=
team
_member
.
user
if
group
_member
.
update_attributes
(
access_level:
params
[
:access_level
])
@member
=
group
_member
.
user
present
@member
,
with:
Entities
::
GroupMember
,
group:
group
else
handle_member_errors
team
_member
.
errors
handle_member_errors
group
_member
.
errors
end
end
...
...
spec/models/members/group_member_spec.rb
View file @
99f99575
...
...
@@ -28,18 +28,18 @@ describe GroupMember do
describe
"#after_update"
do
before
do
@
membership
=
create
:group_member
@
membership
.
stub
(
notification_service:
double
(
'NotificationService'
).
as_null_object
)
@
group_member
=
create
:group_member
@
group_member
.
stub
(
notification_service:
double
(
'NotificationService'
).
as_null_object
)
end
it
"should send email to user"
do
expect
(
@
membership
).
to
receive
(
:notification_service
)
@
membership
.
update_attribute
(
:access_level
,
GroupMember
::
MASTER
)
expect
(
@
group_member
).
to
receive
(
:notification_service
)
@
group_member
.
update_attribute
(
:access_level
,
GroupMember
::
MASTER
)
end
it
"does not send an email when the access level has not changed"
do
expect
(
@
membership
).
not_to
receive
(
:notification_service
)
@
membership
.
update_attribute
(
:access_level
,
GroupMember
::
OWNER
)
expect
(
@
group_member
).
not_to
receive
(
:notification_service
)
@
group_member
.
update_attribute
(
:access_level
,
GroupMember
::
OWNER
)
end
end
end
...
...
spec/services/notification_service_spec.rb
View file @
99f99575
...
...
@@ -69,9 +69,9 @@ describe NotificationService do
user_project
=
note
.
project
.
project_members
.
find_by_user_id
(
@u_watcher
.
id
)
user_project
.
notification_level
=
Notification
::
N_PARTICIPATING
user_project
.
save
user_group
=
note
.
project
.
group
.
group_members
.
find_by_user_id
(
@u_watcher
.
id
)
user_group
.
notification_level
=
Notification
::
N_GLOBAL
user_group
.
save
group_member
=
note
.
project
.
group
.
group_members
.
find_by_user_id
(
@u_watcher
.
id
)
group_member
.
notification_level
=
Notification
::
N_GLOBAL
group_member
.
save
end
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