summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2019-06-17 15:22:44 -0300
committerFelipe Artur <felipefac@gmail.com>2019-06-17 15:22:44 -0300
commitd9df2f730b4eaab4e2d1b5f5045e34bb14e3486f (patch)
tree050490a4e90601ad4d175ba6674b98f35937587e /app/models
parent66b9ca952aa4104f99c1275566e8b5c7d28fce01 (diff)
parentd2929d6edb3a04054a5218cb1b21cb0759ec1ec8 (diff)
downloadgitlab-ce-issue_60515.tar.gz
Merge branch 'master' into issue_60515issue_60515
Diffstat (limited to 'app/models')
-rw-r--r--app/models/commit.rb2
-rw-r--r--app/models/concerns/diff_positionable_note.rb9
-rw-r--r--app/models/discussion.rb8
-rw-r--r--app/models/group.rb2
-rw-r--r--app/models/lfs_object.rb2
-rw-r--r--app/models/lfs_objects_project.rb8
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--app/models/note.rb2
-rw-r--r--app/models/notification_recipient.rb5
-rw-r--r--app/models/project.rb20
-rw-r--r--app/models/project_feature.rb2
-rw-r--r--app/models/project_services/data_fields.rb10
-rw-r--r--app/models/project_services/issue_tracker_data.rb25
-rw-r--r--app/models/project_services/jira_tracker_data.rb30
-rw-r--r--app/models/service.rb1
-rw-r--r--app/models/user_callout_enums.rb6
16 files changed, 112 insertions, 22 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index fa0bf36ba49..be37fa2e76f 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -94,7 +94,7 @@ class Commit
end
def lazy(project, oid)
- BatchLoader.for({ project: project, oid: oid }).batch do |items, loader|
+ BatchLoader.for({ project: project, oid: oid }).batch(replace_methods: false) do |items, loader|
items_by_project = items.group_by { |i| i[:project] }
items_by_project.each do |project, commit_ids|
diff --git a/app/models/concerns/diff_positionable_note.rb b/app/models/concerns/diff_positionable_note.rb
index b61bf29e6ad..2d09eff0111 100644
--- a/app/models/concerns/diff_positionable_note.rb
+++ b/app/models/concerns/diff_positionable_note.rb
@@ -3,6 +3,7 @@ module DiffPositionableNote
extend ActiveSupport::Concern
included do
+ delegate :on_text?, :on_image?, to: :position, allow_nil: true
before_validation :set_original_position, on: :create
before_validation :update_position, on: :create, if: :on_text?
@@ -28,14 +29,6 @@ module DiffPositionableNote
end
end
- def on_text?
- position&.position_type == "text"
- end
-
- def on_image?
- position&.position_type == "image"
- end
-
def supported?
for_commit? || self.noteable.has_complete_diff_refs?
end
diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index 32529ebf71d..ae13cdfd85f 100644
--- a/app/models/discussion.rb
+++ b/app/models/discussion.rb
@@ -4,6 +4,7 @@
#
# A discussion of this type can be resolvable.
class Discussion
+ include GlobalID::Identification
include ResolvableDiscussion
attr_reader :notes, :context_noteable
@@ -11,14 +12,19 @@ class Discussion
delegate :created_at,
:project,
:author,
-
:noteable,
:commit_id,
:for_commit?,
:for_merge_request?,
+ :to_ability_name,
+ :editable?,
to: :first_note
+ def declarative_policy_delegate
+ first_note
+ end
+
def project_id
project&.id
end
diff --git a/app/models/group.rb b/app/models/group.rb
index cdb4e6e87f6..dbec211935d 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -423,7 +423,7 @@ class Group < Namespace
def update_two_factor_requirement
return unless saved_change_to_require_two_factor_authentication? || saved_change_to_two_factor_grace_period?
- users.find_each(&:update_two_factor_requirement)
+ members_with_descendants.find_each(&:update_two_factor_requirement)
end
def path_changed_hook
diff --git a/app/models/lfs_object.rb b/app/models/lfs_object.rb
index 5245dbc8d15..79a376ff0fd 100644
--- a/app/models/lfs_object.rb
+++ b/app/models/lfs_object.rb
@@ -5,7 +5,7 @@ class LfsObject < ApplicationRecord
include ObjectStorage::BackgroundMove
has_many :lfs_objects_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
- has_many :projects, through: :lfs_objects_projects
+ has_many :projects, -> { distinct }, through: :lfs_objects_projects
scope :with_files_stored_locally, -> { where(file_store: LfsObjectUploader::Store::LOCAL) }
diff --git a/app/models/lfs_objects_project.rb b/app/models/lfs_objects_project.rb
index f9afb18c1d7..e45c56b6394 100644
--- a/app/models/lfs_objects_project.rb
+++ b/app/models/lfs_objects_project.rb
@@ -5,11 +5,17 @@ class LfsObjectsProject < ApplicationRecord
belongs_to :lfs_object
validates :lfs_object_id, presence: true
- validates :lfs_object_id, uniqueness: { scope: [:project_id], message: "already exists in project" }
+ validates :lfs_object_id, uniqueness: { scope: [:project_id, :repository_type], message: "already exists in repository" }
validates :project_id, presence: true
after_commit :update_project_statistics, on: [:create, :destroy]
+ enum repository_type: {
+ project: 0,
+ wiki: 1,
+ design: 2 ## EE-specific
+ }
+
private
def update_project_statistics
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 7481f1939ad..f07636e8f77 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -668,7 +668,7 @@ class MergeRequest < ApplicationRecord
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37435
Gitlab::GitalyClient.allow_n_plus_1_calls do
- merge_request_diffs.create
+ merge_request_diffs.create!
reload_merge_request_diff
end
end
diff --git a/app/models/note.rb b/app/models/note.rb
index 081d6f91230..15271c68a9e 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -342,7 +342,7 @@ class Note < ApplicationRecord
end
def to_ability_name
- for_snippet? ? noteable.class.name.underscore : noteable_type.underscore
+ for_snippet? ? noteable.class.name.underscore : noteable_type.demodulize.underscore
end
def can_be_discussion_note?
diff --git a/app/models/notification_recipient.rb b/app/models/notification_recipient.rb
index 9b2bbb7eba5..a7f73c0f29c 100644
--- a/app/models/notification_recipient.rb
+++ b/app/models/notification_recipient.rb
@@ -101,6 +101,7 @@ class NotificationRecipient
end
def excluded_watcher_action?
+ return false unless @type == :watch
return false unless @custom_action
NotificationSetting::EXCLUDED_WATCHER_EVENTS.include?(@custom_action)
@@ -140,7 +141,7 @@ class NotificationRecipient
return project_setting unless project_setting.nil? || project_setting.global?
- group_setting = closest_non_global_group_notification_settting
+ group_setting = closest_non_global_group_notification_setting
return group_setting unless group_setting.nil?
@@ -148,7 +149,7 @@ class NotificationRecipient
end
# Returns the notification_setting of the lowest group in hierarchy with non global level
- def closest_non_global_group_notification_settting
+ def closest_non_global_group_notification_setting
return unless @group
@group
diff --git a/app/models/project.rb b/app/models/project.rb
index 9d17d68eee2..351d08eaf63 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -72,7 +72,6 @@ class Project < ApplicationRecord
delegate :no_import?, to: :import_state, allow_nil: true
default_value_for :archived, false
- default_value_for(:visibility_level) { Gitlab::CurrentSettings.default_project_visibility }
default_value_for :resolve_outdated_diff_discussions, false
default_value_for :container_registry_enabled, gitlab_config_features.container_registry
default_value_for(:repository_storage) { Gitlab::CurrentSettings.pick_repository_storage }
@@ -223,7 +222,7 @@ class Project < ApplicationRecord
has_many :starrers, through: :users_star_projects, source: :user
has_many :releases
has_many :lfs_objects_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
- has_many :lfs_objects, through: :lfs_objects_projects
+ has_many :lfs_objects, -> { distinct }, through: :lfs_objects_projects
has_many :lfs_file_locks
has_many :project_group_links
has_many :invited_groups, through: :project_group_links, source: :group
@@ -613,6 +612,23 @@ class Project < ApplicationRecord
end
end
+ def initialize(attributes = {})
+ # We can't use default_value_for because the database has a default
+ # value of 0 for visibility_level. If someone attempts to create a
+ # private project, default_value_for will assume that the
+ # visibility_level hasn't changed and will use the application
+ # setting default, which could be internal or public. For projects
+ # inside a private group, those levels are invalid.
+ #
+ # To fix the problem, we assign the actual default in the application if
+ # no explicit visibility has been initialized.
+ unless visibility_attribute_present?(attributes)
+ attributes[:visibility_level] = Gitlab::CurrentSettings.default_project_visibility
+ end
+
+ super
+ end
+
def all_pipelines
if builds_enabled?
super
diff --git a/app/models/project_feature.rb b/app/models/project_feature.rb
index 6bcb051bff6..0542581c6e0 100644
--- a/app/models/project_feature.rb
+++ b/app/models/project_feature.rb
@@ -72,8 +72,6 @@ class ProjectFeature < ApplicationRecord
default_value_for :wiki_access_level, value: ENABLED, allows_nil: false
default_value_for :repository_access_level, value: ENABLED, allows_nil: false
- scope :for_project_id, -> (project) { where(project: project) }
-
def feature_available?(feature, user)
# This feature might not be behind a feature flag at all, so default to true
return false unless ::Feature.enabled?(feature, user, default_enabled: true)
diff --git a/app/models/project_services/data_fields.rb b/app/models/project_services/data_fields.rb
new file mode 100644
index 00000000000..438d85098c8
--- /dev/null
+++ b/app/models/project_services/data_fields.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+module DataFields
+ extend ActiveSupport::Concern
+
+ included do
+ has_one :issue_tracker_data
+ has_one :jira_tracker_data
+ end
+end
diff --git a/app/models/project_services/issue_tracker_data.rb b/app/models/project_services/issue_tracker_data.rb
new file mode 100644
index 00000000000..2c1d28ed421
--- /dev/null
+++ b/app/models/project_services/issue_tracker_data.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+class IssueTrackerData < ApplicationRecord
+ belongs_to :service
+
+ delegate :activated?, to: :service, allow_nil: true
+
+ validates :service, presence: true
+ validates :project_url, presence: true, public_url: { enforce_sanitization: true }, if: :activated?
+ validates :issues_url, presence: true, public_url: { enforce_sanitization: true }, if: :activated?
+ validates :new_issue_url, public_url: { enforce_sanitization: true }, if: :activated?
+
+ def self.encryption_options
+ {
+ key: Settings.attr_encrypted_db_key_base_32,
+ encode: true,
+ mode: :per_attribute_iv,
+ algorithm: 'aes-256-gcm'
+ }
+ end
+
+ attr_encrypted :project_url, encryption_options
+ attr_encrypted :issues_url, encryption_options
+ attr_encrypted :new_issue_url, encryption_options
+end
diff --git a/app/models/project_services/jira_tracker_data.rb b/app/models/project_services/jira_tracker_data.rb
new file mode 100644
index 00000000000..4f528e3d81b
--- /dev/null
+++ b/app/models/project_services/jira_tracker_data.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+class JiraTrackerData < ApplicationRecord
+ belongs_to :service
+
+ delegate :activated?, to: :service, allow_nil: true
+
+ validates :service, presence: true
+ validates :url, public_url: { enforce_sanitization: true }, presence: true, if: :activated?
+ validates :api_url, public_url: { enforce_sanitization: true }, allow_blank: true
+ validates :username, presence: true, if: :activated?
+ validates :password, presence: true, if: :activated?
+ validates :jira_issue_transition_id,
+ format: { with: Gitlab::Regex.jira_transition_id_regex, message: s_("JiraService|transition ids can have only numbers which can be split with , or ;") },
+ allow_blank: true
+
+ def self.encryption_options
+ {
+ key: Settings.attr_encrypted_db_key_base_32,
+ encode: true,
+ mode: :per_attribute_iv,
+ algorithm: 'aes-256-gcm'
+ }
+ end
+
+ attr_encrypted :url, encryption_options
+ attr_encrypted :api_url, encryption_options
+ attr_encrypted :username, encryption_options
+ attr_encrypted :password, encryption_options
+end
diff --git a/app/models/service.rb b/app/models/service.rb
index 9896aa12e90..16fbe6648cc 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -6,6 +6,7 @@ class Service < ApplicationRecord
include Sortable
include Importable
include ProjectServicesLoggable
+ include DataFields
serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize
diff --git a/app/models/user_callout_enums.rb b/app/models/user_callout_enums.rb
index b9373ae6166..7b68e5076c7 100644
--- a/app/models/user_callout_enums.rb
+++ b/app/models/user_callout_enums.rb
@@ -6,11 +6,15 @@ module UserCalloutEnums
#
# This method is separate from the `UserCallout` model so that it can be
# extended by EE.
+ #
+ # If you are going to add new items to this hash, check that you're not going
+ # to conflict with EE-only values: https://gitlab.com/gitlab-org/gitlab-ee/blob/master/ee/app/models/ee/user_callout_enums.rb
def self.feature_names
{
gke_cluster_integration: 1,
gcp_signup_offer: 2,
- cluster_security_warning: 3
+ cluster_security_warning: 3,
+ suggest_popover_dismissed: 9
}
end
end