Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/user_preference.rb')
-rw-r--r--app/models/user_preference.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 59cfe9a8426..70ffe0c85f8 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -10,6 +10,7 @@ class UserPreference < MainClusterwide::ApplicationRecord
TIME_DISPLAY_FORMATS = { system: 0, non_iso_format: 1, iso_format: 2 }.freeze
belongs_to :user
+ belongs_to :home_organization, class_name: "Organizations::Organization", optional: true
scope :with_user, -> { joins(:user) }
scope :gitpod_enabled, -> { where(gitpod_enabled: true) }
@@ -30,7 +31,8 @@ class UserPreference < MainClusterwide::ApplicationRecord
validates :time_display_format, inclusion: { in: TIME_DISPLAY_FORMATS.values }, presence: true
- ignore_columns :experience_level, remove_with: '14.10', remove_after: '2021-03-22'
+ validate :user_belongs_to_home_organization, if: :home_organization_changed?
+
# 2023-06-22 is after 16.1 release and during 16.2 release https://docs.gitlab.com/ee/development/database/avoiding_downtime_in_migrations.html#ignoring-the-column-release-m
ignore_columns :use_legacy_web_ide, remove_with: '16.2', remove_after: '2023-06-22'
@@ -40,6 +42,7 @@ class UserPreference < MainClusterwide::ApplicationRecord
attribute :render_whitespace_in_code, default: false
attribute :project_shortcut_buttons, default: true
attribute :keyboard_shortcuts_enabled, default: true
+ attribute :use_web_ide_extension_marketplace, default: false
enum visibility_pipeline_id_type: { id: 0, iid: 1 }
@@ -53,6 +56,16 @@ class UserPreference < MainClusterwide::ApplicationRecord
end
end
+ def user_belongs_to_home_organization
+ # If we don't ignore the default organization id below then all users need to have their corresponding entry
+ # with default organization id as organization id in the `organization_users` table.
+ # Otherwise, the user won't be able to the default organization as the home organization.
+ return if home_organization_id == Organizations::Organization::DEFAULT_ORGANIZATION_ID
+ return if user.user_belongs_to_organization?(home_organization_id)
+
+ errors.add(:user, _("is not part of the given organization"))
+ end
+
def set_notes_filter(filter_id, issuable)
# No need to update the column if the value is already set.
if filter_id && NOTES_FILTERS.value?(filter_id)