Skip to content
代码片段 群组 项目
未验证 提交 ce6593ac 编辑于 作者: Piotr Skorupa's avatar Piotr Skorupa 提交者: GitLab
浏览文件

Add notes to WikiPage::Meta for all wikis

- Adds Wikis::UserMention model and a new table
- Adds notes support for both project- and group-level wikis by making
  WikiPage::Meta a noteable
- Includes a namespace_id attribute in user mentions copied from the
  note as a sharding key for Cells purposes
上级 42c8aa9a
No related branches found
No related tags found
无相关合并请求
显示
203 个添加8 个删除
...@@ -76,6 +76,10 @@ def release_url(entity, *args) ...@@ -76,6 +76,10 @@ def release_url(entity, *args)
project_release_url(entity.project, entity, *args) project_release_url(entity.project, entity, *args)
end end
def project_wiki_page_url(entity, *args)
project_wiki_url(entity.project, entity.canonical_slug, *args)
end
def edit_milestone_path(entity, *args) def edit_milestone_path(entity, *args)
if entity.resource_parent.is_a?(Group) if entity.resource_parent.is_a?(Group)
edit_group_milestone_path(entity.resource_parent, entity, *args) edit_group_milestone_path(entity.resource_parent, entity, *args)
......
...@@ -12,12 +12,12 @@ module Noteable ...@@ -12,12 +12,12 @@ module Noteable
class_methods do class_methods do
# `Noteable` class names that support replying to individual notes. # `Noteable` class names that support replying to individual notes.
def replyable_types def replyable_types
%w[Issue MergeRequest AbuseReport] %w[Issue MergeRequest AbuseReport WikiPage::Meta]
end end
# `Noteable` class names that support resolvable notes. # `Noteable` class names that support resolvable notes.
def resolvable_types def resolvable_types
%w[Issue MergeRequest DesignManagement::Design AbuseReport] %w[Issue MergeRequest DesignManagement::Design AbuseReport WikiPage::Meta]
end end
# `Noteable` class names that support creating/forwarding individual notes. # `Noteable` class names that support creating/forwarding individual notes.
......
...@@ -11,7 +11,7 @@ class DiscussionNote < Note ...@@ -11,7 +11,7 @@ class DiscussionNote < Note
# Names of all implementers of `Noteable` that support discussions. # Names of all implementers of `Noteable` that support discussions.
def self.noteable_types def self.noteable_types
%w[MergeRequest Issue Commit Snippet] %w[MergeRequest Issue Commit Snippet WikiPage::Meta]
end end
validates :noteable_type, inclusion: { in: noteable_types } validates :noteable_type, inclusion: { in: noteable_types }
......
...@@ -361,6 +361,10 @@ def for_personal_snippet? ...@@ -361,6 +361,10 @@ def for_personal_snippet?
noteable.is_a?(PersonalSnippet) noteable.is_a?(PersonalSnippet)
end end
def for_wiki_page?
noteable_type == "WikiPage::Meta"
end
def for_project_noteable? def for_project_noteable?
!(for_personal_snippet? || for_abuse_report? || group_level_issue?) !(for_personal_snippet? || for_abuse_report? || group_level_issue?)
end end
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
class WikiPage class WikiPage
class Meta < ApplicationRecord class Meta < ApplicationRecord
include HasWikiPageMetaAttributes include HasWikiPageMetaAttributes
include Mentionable
include Noteable
self.table_name = 'wiki_page_meta' self.table_name = 'wiki_page_meta'
...@@ -10,15 +12,14 @@ class Meta < ApplicationRecord ...@@ -10,15 +12,14 @@ class Meta < ApplicationRecord
belongs_to :namespace, optional: true belongs_to :namespace, optional: true
has_many :slugs, class_name: 'WikiPage::Slug', foreign_key: 'wiki_page_meta_id', inverse_of: :wiki_page_meta has_many :slugs, class_name: 'WikiPage::Slug', foreign_key: 'wiki_page_meta_id', inverse_of: :wiki_page_meta
has_many :notes, as: :noteable
has_many :user_mentions, class_name: 'Wikis::UserMention', foreign_key: 'wiki_page_meta_id',
inverse_of: :wiki_page_meta
validate :project_or_namespace_present? validate :project_or_namespace_present?
alias_method :resource_parent, :project alias_method :resource_parent, :project
def container_key
namespace.present? ? :namespace_id : :project_id
end
def container def container
project || namespace project || namespace
end end
...@@ -28,6 +29,14 @@ def container=(value) ...@@ -28,6 +29,14 @@ def container=(value)
self.namespace = value if value.is_a?(Namespace) self.namespace = value if value.is_a?(Namespace)
end end
def for_group_wiki?
namespace_id.present?
end
def container_key
for_group_wiki? ? :namespace_id : :project_id
end
private private
def project_or_namespace_present? def project_or_namespace_present?
......
# frozen_string_literal: true
module Wikis
class UserMention < UserMention
self.table_name = 'wiki_page_meta_user_mentions'
belongs_to :wiki_page_meta, class_name: 'WikiPage::Meta', optional: false
belongs_to :note, optional: false
before_validation :set_namespace_id_from_note, on: :create
private
def set_namespace_id_from_note
self.namespace_id ||= note&.namespace_id
end
end
end
---
table_name: wiki_page_meta_user_mentions
classes:
- Wikis::UserMention
feature_categories:
- wiki
description: User mentions in wiki page notes
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/163305
milestone: '17.5'
gitlab_schema: gitlab_main_cell
sharding_key:
namespace_id: namespaces
# frozen_string_literal: true
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class CreateWikiPageUserMentions < Gitlab::Database::Migration[2.2]
enable_lock_retries!
milestone '17.5'
def up
create_table :wiki_page_meta_user_mentions do |t| # rubocop:disable Migration/EnsureFactoryForTable -- No factory needed
t.bigint :wiki_page_meta_id, null: false
t.bigint :note_id, null: false
t.bigint :namespace_id, null: false
t.bigint :mentioned_users_ids, array: true, default: nil
t.bigint :mentioned_projects_ids, array: true, default: nil
t.bigint :mentioned_groups_ids, array: true, default: nil
t.index :note_id
t.index :namespace_id
t.index [:wiki_page_meta_id, :note_id],
unique: true,
name: :index_wiki_meta_user_mentions_on_wiki_page_meta_id_and_note_id
end
end
def down
drop_table :wiki_page_meta_user_mentions, if_exists: true
end
end
# frozen_string_literal: true
class AddWikiPageMetaForeignKeyToWikiPageMetaUserMentions < Gitlab::Database::Migration[2.2]
milestone '17.5'
disable_ddl_transaction!
def up
add_concurrent_foreign_key :wiki_page_meta_user_mentions, :wiki_page_meta, column: :wiki_page_meta_id,
on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :wiki_page_meta_user_mentions, column: :wiki_page_meta_id
end
end
end
# frozen_string_literal: true
class AddNotesForeignKeyToWikiPageMetaUserMentions < Gitlab::Database::Migration[2.2]
milestone '17.5'
disable_ddl_transaction!
def up
add_concurrent_foreign_key :wiki_page_meta_user_mentions, :notes, column: :note_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :wiki_page_meta_user_mentions, column: :note_id
end
end
end
# frozen_string_literal: true
class AddNamespacesForeignKeyToWikiPageMetaUserMentions < Gitlab::Database::Migration[2.2]
milestone '17.5'
disable_ddl_transaction!
def up
add_concurrent_foreign_key :wiki_page_meta_user_mentions, :namespaces, column: :namespace_id, on_delete: :cascade
end
def down
with_lock_retries do
remove_foreign_key :wiki_page_meta_user_mentions, column: :namespace_id
end
end
end
9ee63c7a0b13f8eabca033494d551c498d8320144f6acec53b2bd6263e1b5152
\ No newline at end of file
ec9255f62950f75064ad2cd65c9fef6a1b4c136d4bb86238b24ed567098fb28e
\ No newline at end of file
caa78be456eebea5d9fc8cbcc0d0daa56e11f3e633f5327014702814919a073c
\ No newline at end of file
b844c5179a55387b9c0f631a9172b7b62fae98e38d8c86532dbcac2365f8a1c7
\ No newline at end of file
...@@ -20571,6 +20571,25 @@ CREATE SEQUENCE wiki_page_meta_id_seq ...@@ -20571,6 +20571,25 @@ CREATE SEQUENCE wiki_page_meta_id_seq
   
