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
users_group.notification_level = params[:notification_level]
users_group.save
else
users_project = current_user.project_members.find(params[:notification_id])
users_project.notification_level = params[:notification_level]
users_project.save
project_member = current_user.project_members.find(params[:notification_id])
project_member.notification_level = params[:notification_level]
project_member.save
end
end
end
module Emails
module Groups
def access_level_granted_email(user_group_id)
def group_access_granted_email(user_group_id)
@membership = GroupMember.find(user_group_id)
@group = @membership.group
@target_url = group_url(@group)
......
module Emails
module Projects
def access_level_granted_email(user_project_id)
@users_project = ProjectMember.find user_project_id
@project = @users_project.project
def project_access_granted_email(user_project_id)
@project_member = ProjectMember.find user_project_id
@project = @project_member.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"))
end
......
......@@ -177,7 +177,7 @@ class User < ActiveRecord::Base
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_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 :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active }
......
......@@ -157,20 +157,20 @@ class NotificationService
end
end
def new_team_member(users_project)
mailer.access_level_granted_email(users_project.id)
def new_team_member(project_member)
mailer.project_access_granted_email(project_member.id)
end
def update_team_member(users_project)
mailer.access_level_granted_email(users_project.id)
def update_team_member(project_member)
mailer.project_access_granted_email(project_member.id)
end
def new_group_member(users_group)
mailer.access_level_granted_email(users_group.id)
mailer.group_access_granted_email(users_group.id)
end
def update_group_member(users_group)
mailer.access_level_granted_email(users_group.id)
mailer.group_access_granted_email(users_group.id)
end
def project_was_moved(project)
......@@ -186,19 +186,19 @@ class NotificationService
# Get project users with WATCH notification level
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 = 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)
User.where(id: users_with_project_setting.concat(users_with_group_setting).uniq).to_a
end
def users_project_notification(project, notification_level=nil)
def project_member_notification(project, notification_level=nil)
project_members = project.project_members
if notification_level
......@@ -224,8 +224,8 @@ class NotificationService
end
# Build a list of users based on project notifcation settings
def select_users_project_setting(project, global_setting, users_global_level_watch)
users = users_project_notification(project, Notification::N_WATCH)
def select_project_member_setting(project, global_setting, users_global_level_watch)
users = project_member_notification(project, Notification::N_WATCH)
# If project setting is global, add to watch list if global setting is watch
global_setting.each do |user_id|
......
......@@ -80,7 +80,7 @@
= link_to user.name, admin_user_path(user)
%span.pull-right.light
= 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
.panel-footer
= paginate @members, param_name: 'members_page', theme: 'gitlab'
......@@ -101,7 +101,7 @@
%i.icon-edit
%ul.well-list
- @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
= paginate @group_members, param_name: 'group_members_page', theme: 'gitlab'
......@@ -115,17 +115,17 @@
%i.icon-edit
Manage Access
%ul.well-list.team_members
- @project_members.each do |users_project|
- user = users_project.user
- @project_members.each do |project_member|
- user = project_member.user
%li.project_member
.list-item-name
%strong
= link_to user.name, admin_user_path(user)
.pull-right
- if users_project.owner?
- if project_member.owner?
%span.light Owner
- 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
%i.icon-remove
.panel-footer
......
%p
= "You have been granted #{@users_project.human_access} access to project"
= "You have been granted #{@project_member.human_access} access to project"
%p
= link_to project_url(@project) do
= @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)) %>
......@@ -46,6 +46,6 @@
.col-md-6
%h4 Projects:
%ul.bordered-list
- @project_members.each do |users_project|
- notification = Notification.new(users_project)
= render 'settings', type: 'project', membership: users_project, notification: notification
- @project_members.each do |project_member|
- notification = Notification.new(project_member)
= render 'settings', type: 'project', membership: project_member, notification: notification
......@@ -8,7 +8,7 @@
%i.icon-edit
%ul.well-list
- @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
%li
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
owner
end
factory :users_project do
factory :project_member do
user
project
project_access { ProjectMember::MASTER }
access_level { ProjectMember::MASTER }
end
factory :issue do
......
......@@ -12,8 +12,8 @@
#
FactoryGirl.define do
factory :users_group do
group_access { GroupMember::OWNER }
factory :group_member do
access_level { GroupMember::OWNER }
group
user
end
......
......@@ -402,10 +402,10 @@ describe Notify do
describe 'project access changed' do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:users_project) { create(:users_project,
let(:project_member) { create(:project_member,
project: project,
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'
......@@ -416,7 +416,7 @@ describe Notify do
should have_body_text /#{project.name}/
end
it 'contains new user role' do
should have_body_text /#{users_project.human_access}/
should have_body_text /#{project_member.human_access}/
end
end
......
......@@ -7,8 +7,8 @@ describe API::API, api: true do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:users_project, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:users_project, user: user2, project: project, project_access: ProjectMember::GUEST) }
let!(:master) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:project_member, user: user2, project: project, project_access: ProjectMember::GUEST) }
let!(:branch_name) { 'feature' }
let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' }
......
......@@ -6,8 +6,8 @@ describe API::API, api: true do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:users_project, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:users_project, user: user2, project: project, project_access: ProjectMember::GUEST) }
let!(:master) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:project_member, user: user2, project: project, project_access: ProjectMember::GUEST) }
before { project.team << [user, :reporter] }
......
......@@ -6,12 +6,12 @@ describe API::API, api: true do
let(:user2) { create(:user) }
let(:user3) { create(:user) }
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(:users_project2) { create(:users_project, user: user3, project: project, project_access: ProjectMember::DEVELOPER) }
let(:project_member) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let(:project_member2) { create(:project_member, user: user3, project: project, project_access: ProjectMember::DEVELOPER) }
describe "GET /projects/:id/members" do
before { users_project }
before { users_project2 }
before { project_member }
before { project_member2 }
it "should return project team members" do
get api("/projects/#{project.id}/members", user)
......@@ -36,7 +36,7 @@ describe API::API, api: true do
end
describe "GET /projects/:id/members/:user_id" do
before { users_project }
before { project_member }
it "should return project team member" do
get api("/projects/#{project.id}/members/#{user.id}", user)
......@@ -93,7 +93,7 @@ describe API::API, api: true do
end
describe "PUT /projects/:id/members/:user_id" do
before { users_project2 }
before { project_member2 }
it "should update project team member" do
put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER
......@@ -119,8 +119,8 @@ describe API::API, api: true do
end
describe "DELETE /projects/:id/members/:user_id" do
before { users_project }
before { users_project2 }
before { project_member }
before { project_member2 }
it "should remove user from project team" do
expect {
......
......@@ -8,8 +8,8 @@ describe API::API, api: true do
let(:admin) { create(:admin) }
let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) }
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(:users_project2) { create(:users_project, user: user3, project: project, project_access: ProjectMember::DEVELOPER) }
let(:project_member) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let(:project_member2) { create(:project_member, user: user3, project: project, project_access: ProjectMember::DEVELOPER) }
describe "GET /projects" do
before { project }
......@@ -254,7 +254,7 @@ describe API::API, api: true do
describe "GET /projects/:id" do
before { project }
before { users_project }
before { project_member }
it "should return a project by id" do
get api("/projects/#{project.id}", user)
......@@ -305,7 +305,7 @@ describe API::API, api: true do
end
describe "GET /projects/:id/events" do
before { users_project }
before { project_member }
it "should return a project events" do
get api("/projects/#{project.id}/events", user)
......
......@@ -8,8 +8,8 @@ describe API::API, api: true do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:users_project, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:users_project, user: user2, project: project, project_access: ProjectMember::GUEST) }
let!(:master) { create(:project_member, user: user, project: project, project_access: ProjectMember::MASTER) }
let!(:guest) { create(:project_member, user: user2, project: project, project_access: ProjectMember::GUEST) }
before { project.team << [user, :reporter] }
......
......@@ -3,7 +3,7 @@ require 'spec_helper'
describe SystemHooksService do
let (:user) { create :user }
let (:project) { create :project }
let (:users_project) { create :users_project }
let (:project_member) { create :project_member }
let (:key) { create(:key, user: user) }
context 'event data' 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(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(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(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, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :access_level, :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, :destroy).should include(:username, :key, :id) }
end
......@@ -22,8 +22,8 @@ describe SystemHooksService do
it { event_name(user, :destroy).should eq "user_destroy" }
it { event_name(project, :create).should eq "project_create" }
it { event_name(project, :destroy).should eq "project_destroy" }
it { event_name(users_project, :create).should eq "user_add_to_team" }
it { event_name(users_project, :destroy).should eq "user_remove_from_team" }
it { event_name(project_member, :create).should eq "user_add_to_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, :destroy).should eq 'key_destroy' }
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