diff options
-rw-r--r-- | app/models/board.rb | 1 | ||||
-rw-r--r-- | app/models/concerns/issuable.rb | 4 | ||||
-rw-r--r-- | app/models/event.rb | 1 | ||||
-rw-r--r-- | app/models/milestone.rb | 1 | ||||
-rw-r--r-- | app/models/note.rb | 1 | ||||
-rw-r--r-- | app/models/todo.rb | 1 | ||||
-rw-r--r-- | app/services/event_create_service.rb | 13 | ||||
-rw-r--r-- | db/migrate/20190826100605_add_group_column_to_events.rb | 9 | ||||
-rw-r--r-- | db/schema.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/safe_model_attributes.yml | 1 |
11 files changed, 33 insertions, 3 deletions
diff --git a/app/models/board.rb b/app/models/board.rb index 50b6ca9b70f..b5d07f1b282 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -19,6 +19,7 @@ class Board < ApplicationRecord def parent @parent ||= group || project end + alias_method :resource_parent, :parent def group_board? group_id.present? diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index eefe9f00836..a998d9b7e1b 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -277,6 +277,10 @@ module Issuable end end + def resource_parent + project + end + def milestone_available? project_id == milestone&.project_id || project.ancestors_upto.compact.include?(milestone&.group) end diff --git a/app/models/event.rb b/app/models/event.rb index 392d7368033..52d54be39a9 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -51,6 +51,7 @@ class Event < ApplicationRecord belongs_to :author, class_name: "User" belongs_to :project + belongs_to :group belongs_to :target, -> { # If the association for "target" defines an "author" association we want to diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 101e963ea29..cb87b46a31d 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -260,6 +260,7 @@ class Milestone < ApplicationRecord def parent group || project end + alias_method :resource_parent, :parent def group_milestone? group_id.present? diff --git a/app/models/note.rb b/app/models/note.rb index ebd13675dc9..0d024b0a25c 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -477,6 +477,7 @@ class Note < ApplicationRecord def parent project end + alias_method :resource_parent, :parent private diff --git a/app/models/todo.rb b/app/models/todo.rb index 1ec04189482..f7f30aed832 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -146,6 +146,7 @@ class Todo < ApplicationRecord def parent project end + alias_method :resource_parent, :parent def unmergeable? action == UNMERGEABLE diff --git a/app/services/event_create_service.rb b/app/services/event_create_service.rb index e7464fd9d5f..39266a6c961 100644 --- a/app/services/event_create_service.rb +++ b/app/services/event_create_service.rb @@ -95,16 +95,23 @@ class EventCreateService private def create_record_event(record, current_user, status) - create_event(record.project, current_user, status, target_id: record.id, target_type: record.class.name) + create_event(record.resource_parent, current_user, status, target_id: record.id, target_type: record.class.name) end - def create_event(project, current_user, status, attributes = {}) + def create_event(resource_parent, current_user, status, attributes = {}) attributes.reverse_merge!( - project: project, action: status, author_id: current_user.id ) + resource_parent_attr = case resource_parent + when Project + :project + when Group + :group + end + attributes[resource_parent_attr] = resource_parent if resource_parent_attr + Event.create!(attributes) end end diff --git a/db/migrate/20190826100605_add_group_column_to_events.rb b/db/migrate/20190826100605_add_group_column_to_events.rb new file mode 100644 index 00000000000..cd7b2b1d96a --- /dev/null +++ b/db/migrate/20190826100605_add_group_column_to_events.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddGroupColumnToEvents < ActiveRecord::Migration[5.2] + DOWNTIME = false + + def change + add_reference :events, :group, index: true, foreign_key: { to_table: :namespaces, on_delete: :cascade } + end +end diff --git a/db/schema.rb b/db/schema.rb index 0f535e4d674..f2d6f70217b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1310,9 +1310,11 @@ ActiveRecord::Schema.define(version: 2019_09_02_160015) do t.datetime_with_timezone "updated_at", null: false t.integer "action", limit: 2, null: false t.string "target_type" + t.bigint "group_id" t.index ["action"], name: "index_events_on_action" t.index ["author_id", "project_id"], name: "index_events_on_author_id_and_project_id" t.index ["created_at", "author_id"], name: "analytics_index_events_on_created_at_and_author_id" + t.index ["group_id"], name: "index_events_on_group_id" t.index ["project_id", "created_at"], name: "index_events_on_project_id_and_created_at" t.index ["project_id", "id"], name: "index_events_on_project_id_and_id" t.index ["target_type", "target_id"], name: "index_events_on_target_type_and_target_id" @@ -3838,6 +3840,7 @@ ActiveRecord::Schema.define(version: 2019_09_02_160015) do add_foreign_key "epics", "users", column: "assignee_id", name: "fk_dccd3f98fc", on_delete: :nullify add_foreign_key "epics", "users", column: "author_id", name: "fk_3654b61b03", on_delete: :cascade add_foreign_key "epics", "users", column: "closed_by_id", name: "fk_aa5798e761", on_delete: :nullify + add_foreign_key "events", "namespaces", column: "group_id", on_delete: :cascade add_foreign_key "events", "projects", on_delete: :cascade add_foreign_key "events", "users", column: "author_id", name: "fk_edfd187b6f", on_delete: :cascade add_foreign_key "fork_network_members", "fork_networks", on_delete: :cascade diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index c6aa4a2482c..47ba7eff8ed 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -26,6 +26,7 @@ issues: events: - author - project +- group - target - push_event_payload notes: diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index f0545176a90..516e62c4728 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -33,6 +33,7 @@ Event: - target_type - target_id - project_id +- group_id - created_at - updated_at - action |