ALTER SEQUENCE wiki_page_meta_id_seq OWNED BY wiki_page_meta.id; ALTER SEQUENCE wiki_page_meta_id_seq OWNED BY wiki_page_meta.id;
   
CREATE TABLE wiki_page_meta_user_mentions (
id bigint NOT NULL,
wiki_page_meta_id bigint NOT NULL,
note_id bigint NOT NULL,
namespace_id bigint NOT NULL,
mentioned_users_ids bigint[],
mentioned_projects_ids bigint[],
mentioned_groups_ids bigint[]
);
CREATE SEQUENCE wiki_page_meta_user_mentions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE wiki_page_meta_user_mentions_id_seq OWNED BY wiki_page_meta_user_mentions.id;
CREATE TABLE wiki_page_slugs ( CREATE TABLE wiki_page_slugs (
id bigint NOT NULL, id bigint NOT NULL,
canonical boolean DEFAULT false NOT NULL, canonical boolean DEFAULT false NOT NULL,
...@@ -22731,6 +22750,8 @@ ALTER TABLE ONLY webauthn_registrations ALTER COLUMN id SET DEFAULT nextval('web ...@@ -22731,6 +22750,8 @@ ALTER TABLE ONLY webauthn_registrations ALTER COLUMN id SET DEFAULT nextval('web
   
ALTER TABLE ONLY wiki_page_meta ALTER COLUMN id SET DEFAULT nextval('wiki_page_meta_id_seq'::regclass); ALTER TABLE ONLY wiki_page_meta ALTER COLUMN id SET DEFAULT nextval('wiki_page_meta_id_seq'::regclass);
   
ALTER TABLE ONLY wiki_page_meta_user_mentions ALTER COLUMN id SET DEFAULT nextval('wiki_page_meta_user_mentions_id_seq'::regclass);
ALTER TABLE ONLY wiki_page_slugs ALTER COLUMN id SET DEFAULT nextval('wiki_page_slugs_id_seq'::regclass); ALTER TABLE ONLY wiki_page_slugs ALTER COLUMN id SET DEFAULT nextval('wiki_page_slugs_id_seq'::regclass);
   
ALTER TABLE ONLY wiki_repository_states ALTER COLUMN id SET DEFAULT nextval('wiki_repository_states_id_seq'::regclass); ALTER TABLE ONLY wiki_repository_states ALTER COLUMN id SET DEFAULT nextval('wiki_repository_states_id_seq'::regclass);
...@@ -25537,6 +25558,9 @@ ALTER TABLE ONLY webauthn_registrations ...@@ -25537,6 +25558,9 @@ ALTER TABLE ONLY webauthn_registrations
ALTER TABLE ONLY wiki_page_meta ALTER TABLE ONLY wiki_page_meta
ADD CONSTRAINT wiki_page_meta_pkey PRIMARY KEY (id); ADD CONSTRAINT wiki_page_meta_pkey PRIMARY KEY (id);
   
ALTER TABLE ONLY wiki_page_meta_user_mentions
ADD CONSTRAINT wiki_page_meta_user_mentions_pkey PRIMARY KEY (id);
ALTER TABLE ONLY wiki_page_slugs ALTER TABLE ONLY wiki_page_slugs
ADD CONSTRAINT wiki_page_slugs_pkey PRIMARY KEY (id); ADD CONSTRAINT wiki_page_slugs_pkey PRIMARY KEY (id);
   
...@@ -31146,10 +31170,16 @@ CREATE UNIQUE INDEX index_webauthn_registrations_on_credential_xid ON webauthn_r ...@@ -31146,10 +31170,16 @@ CREATE UNIQUE INDEX index_webauthn_registrations_on_credential_xid ON webauthn_r
   
CREATE INDEX index_webauthn_registrations_on_user_id ON webauthn_registrations USING btree (user_id); CREATE INDEX index_webauthn_registrations_on_user_id ON webauthn_registrations USING btree (user_id);
   
CREATE UNIQUE INDEX index_wiki_meta_user_mentions_on_wiki_page_meta_id_and_note_id ON wiki_page_meta_user_mentions USING btree (wiki_page_meta_id, note_id);
CREATE INDEX index_wiki_page_meta_on_namespace_id ON wiki_page_meta USING btree (namespace_id); CREATE INDEX index_wiki_page_meta_on_namespace_id ON wiki_page_meta USING btree (namespace_id);
   
CREATE INDEX index_wiki_page_meta_on_project_id ON wiki_page_meta USING btree (project_id); CREATE INDEX index_wiki_page_meta_on_project_id ON wiki_page_meta USING btree (project_id);
   
CREATE INDEX index_wiki_page_meta_user_mentions_on_namespace_id ON wiki_page_meta_user_mentions USING btree (namespace_id);
CREATE INDEX index_wiki_page_meta_user_mentions_on_note_id ON wiki_page_meta_user_mentions USING btree (note_id);
CREATE INDEX index_wiki_page_slugs_on_project_id ON wiki_page_slugs USING btree (project_id); CREATE INDEX index_wiki_page_slugs_on_project_id ON wiki_page_slugs USING btree (project_id);
   
CREATE UNIQUE INDEX index_wiki_page_slugs_on_slug_and_wiki_page_meta_id ON wiki_page_slugs USING btree (slug, wiki_page_meta_id); CREATE UNIQUE INDEX index_wiki_page_slugs_on_slug_and_wiki_page_meta_id ON wiki_page_slugs USING btree (slug, wiki_page_meta_id);
...@@ -34103,6 +34133,9 @@ ALTER TABLE ONLY users ...@@ -34103,6 +34133,9 @@ ALTER TABLE ONLY users
ALTER TABLE ONLY analytics_devops_adoption_snapshots ALTER TABLE ONLY analytics_devops_adoption_snapshots
ADD CONSTRAINT fk_78c9eac821 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE; ADD CONSTRAINT fk_78c9eac821 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
   
ALTER TABLE ONLY wiki_page_meta_user_mentions
ADD CONSTRAINT fk_7954f34107 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY topics ALTER TABLE ONLY topics
ADD CONSTRAINT fk_79ae18bd4b FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE; ADD CONSTRAINT fk_79ae18bd4b FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE;
   
...@@ -34499,12 +34532,18 @@ ALTER TABLE ONLY uploads ...@@ -34499,12 +34532,18 @@ ALTER TABLE ONLY uploads
ALTER TABLE ONLY deployments ALTER TABLE ONLY deployments
ADD CONSTRAINT fk_b9a3851b82 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; ADD CONSTRAINT fk_b9a3851b82 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
   
ALTER TABLE ONLY wiki_page_meta_user_mentions
ADD CONSTRAINT fk_ba8a9d7f95 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
ALTER TABLE ONLY project_compliance_standards_adherence ALTER TABLE ONLY project_compliance_standards_adherence
ADD CONSTRAINT fk_baf6f6f878 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; ADD CONSTRAINT fk_baf6f6f878 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
   
ALTER TABLE p_ci_runner_machine_builds ALTER TABLE p_ci_runner_machine_builds
ADD CONSTRAINT fk_bb490f12fe_p FOREIGN KEY (partition_id, build_id) REFERENCES p_ci_builds(partition_id, id) ON UPDATE CASCADE ON DELETE CASCADE; ADD CONSTRAINT fk_bb490f12fe_p FOREIGN KEY (partition_id, build_id) REFERENCES p_ci_builds(partition_id, id) ON UPDATE CASCADE ON DELETE CASCADE;
   
ALTER TABLE ONLY wiki_page_meta_user_mentions
ADD CONSTRAINT fk_bc155eba89 FOREIGN KEY (wiki_page_meta_id) REFERENCES wiki_page_meta(id) ON DELETE CASCADE;
ALTER TABLE ONLY security_orchestration_policy_rule_schedules ALTER TABLE ONLY security_orchestration_policy_rule_schedules
ADD CONSTRAINT fk_bcbb90477f FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; ADD CONSTRAINT fk_bcbb90477f FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
   
...@@ -51,13 +51,17 @@ def for_epic? ...@@ -51,13 +51,17 @@ def for_epic?
noteable.is_a?(Epic) noteable.is_a?(Epic)
end end
def for_group_wiki?
for_wiki_page? && noteable&.for_group_wiki?
end
def for_vulnerability? def for_vulnerability?
noteable.is_a?(Vulnerability) noteable.is_a?(Vulnerability)
end end
override :for_project_noteable? override :for_project_noteable?
def for_project_noteable? def for_project_noteable?
!for_epic? && super !(for_epic? || for_group_wiki?) && super
end end
override :banzai_render_context override :banzai_render_context
......
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
trait :on_vulnerability do trait :on_vulnerability do
noteable { association(:vulnerability, project: project) } noteable { association(:vulnerability, project: project) }
end end
trait :on_group_level_wiki do
project { nil }
namespace { association :group }
noteable { association(:wiki_page_meta, namespace: namespace) }
end
end end
end end
......
...@@ -297,6 +297,16 @@ ...@@ -297,6 +297,16 @@
end end
end end
describe '#for_group_wiki?' do
it 'returns true for a group-level wiki page' do
expect(build_stubbed(:note_on_wiki_page, :on_group_level_wiki).for_group_wiki?).to be_truthy
end
it 'returns false for a project-level wiki page' do
expect(build_stubbed(:note_on_wiki_page, :on_project_level_wiki).for_group_wiki?).to be_falsy
end
end
describe '.note_starting_with' do describe '.note_starting_with' do
it 'returns a note matching the prefix' do it 'returns a note matching the prefix' do
create(:note) create(:note)
......
...@@ -101,6 +101,8 @@ def note_url(note, **options) ...@@ -101,6 +101,8 @@ def note_url(note, **options)
instance.gitlab_snippet_url(note.noteable, anchor: dom_id(note), **options) instance.gitlab_snippet_url(note.noteable, anchor: dom_id(note), **options)
elsif note.for_abuse_report? elsif note.for_abuse_report?
instance.admin_abuse_report_url(note.noteable, anchor: dom_id(note), **options) instance.admin_abuse_report_url(note.noteable, anchor: dom_id(note), **options)
elsif note.for_wiki_page?
instance.project_wiki_page_url(note.noteable, anchor: dom_id(note), **options)
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册