diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-09-07 18:03:20 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-09-07 18:03:20 +0200 |
commit | 12ddc28f844fe63446a16ac908b09ed7b13c71ef (patch) | |
tree | 149ef1a7e2b32e6fa8c4462394daf942b7452440 /app/models | |
parent | 62a5cc7134457d21bf3a68bfdb04e090cf0e6ecf (diff) | |
parent | f2421b2b97d81ef7631f1baefb4ba4401c8a04dc (diff) | |
download | gitlab-ce-12ddc28f844fe63446a16ac908b09ed7b13c71ef.tar.gz |
Merge remote-tracking branch 'origin/master' into zj/gitlab-ce-zj-auto-devops-table
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/board.rb | 14 | ||||
-rw-r--r-- | app/models/concerns/relative_positioning.rb | 14 | ||||
-rw-r--r-- | app/models/event.rb | 102 | ||||
-rw-r--r-- | app/models/event_for_migration.rb | 5 | ||||
-rw-r--r-- | app/models/label.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 8 | ||||
-rw-r--r-- | app/models/push_event.rb | 77 | ||||
-rw-r--r-- | app/models/user.rb | 1 |
8 files changed, 56 insertions, 169 deletions
diff --git a/app/models/board.rb b/app/models/board.rb index 97d0f550925..5bb7d3d3722 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -3,7 +3,19 @@ class Board < ActiveRecord::Base has_many :lists, -> { order(:list_type, :position) }, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent - validates :project, presence: true + validates :project, presence: true, if: :project_needed? + + def project_needed? + true + end + + def parent + project + end + + def group_board? + false + end def backlog_list lists.merge(List.backlog).take diff --git a/app/models/concerns/relative_positioning.rb b/app/models/concerns/relative_positioning.rb index 7cb9a28a284..e961c97e337 100644 --- a/app/models/concerns/relative_positioning.rb +++ b/app/models/concerns/relative_positioning.rb @@ -10,8 +10,12 @@ module RelativePositioning after_save :save_positionable_neighbours end + def project_ids + [project.id] + end + def max_relative_position - self.class.in_projects(project.id).maximum(:relative_position) + self.class.in_projects(project_ids).maximum(:relative_position) end def prev_relative_position @@ -19,7 +23,7 @@ module RelativePositioning if self.relative_position prev_pos = self.class - .in_projects(project.id) + .in_projects(project_ids) .where('relative_position < ?', self.relative_position) .maximum(:relative_position) end @@ -32,7 +36,7 @@ module RelativePositioning if self.relative_position next_pos = self.class - .in_projects(project.id) + .in_projects(project_ids) .where('relative_position > ?', self.relative_position) .minimum(:relative_position) end @@ -59,7 +63,7 @@ module RelativePositioning pos_after = before.next_relative_position if before.shift_after? - issue_to_move = self.class.in_projects(project.id).find_by!(relative_position: pos_after) + issue_to_move = self.class.in_projects(project_ids).find_by!(relative_position: pos_after) issue_to_move.move_after @positionable_neighbours = [issue_to_move] @@ -74,7 +78,7 @@ module RelativePositioning pos_before = after.prev_relative_position if after.shift_before? - issue_to_move = self.class.in_projects(project.id).find_by!(relative_position: pos_before) + issue_to_move = self.class.in_projects(project_ids).find_by!(relative_position: pos_before) issue_to_move.move_before @positionable_neighbours = [issue_to_move] diff --git a/app/models/event.rb b/app/models/event.rb index 996768a267b..c313bbb66f8 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,5 +1,6 @@ class Event < ActiveRecord::Base include Sortable + include IgnorableColumn default_scope { reorder(nil).where.not(author_id: nil) } CREATED = 1 @@ -50,13 +51,9 @@ class Event < ActiveRecord::Base belongs_to :target, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations has_one :push_event_payload, foreign_key: :event_id - # For Hash only - serialize :data # rubocop:disable Cop/ActiveRecordSerialize - # Callbacks after_create :reset_project_activity after_create :set_last_repository_updated_at, if: :push? - after_create :replicate_event_for_push_events_migration # Scopes scope :recent, -> { reorder(id: :desc) } @@ -82,6 +79,10 @@ class Event < ActiveRecord::Base self.inheritance_column = 'action' + # "data" will be removed in 10.0 but it may be possible that JOINs happen that + # include this column, hence we're ignoring it as well. + ignore_column :data + class << self def model_name ActiveModel::Name.new(self, nil, 'event') @@ -159,7 +160,7 @@ class Event < ActiveRecord::Base end def push? - action == PUSHED && valid_push? + false end def merged? @@ -272,87 +273,6 @@ class Event < ActiveRecord::Base end end - def valid_push? - data[:ref] && ref_name.present? - rescue - false - end - - def tag? - Gitlab::Git.tag_ref?(data[:ref]) - end - - def branch? - Gitlab::Git.branch_ref?(data[:ref]) - end - - def new_ref? - Gitlab::Git.blank_ref?(commit_from) - end - - def rm_ref? - Gitlab::Git.blank_ref?(commit_to) - end - - def md_ref? - !(rm_ref? || new_ref?) - end - - def commit_from - data[:before] - end - - def commit_to - data[:after] - end - - def ref_name - if tag? - tag_name - else - branch_name - end - end - - def branch_name - @branch_name ||= Gitlab::Git.ref_name(data[:ref]) - end - - def tag_name - @tag_name ||= Gitlab::Git.ref_name(data[:ref]) - end - - # Max 20 commits from push DESC - def commits - @commits ||= (data[:commits] || []).reverse - end - - def commit_title - commit = commits.last - - commit[:message] if commit - end - - def commit_id - commit_to || commit_from - end - - def commits_count - data[:total_commits_count] || commits.count || 0 - end - - def ref_type - tag? ? "tag" : "branch" - end - - def push_with_commits? - !commits.empty? && commit_from && commit_to - end - - def last_push_to_non_root? - branch? && project.default_branch != branch_name - end - def target_iid target.respond_to?(:iid) ? target.iid : target_id end @@ -432,16 +352,6 @@ class Event < ActiveRecord::Base user ? author_id == user.id : false end - # We're manually replicating data into the new table since database triggers - # are not dumped to db/schema.rb. This could mean that a new installation - # would not have the triggers in place, thus losing events data in GitLab - # 10.0. - def replicate_event_for_push_events_migration - new_attributes = attributes.with_indifferent_access.except(:title, :data) - - EventForMigration.create!(new_attributes) - end - def to_partial_path # We are intentionally using `Event` rather than `self.class` so that # subclasses also use the `Event` implementation. diff --git a/app/models/event_for_migration.rb b/app/models/event_for_migration.rb deleted file mode 100644 index a1672da5eec..00000000000 --- a/app/models/event_for_migration.rb +++ /dev/null @@ -1,5 +0,0 @@ -# This model is used to replicate events between the old "events" table and the -# new "events_for_migration" table that will replace "events" in GitLab 10.0. -class EventForMigration < ActiveRecord::Base - self.table_name = 'events_for_migration' -end diff --git a/app/models/label.rb b/app/models/label.rb index 674bb3f2720..958141a7358 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -34,7 +34,8 @@ class Label < ActiveRecord::Base scope :templates, -> { where(template: true) } scope :with_title, ->(title) { where(title: title) } - scope :on_project_boards, ->(project_id) { joins(lists: :board).merge(List.movable).where(boards: { project_id: project_id }) } + scope :with_lists_and_board, -> { joins(lists: :board).merge(List.movable) } + scope :on_project_boards, ->(project_id) { with_lists_and_board.where(boards: { project_id: project_id }) } def self.prioritized(project) joins(:priorities) @@ -172,6 +173,7 @@ class Label < ActiveRecord::Base def as_json(options = {}) super(options).tap do |json| + json[:type] = self.try(:type) json[:priority] = priority(options[:project]) if options.key?(:project) end end diff --git a/app/models/project.rb b/app/models/project.rb index b52b1e9049b..039dacf1945 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1507,6 +1507,14 @@ class Project < ActiveRecord::Base end end + def multiple_issue_boards_available?(user) + feature_available?(:multiple_issue_boards, user) + end + + def issue_board_milestone_available?(user = nil) + feature_available?(:issue_board_milestone, user) + end + def full_path_was File.join(namespace.full_path, previous_changes['path'].first) end diff --git a/app/models/push_event.rb b/app/models/push_event.rb index 3f1ff979de6..23ffb0d4ea8 100644 --- a/app/models/push_event.rb +++ b/app/models/push_event.rb @@ -15,15 +15,21 @@ class PushEvent < Event # should ensure the ID points to a valid project. validates :project_id, presence: true - # The "data" field must not be set for push events since it's not used and a - # waste of space. - validates :data, absence: true - # These fields are also not used for push events, thus storing them would be a # waste. validates :target_id, absence: true validates :target_type, absence: true + delegate :branch?, to: :push_event_payload + delegate :tag?, to: :push_event_payload + delegate :commit_from, to: :push_event_payload + delegate :commit_to, to: :push_event_payload + delegate :ref_type, to: :push_event_payload + delegate :commit_title, to: :push_event_payload + + delegate :commit_count, to: :push_event_payload + alias_method :commits_count, :commit_count + def self.sti_name PUSHED end @@ -36,86 +42,35 @@ class PushEvent < Event !!(commit_from && commit_to) end - def tag? - return super unless push_event_payload - - push_event_payload.tag? - end - - def branch? - return super unless push_event_payload - - push_event_payload.branch? - end - def valid_push? - return super unless push_event_payload - push_event_payload.ref.present? end def new_ref? - return super unless push_event_payload - push_event_payload.created? end def rm_ref? - return super unless push_event_payload - push_event_payload.removed? end - def commit_from - return super unless push_event_payload - - push_event_payload.commit_from - end - - def commit_to - return super unless push_event_payload - - push_event_payload.commit_to + def md_ref? + !(rm_ref? || new_ref?) end def ref_name - return super unless push_event_payload - push_event_payload.ref end - def ref_type - return super unless push_event_payload - - push_event_payload.ref_type - end - - def branch_name - return super unless push_event_payload - - ref_name - end - - def tag_name - return super unless push_event_payload - - ref_name - end - - def commit_title - return super unless push_event_payload - - push_event_payload.commit_title - end + alias_method :branch_name, :ref_name + alias_method :tag_name, :ref_name def commit_id commit_to || commit_from end - def commits_count - return super unless push_event_payload - - push_event_payload.commit_count + def last_push_to_non_root? + branch? && project.default_branch != branch_name end def validate_push_action diff --git a/app/models/user.rb b/app/models/user.rb index 105eb62f1fa..f75cc21c65c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,6 +35,7 @@ class User < ActiveRecord::Base default_value_for :project_view, :files default_value_for :notified_of_own_activity, false default_value_for :preferred_language, I18n.default_locale + default_value_for :theme_id, gitlab_config.default_theme attr_encrypted :otp_secret, key: Gitlab::Application.secrets.otp_key_base, |