Commit ea37fafd authored by Steve Abrams's avatar Steve Abrams

Merge branch '2256-add-namespace-crm-settings' into 'master'

Add group crm settings

See merge request gitlab-org/gitlab!76983
parents f515ab01 083c1f8f
......@@ -92,6 +92,8 @@ class Group < Namespace
delegate :prevent_sharing_groups_outside_hierarchy, :new_user_signups_cap, :setup_for_company, :jobs_to_be_done, to: :namespace_settings
has_one :crm_settings, class_name: 'Group::CrmSettings', inverse_of: :group
accepts_nested_attributes_for :variables, allow_destroy: true
validate :visibility_level_allowed_by_projects
......@@ -764,6 +766,10 @@ class Group < Namespace
super || build_dependency_proxy_image_ttl_policy
end
def crm_enabled?
crm_settings&.enabled?
end
private
def max_member_access(user_ids)
......
# frozen_string_literal: true
class Group::CrmSettings < ApplicationRecord
self.primary_key = :group_id
self.table_name = 'group_crm_settings'
belongs_to :group, -> { where(type: Group.sti_name) }, foreign_key: 'group_id'
validates :group, presence: true
end
# frozen_string_literal: true
class AddGroupCrmSettings < Gitlab::Database::Migration[1.0]
enable_lock_retries!
def change
create_table :group_crm_settings, id: false do |t|
t.references :group, primary_key: true, foreign_key: { to_table: :namespaces, on_delete: :cascade }
t.timestamps_with_timezone
t.boolean :enabled, null: false, default: false
end
end
end
649cf0eb794904457b230c1240d2bea8a6e80b00dbf6b2d25b95c66247460aa4
\ No newline at end of file
......@@ -14713,6 +14713,22 @@ CREATE SEQUENCE grafana_integrations_id_seq
ALTER SEQUENCE grafana_integrations_id_seq OWNED BY grafana_integrations.id;
CREATE TABLE group_crm_settings (
group_id bigint NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
enabled boolean DEFAULT false NOT NULL
);
CREATE SEQUENCE group_crm_settings_group_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE group_crm_settings_group_id_seq OWNED BY group_crm_settings.group_id;
CREATE TABLE group_custom_attributes (
id integer NOT NULL,
created_at timestamp with time zone NOT NULL,
......@@ -21635,6 +21651,8 @@ ALTER TABLE ONLY gpg_signatures ALTER COLUMN id SET DEFAULT nextval('gpg_signatu
ALTER TABLE ONLY grafana_integrations ALTER COLUMN id SET DEFAULT nextval('grafana_integrations_id_seq'::regclass);
ALTER TABLE ONLY group_crm_settings ALTER COLUMN group_id SET DEFAULT nextval('group_crm_settings_group_id_seq'::regclass);
ALTER TABLE ONLY group_custom_attributes ALTER COLUMN id SET DEFAULT nextval('group_custom_attributes_id_seq'::regclass);
ALTER TABLE ONLY group_deploy_keys ALTER COLUMN id SET DEFAULT nextval('group_deploy_keys_id_seq'::regclass);
......@@ -23271,6 +23289,9 @@ ALTER TABLE ONLY gpg_signatures
ALTER TABLE ONLY grafana_integrations
ADD CONSTRAINT grafana_integrations_pkey PRIMARY KEY (id);
ALTER TABLE ONLY group_crm_settings
ADD CONSTRAINT group_crm_settings_pkey PRIMARY KEY (group_id);
ALTER TABLE ONLY group_custom_attributes
ADD CONSTRAINT group_custom_attributes_pkey PRIMARY KEY (id);
......@@ -26159,6 +26180,8 @@ CREATE INDEX index_grafana_integrations_on_enabled ON grafana_integrations USING
CREATE INDEX index_grafana_integrations_on_project_id ON grafana_integrations USING btree (project_id);
CREATE INDEX index_group_crm_settings_on_group_id ON group_crm_settings USING btree (group_id);
CREATE UNIQUE INDEX index_group_custom_attributes_on_group_id_and_key ON group_custom_attributes USING btree (group_id, key);
CREATE INDEX index_group_custom_attributes_on_key_and_value ON group_custom_attributes USING btree (key, value);
......@@ -30613,6 +30636,9 @@ ALTER TABLE ONLY dast_site_profiles
ALTER TABLE ONLY merge_request_context_commit_diff_files
ADD CONSTRAINT fk_rails_74a00a1787 FOREIGN KEY (merge_request_context_commit_id) REFERENCES merge_request_context_commits(id) ON DELETE CASCADE;
ALTER TABLE ONLY group_crm_settings
ADD CONSTRAINT fk_rails_74fdf2f13d FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY clusters_applications_ingress
ADD CONSTRAINT fk_rails_753a7b41c1 FOREIGN KEY (cluster_id) REFERENCES clusters(id) ON DELETE CASCADE;
......@@ -231,6 +231,7 @@ gpg_key_subkeys: :gitlab_main
gpg_signatures: :gitlab_main
grafana_integrations: :gitlab_main
group_custom_attributes: :gitlab_main
group_crm_settings: :gitlab_main
group_deletion_schedules: :gitlab_main
group_deploy_keys: :gitlab_main
group_deploy_keys_groups: :gitlab_main
......
# frozen_string_literal: true
FactoryBot.define do
factory :crm_settings, class: 'Group::CrmSettings' do
group
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Group::CrmSettings do
describe 'associations' do
it { is_expected.to belong_to(:group) }
end
describe 'validations' do
subject { build(:crm_settings) }
it { is_expected.to validate_presence_of(:group) }
end
end
......@@ -39,6 +39,7 @@ RSpec.describe Group do
it { is_expected.to have_many(:bulk_import_exports).class_name('BulkImports::Export') }
it { is_expected.to have_many(:contacts).class_name('CustomerRelations::Contact') }
it { is_expected.to have_many(:organizations).class_name('CustomerRelations::Organization') }
it { is_expected.to have_one(:crm_settings) }
describe '#members & #requesters' do
let(:requester) { create(:user) }
......@@ -2784,4 +2785,22 @@ RSpec.describe Group do
end
end
end
describe '#crm_enabled?' do
it 'returns false where no crm_settings exist' do
expect(group.crm_enabled?).to be_falsey
end
it 'returns false where crm_settings.state is disabled' do
create(:crm_settings, enabled: false, group: group)
expect(group.crm_enabled?).to be_falsey
end
it 'returns true where crm_settings.state is enabled' do
create(:crm_settings, enabled: true, group: group)
expect(group.crm_enabled?).to be_truthy
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