Commit bdbadebe authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix adminarea and emails for new membership logic

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 1aa48174
...@@ -18,9 +18,9 @@ class Profiles::NotificationsController < ApplicationController ...@@ -18,9 +18,9 @@ class Profiles::NotificationsController < ApplicationController
users_group.notification_level = params[:notification_level] users_group.notification_level = params[:notification_level]
users_group.save users_group.save
else else
users_project = current_user.project_members.find(params[:notification_id]) project_member = current_user.project_members.find(params[:notification_id])
users_project.notification_level = params[:notification_level] project_member.notification_level = params[:notification_level]
users_project.save project_member.save
end end
end end
end end
module Emails module Emails
module Groups module Groups
def access_level_granted_email(user_group_id) def group_access_granted_email(user_group_id)
@membership = GroupMember.find(user_group_id) @membership = GroupMember.find(user_group_id)
@group = @membership.group @group = @membership.group
@target_url = group_url(@group) @target_url = group_url(@group)
......
module Emails module Emails
module Projects module Projects
def access_level_granted_email(user_project_id) def project_access_granted_email(user_project_id)
@users_project = ProjectMember.find user_project_id @project_member = ProjectMember.find user_project_id
@project = @users_project.project @project = @project_member.project
@target_url = project_url(@project) @target_url = project_url(@project)
mail(to: @users_project.user.email, mail(to: @project_member.user.email,
subject: subject("Access to project was granted")) subject: subject("Access to project was granted"))
end end
......
...@@ -177,7 +177,7 @@ class User < ActiveRecord::Base ...@@ -177,7 +177,7 @@ class User < ActiveRecord::Base
scope :in_team, ->(team){ where(id: team.member_ids) } scope :in_team, ->(team){ where(id: team.member_ids) }
scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) }
scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all } scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all }
scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM project_members)') } scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members)') }
scope :ldap, -> { where(provider: 'ldap') } scope :ldap, -> { where(provider: 'ldap') }
scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active } scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active }
......
...@@ -157,20 +157,20 @@ class NotificationService ...@@ -157,20 +157,20 @@ class NotificationService
end end
end end
def new_team_member(users_project) def new_team_member(project_member)
mailer.access_level_granted_email(users_project.id) mailer.project_access_granted_email(project_member.id)
end end
def update_team_member(users_project) def update_team_member(project_member)
mailer.access_level_granted_email(users_project.id) mailer.project_access_granted_email(project_member.id)
end end
def new_group_member(users_group) def new_group_member(users_group)
mailer.access_level_granted_email(users_group.id) mailer.group_access_granted_email(users_group.id)
end end
def update_group_member(users_group) def update_group_member(users_group)
mailer.access_level_granted_email(users_group.id) mailer.group_access_granted_email(users_group.id)
end end
def project_was_moved(project) def project_was_moved(project)
...@@ -186,19 +186,19 @@ class NotificationService ...@@ -186,19 +186,19 @@ class NotificationService
# Get project users with WATCH notification level # Get project users with WATCH notification level
def project_watchers(project) def project_watchers(project)
project_members = users_project_notification(project) project_members = project_member_notification(project)
users_with_project_level_global = users_project_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 = users_group_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_users_project_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_users_group_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
def users_project_notification(project, notification_level=nil) def project_member_notification(project, notification_level=nil)
project_members = project.project_members project_members = project.project_members
if notification_level if notification_level
...@@ -224,8 +224,8 @@ class NotificationService ...@@ -224,8 +224,8 @@ class NotificationService
end end
# Build a list of users based on project notifcation settings # Build a list of users based on project notifcation settings
def select_users_project_setting(project, global_setting, users_global_level_watch) def select_project_member_setting(project, global_setting, users_global_level_watch)
users = users_project_notification(project, Notification::N_WATCH) users = project_member_notification(project, Notification::N_WATCH)
# If project setting is global, add to watch list if global setting is watch # If project setting is global, add to watch list if global setting is watch
global_setting.each do |user_id| global_setting.each do |user_id|
......
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
= link_to user.name, admin_user_path(user) = link_to user.name, admin_user_path(user)
%span.pull-right.light %span.pull-right.light
= member.human_access = member.human_access
= link_to group_users_group_path(@group, member), data: { confirm: remove_user_from_group_message(@group, user) }, method: :delete, remote: true, class: "btn-tiny btn btn-remove", title: 'Remove user from group' do = link_to group_group_members_path(@group, member), data: { confirm: remove_user_from_group_message(@group, user) }, method: :delete, remote: true, class: "btn-tiny btn btn-remove", title: 'Remove user from group' do
%i.icon-minus.icon-white %i.icon-minus.icon-white
.panel-footer .panel-footer
= paginate @members, param_name: 'members_page', theme: 'gitlab' = paginate @members, param_name: 'members_page', theme: 'gitlab'
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
%i.icon-edit %i.icon-edit
%ul.well-list %ul.well-list
- @group_members.each do |member| - @group_members.each do |member|
= render 'group_members/users_group', member: member, show_controls: false = render 'groups/group_members/group_member', member: member, show_controls: false
.panel-footer .panel-footer
= paginate @group_members, param_name: 'group_members_page', theme: 'gitlab' = paginate @group_members, param_name: 'group_members_page', theme: 'gitlab'
...@@ -115,17 +115,17 @@ ...@@ -115,17 +115,17 @@
%i.icon-edit %i.icon-edit
Manage Access Manage Access
%ul.well-list.team_members %ul.well-list.team_members
- @project_members.each do |users_project| - @project_members.each do |project_member|
- user = users_project.user - user = project_member.user
%li.project_member %li.project_member
.list-item-name .list-item-name
%strong %strong
= link_to user.name, admin_user_path(user) = link_to user.name, admin_user_path(user)
.pull-right .pull-right
- if users_project.owner? - if project_member.owner?
%span.light Owner %span.light Owner
- else - else
%span.light= users_project.human_access %span.light= project_member.human_access
= link_to project_team_member_path(@project, user), data: { confirm: remove_from_project_team_message(@project, user)}, method: :delete, remote: true, class: "btn btn-small btn-remove" do = link_to project_team_member_path(@project, user), data: { confirm: remove_from_project_team_message(@project, user)}, method: :delete, remote: true, class: "btn btn-small btn-remove" do
%i.icon-remove %i.icon-remove
.panel-footer .panel-footer
......
%p %p
= "You have been granted #{@users_project.human_access} access to project" = "You have been granted #{@project_member.human_access} access to project"
%p %p
= link_to project_url(@project) do = link_to project_url(@project) do
= @project.name_with_namespace = @project.name_with_namespace
You have been granted <%= @users_project.human_access %> access to project <%= @project.name_with_namespace %> You have been granted <%= @project_member.human_access %> access to project <%= @project.name_with_namespace %>
<%= url_for(project_url(@project)) %> <%= url_for(project_url(@project)) %>
...@@ -46,6 +46,6 @@ ...@@ -46,6 +46,6 @@
.col-md-6 .col-md-6
%h4 Projects: %h4 Projects:
%ul.bordered-list %ul.bordered-list
- @project_members.each do |users_project| - @project_members.each do |project_member|
- notification = Notification.new(users_project) - notification = Notification.new(project_member)
= render 'settings', type: 'project', membership: users_project, notification: notification = render 'settings', type: 'project', membership: project_member, notification: notification
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
%i.icon-edit %i.icon-edit
%ul.well-list %ul.well-list
- @group.group_members.order('access_level DESC').limit(20).each do |member| - @group.group_members.order('access_level DESC').limit(20).each do |member|
= render 'group_members/users_group', member: member, show_controls: false = render 'groups/group_members/group_member', member: member, show_controls: false
- if group_users_count > 20 - if group_users_count > 20
%li %li
and #{group_users_count - 20} more. For full list visit #{link_to 'group members page', members_group_path(@group)} and #{group_users_count - 20} more. For full list visit #{link_to 'group members page', members_group_path(@group)}
...@@ -39,10 +39,10 @@ FactoryGirl.define do ...@@ -39,10 +39,10 @@ FactoryGirl.define do
owner owner
end end
factory :users_project do factory :project_member do
user user
project project
project_access { ProjectMember::MASTER } access_level { ProjectMember::MASTER }
end end
factory :issue do factory :issue do
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
# #
FactoryGirl.define do FactoryGirl.define do
factory :users_group do factory :group_member do
group_access { GroupMember::OWNER } access_level { GroupMember::OWNER }
group group
user user
end end
......
...@@ -402,10 +402,10 @@ describe Notify do ...@@ -402,10 +402,10 @@ describe Notify do
describe 'project access changed' do describe 'project access changed' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:users_project) { create(:users_project, let(:project_member) { create(:project_member,
project: project, project: project,
user: user) } user: user) }
subject { Notify.project_access_granted_email(users_project.id) } subject { Notify.project_access_granted_email(project_member.id) }
it_behaves_like 'an email sent from GitLab' it_behaves_like 'an email sent from GitLab'
...@@ -416,7 +416,7 @@ describe Notify do ...@@ -416,7 +416,7 @@ describe Notify do
should have_body_text /#{project.name}/ should have_body_text /#{project.name}/
end end
it 'contains new user role' do it 'contains new user role' do
should have_body_text /#{users_project.human_access}/ should have_body_text /#{project_member.human_access}/
end end
end end
......
...@@ -7,8 +7,8 @@ describe API::API, api: true do ...@@ -7,8 +7,8 @@ describe API::API, api: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) } let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:users_project, user: user, project: project, project_access: ProjectMember::MASTER) } let!(:master) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:users_project, user: user2, project: project, project_access: ProjectMember::GUEST) } let!(:guest) { create(:project_member, user: user2, project: project, project_access: ProjectMember::GUEST) }
let!(:branch_name) { 'feature' } let!(:branch_name) { 'feature' }
let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' }
......
...@@ -6,8 +6,8 @@ describe API::API, api: true do ...@@ -6,8 +6,8 @@ describe API::API, api: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) } let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:users_project, user: user, project: project, project_access: ProjectMember::MASTER) } let!(:master) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:users_project, user: user2, project: project, project_access: ProjectMember::GUEST) } let!(:guest) { create(:project_member, user: user2, project: project, project_access: ProjectMember::GUEST) }
before { project.team << [user, :reporter] } before { project.team << [user, :reporter] }
......
...@@ -6,12 +6,12 @@ describe API::API, api: true do ...@@ -6,12 +6,12 @@ describe API::API, api: true do
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(:user3) { create(:user) } let(:user3) { create(:user) }
let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) } let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
let(:users_project) { create(:users_project, user: user, project: project, project_access: ProjectMember::MASTER) } let(:project_member) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let(:users_project2) { create(:users_project, user: user3, project: project, project_access: ProjectMember::DEVELOPER) } let(:project_member2) { create(:project_member, user: user3, project: project, project_access: ProjectMember::DEVELOPER) }
describe "GET /projects/:id/members" do describe "GET /projects/:id/members" do
before { users_project } before { project_member }
before { users_project2 } before { project_member2 }
it "should return project team members" do it "should return project team members" do
get api("/projects/#{project.id}/members", user) get api("/projects/#{project.id}/members", user)
...@@ -36,7 +36,7 @@ describe API::API, api: true do ...@@ -36,7 +36,7 @@ describe API::API, api: true do
end end
describe "GET /projects/:id/members/:user_id" do describe "GET /projects/:id/members/:user_id" do
before { users_project } before { project_member }
it "should return project team member" do it "should return project team member" do
get api("/projects/#{project.id}/members/#{user.id}", user) get api("/projects/#{project.id}/members/#{user.id}", user)
...@@ -93,7 +93,7 @@ describe API::API, api: true do ...@@ -93,7 +93,7 @@ describe API::API, api: true do
end end
describe "PUT /projects/:id/members/:user_id" do describe "PUT /projects/:id/members/:user_id" do
before { users_project2 } before { project_member2 }
it "should update project team member" do it "should update project team member" do
put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER
...@@ -119,8 +119,8 @@ describe API::API, api: true do ...@@ -119,8 +119,8 @@ describe API::API, api: true do
end end
describe "DELETE /projects/:id/members/:user_id" do describe "DELETE /projects/:id/members/:user_id" do
before { users_project } before { project_member }
before { users_project2 } before { project_member2 }
it "should remove user from project team" do it "should remove user from project team" do
expect { expect {
......
...@@ -8,8 +8,8 @@ describe API::API, api: true do ...@@ -8,8 +8,8 @@ describe API::API, api: true do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) } let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
let(:snippet) { create(:project_snippet, author: user, project: project, title: 'example') } let(:snippet) { create(:project_snippet, author: user, project: project, title: 'example') }
let(:users_project) { create(:users_project, user: user, project: project, project_access: ProjectMember::MASTER) } let(:project_member) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let(:users_project2) { create(:users_project, user: user3, project: project, project_access: ProjectMember::DEVELOPER) } let(:project_member2) { create(:project_member, user: user3, project: project, project_access: ProjectMember::DEVELOPER) }
describe "GET /projects" do describe "GET /projects" do
before { project } before { project }
...@@ -254,7 +254,7 @@ describe API::API, api: true do ...@@ -254,7 +254,7 @@ describe API::API, api: true do
describe "GET /projects/:id" do describe "GET /projects/:id" do
before { project } before { project }
before { users_project } before { project_member }
it "should return a project by id" do it "should return a project by id" do
get api("/projects/#{project.id}", user) get api("/projects/#{project.id}", user)
...@@ -305,7 +305,7 @@ describe API::API, api: true do ...@@ -305,7 +305,7 @@ describe API::API, api: true do
end end
describe "GET /projects/:id/events" do describe "GET /projects/:id/events" do
before { users_project } before { project_member }
it "should return a project events" do it "should return a project events" do
get api("/projects/#{project.id}/events", user) get api("/projects/#{project.id}/events", user)
......
...@@ -8,8 +8,8 @@ describe API::API, api: true do ...@@ -8,8 +8,8 @@ describe API::API, api: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) } let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:users_project, user: user, project: project, project_access: ProjectMember::MASTER) } let!(:master) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:users_project, user: user2, project: project, project_access: ProjectMember::GUEST) } let!(:guest) { create(:project_member, user: user2, project: project, project_access: ProjectMember::GUEST) }
before { project.team << [user, :reporter] } before { project.team << [user, :reporter] }
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe SystemHooksService do describe SystemHooksService do
let (:user) { create :user } let (:user) { create :user }
let (:project) { create :project } let (:project) { create :project }
let (:users_project) { create :users_project } let (:project_member) { create :project_member }
let (:key) { create(:key, user: user) } let (:key) { create(:key, user: user) }
context 'event data' do context 'event data' do
...@@ -11,8 +11,8 @@ describe SystemHooksService do ...@@ -11,8 +11,8 @@ describe SystemHooksService do
it { event_data(user, :destroy).should include(:event_name, :name, :created_at, :email, :user_id) } it { event_data(user, :destroy).should include(:event_name, :name, :created_at, :email, :user_id) }
it { event_data(project, :create).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) } it { event_data(project, :create).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
it { event_data(project, :destroy).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) } it { event_data(project, :destroy).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
it { event_data(users_project, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access, :project_visibility) } it { event_data(project_member, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :access_level, :project_visibility) }
it { event_data(users_project, :destroy).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access, :project_visibility) } it { event_data(project_member, :destroy).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :access_level, :project_visibility) }
it { event_data(key, :create).should include(:username, :key, :id) } it { event_data(key, :create).should include(:username, :key, :id) }
it { event_data(key, :destroy).should include(:username, :key, :id) } it { event_data(key, :destroy).should include(:username, :key, :id) }
end end
...@@ -22,8 +22,8 @@ describe SystemHooksService do ...@@ -22,8 +22,8 @@ describe SystemHooksService do
it { event_name(user, :destroy).should eq "user_destroy" } it { event_name(user, :destroy).should eq "user_destroy" }
it { event_name(project, :create).should eq "project_create" } it { event_name(project, :create).should eq "project_create" }
it { event_name(project, :destroy).should eq "project_destroy" } it { event_name(project, :destroy).should eq "project_destroy" }
it { event_name(users_project, :create).should eq "user_add_to_team" } it { event_name(project_member, :create).should eq "user_add_to_team" }
it { event_name(users_project, :destroy).should eq "user_remove_from_team" } it { event_name(project_member, :destroy).should eq "user_remove_from_team" }
it { event_name(key, :create).should eq 'key_create' } it { event_name(key, :create).should eq 'key_create' }
it { event_name(key, :destroy).should eq 'key_destroy' } it { event_name(key, :destroy).should eq 'key_destroy' }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment