Commit 1aa48174 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix STI+polymorphic for Group <-> GroupMember

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 13af7de9
class GroupMembersController < ApplicationController
class Groups::GroupMembersController < ApplicationController
before_filter :group
# Authorize
......@@ -43,6 +43,6 @@ class GroupMembersController < ApplicationController
end
def member_params
params.require(:users_group).permit(:access_level, :user_id)
params.require(:group_member).permit(:access_level, :user_id)
end
end
......@@ -69,6 +69,6 @@ class Projects::TeamMembersController < Projects::ApplicationController
end
def member_params
params.require(:team_member).permit(:user_id, :access_level)
params.require(:project_member).permit(:user_id, :access_level)
end
end
class GroupMember < Member
SOURCE_TYPE = 'Group'
SOURCE_TYPE = 'Namespace'
belongs_to :group, class_name: 'Group', foreign_key: 'source_id'
# Make sure group member points only to group as it source
default_value_for :source_type, SOURCE_TYPE
validates_format_of :source_type, with: /\AGroup\z/
default_value_for :notification_level, Notification::N_GLOBAL
validates_format_of :source_type, with: /\ANamespace\z/
default_scope { where(source_type: SOURCE_TYPE) }
scope :with_group, ->(group) { where(source_id: group.id) }
......
......@@ -5,8 +5,10 @@ class ProjectMember < Member
belongs_to :project, class_name: 'Project', foreign_key: 'source_id'
# Make sure project member points only to project as it source
default_value_for :source_type, SOURCE_TYPE
default_value_for :notification_level, Notification::N_GLOBAL
validates_format_of :source_type, with: /\AProject\z/
default_scope { where(source_type: SOURCE_TYPE) }
......
......@@ -21,7 +21,7 @@
= link_to leave_profile_group_path(@group), data: { confirm: leave_group_message(@group.name)}, method: :delete, class: "btn-tiny btn btn-remove", title: 'Remove user from group' do
%i.icon-minus.icon-white
- else
= 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_member_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
.edit-member.hide.js-toggle-content
......
......@@ -32,7 +32,7 @@
(#{@members.total_count})
%ul.well-list
- @members.each do |member|
= render 'group_members/users_group', member: member, show_roles: show_roles, show_controls: true
= render 'groups/group_members/group_member', member: member, show_roles: show_roles, show_controls: true
= paginate @members, theme: 'gitlab'
:coffeescript
......
......@@ -161,9 +161,8 @@ Gitlab::Application.routes.draw do
get :projects
end
resources :users_groups, only: [:create, :update, :destroy]
scope module: :groups do
resources :group_members, only: [:create, :update, :destroy]
resource :avatar, only: [:destroy]
resources :milestones
end
......
class MigrateToNewMembersModel < ActiveRecord::Migration
def up
execute "INSERT INTO members ( user_id, source_id, source_type, access_level, notification_level, type ) SELECT user_id, group_id, 'Group', group_access, notification_level, 'GroupMember' FROM users_groups"
execute "INSERT INTO members ( user_id, source_id, source_type, access_level, notification_level, type ) SELECT user_id, group_id, 'Namespace', group_access, notification_level, 'GroupMember' FROM users_groups"
execute "INSERT INTO members ( user_id, source_id, source_type, access_level, notification_level, type ) SELECT user_id, project_id, 'Project', project_access, notification_level, 'ProjectMember' FROM users_projects"
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