Commit 6fa5916d authored by James Lopez's avatar James Lopez

Merge branch 'sso-dedicated-group-accounts-relations' into 'master'

Add dedicated group relation to user & group classes

See merge request gitlab-org/gitlab-ee!9663
parents 02c75cfd 1b1898aa
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190220150130) do
ActiveRecord::Schema.define(version: 20190222110418) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -3124,6 +3124,7 @@ ActiveRecord::Schema.define(version: 20190220150130) do
t.boolean "include_private_contributions"
t.string "commit_email"
t.integer "group_view"
t.integer "managing_group_id"
t.index ["accepted_term_id"], name: "index_users_on_accepted_term_id", using: :btree
t.index ["admin"], name: "index_users_on_admin", using: :btree
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
......@@ -3134,6 +3135,7 @@ ActiveRecord::Schema.define(version: 20190220150130) do
t.index ["ghost"], name: "index_users_on_ghost", using: :btree
t.index ["group_view"], name: "index_users_on_group_view", using: :btree
t.index ["incoming_email_token"], name: "index_users_on_incoming_email_token", using: :btree
t.index ["managing_group_id"], name: "index_users_on_managing_group_id", using: :btree
t.index ["name"], name: "index_users_on_name", using: :btree
t.index ["name"], name: "index_users_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"}
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
......@@ -3584,6 +3586,7 @@ ActiveRecord::Schema.define(version: 20190220150130) do
add_foreign_key "user_statuses", "users", on_delete: :cascade
add_foreign_key "user_synced_attributes_metadata", "users", on_delete: :cascade
add_foreign_key "users", "application_setting_terms", column: "accepted_term_id", name: "fk_789cd90b35", on_delete: :cascade
add_foreign_key "users", "namespaces", column: "managing_group_id", name: "fk_a4b8fefe3e", on_delete: :nullify
add_foreign_key "users_ops_dashboard_projects", "projects", on_delete: :cascade
add_foreign_key "users_ops_dashboard_projects", "users", on_delete: :cascade
add_foreign_key "users_star_projects", "projects", name: "fk_22cd27ddfc", on_delete: :cascade
......
......@@ -27,6 +27,8 @@ module EE
has_many :project_templates, through: :projects, foreign_key: 'custom_project_templates_group_id'
has_many :managed_users, class_name: 'User', foreign_key: 'managing_group_id', inverse_of: :managing_group
belongs_to :file_template_project, class_name: "Project"
# Use +checked_file_template_project+ instead, which implements important
......
......@@ -51,6 +51,8 @@ module EE
has_many :smartcard_identities
belongs_to :managing_group, class_name: 'Group', optional: true, inverse_of: :managed_users
scope :excluding_guests, -> { joins(:members).where('members.access_level > ?', ::Gitlab::Access::GUEST).distinct }
scope :subscribed_for_admin_email, -> { where(admin_email_unsubscribed_at: nil) }
......@@ -231,6 +233,10 @@ module EE
end
end
def group_managed_account?
managing_group.present?
end
override :ldap_sync_time
def ldap_sync_time
::Gitlab.config.ldap['sync_time']
......
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddUserManagingGroupRelation < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
add_column :users, :managing_group_id, :integer
end
end
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddUserManagingGroupRelationFk < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :users, :managing_group_id
add_concurrent_foreign_key :users, :namespaces, column: :managing_group_id, on_delete: :nullify
end
def down
remove_foreign_key :users, column: :managing_group_id
remove_concurrent_index :users, :managing_group_id
end
end
require 'spec_helper'
describe EE::User do
subject(:user) { User.new }
describe 'user creation' do
describe 'with defaults' do
let(:user) { User.new }
it "applies defaults to user" do
expect(user.group_view).to eq('details')
end
......@@ -378,4 +378,18 @@ describe EE::User do
end
end
end
describe '#group_managed_account?' do
context 'when user has managing group linked' do
before do
subject.managing_group = Group.new
end
it { is_expected.to be_group_managed_account }
end
context 'when user has no linked managing group' do
it { is_expected.not_to be_group_managed_account }
end
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