Commit 6424af9e authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch 'move-group-wiki-model-into-ee' into 'master'

Move GroupWiki model into EE

See merge request gitlab-org/gitlab!30857
parents ab86197c b6717de7
...@@ -15,7 +15,6 @@ class Group < Namespace ...@@ -15,7 +15,6 @@ class Group < Namespace
include WithUploads include WithUploads
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
include GroupAPICompatibility include GroupAPICompatibility
include HasWiki
ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT = 10 ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT = 10
......
...@@ -13,6 +13,7 @@ module EE ...@@ -13,6 +13,7 @@ module EE
include TokenAuthenticatable include TokenAuthenticatable
include InsightsFeature include InsightsFeature
include HasTimelogsReport include HasTimelogsReport
include HasWiki
add_authentication_token_field :saml_discovery_token, unique: false, token_generator: -> { Devise.friendly_token(8) } add_authentication_token_field :saml_discovery_token, unique: false, token_generator: -> { Devise.friendly_token(8) }
......
...@@ -35,6 +35,17 @@ module EE ...@@ -35,6 +35,17 @@ module EE
end end
end end
override :wiki_url
def wiki_url(object, **options)
if object.container.is_a?(Group)
# TODO: Use the new route for group wikis once we add it.
# https://gitlab.com/gitlab-org/gitlab/-/issues/211360
instance.group_canonical_url(object.container, **options) + "/-/wikis/#{::Wiki::HOMEPAGE}"
else
super
end
end
def design_url(design, **options) def design_url(design, **options)
size, ref = options.values_at(:size, :ref) size, ref = options.values_at(:size, :ref)
options.except!(:size, :ref) options.except!(:size, :ref)
......
# frozen_string_literal: true
FactoryBot.define do
factory :group_wiki, parent: :wiki do
container { association(:group, :wiki_repo) }
end
end
# frozen_string_literal: true # frozen_string_literal: true
FactoryBot.modify do
factory :group do
trait :wiki_repo do
after(:create) do |group|
raise 'Failed to create wiki repository!' unless group.create_wiki
end
end
end
end
FactoryBot.define do FactoryBot.define do
factory :group_with_members, parent: :group do factory :group_with_members, parent: :group do
after(:create) do |group, evaluator| after(:create) do |group, evaluator|
......
...@@ -15,6 +15,8 @@ describe Gitlab::UrlBuilder do ...@@ -15,6 +15,8 @@ describe Gitlab::UrlBuilder do
:note_on_epic | ->(note) { "/groups/#{note.noteable.group.full_path}/-/epics/#{note.noteable.iid}#note_#{note.id}" } :note_on_epic | ->(note) { "/groups/#{note.noteable.group.full_path}/-/epics/#{note.noteable.iid}#note_#{note.id}" }
:note_on_vulnerability | ->(note) { "/#{note.project.full_path}/-/security/vulnerabilities/#{note.noteable.id}#note_#{note.id}" } :note_on_vulnerability | ->(note) { "/#{note.project.full_path}/-/security/vulnerabilities/#{note.noteable.id}#note_#{note.id}" }
:group_wiki | ->(wiki) { "/groups/#{wiki.container.full_path}/-/wikis/home" }
end end
with_them do with_them do
......
# frozen_string_literal: true
require 'spec_helper'
describe GroupWiki do
it_behaves_like 'EE wiki model' do
let(:wiki_container) { create(:group, :wiki_repo) }
before do
wiki_container.add_owner(user)
end
it 'does not use Elasticsearch' do
expect(subject).not_to be_a(Elastic::WikiRepositoriesSearch)
end
end
end
...@@ -19,6 +19,11 @@ describe Group do ...@@ -19,6 +19,11 @@ describe Group do
it { is_expected.to have_one(:dependency_proxy_setting) } it { is_expected.to have_one(:dependency_proxy_setting) }
it { is_expected.to have_one(:deletion_schedule) } it { is_expected.to have_one(:deletion_schedule) }
it { is_expected.to belong_to(:push_rule) } it { is_expected.to belong_to(:push_rule) }
it_behaves_like 'model with wiki' do
let(:container) { create(:group, :nested, :wiki_repo) }
let(:container_without_wiki) { create(:group, :nested) }
end
end end
describe 'scopes' do describe 'scopes' do
......
...@@ -35,4 +35,16 @@ describe GroupWiki do ...@@ -35,4 +35,16 @@ describe GroupWiki do
end end
end end
end end
it_behaves_like 'EE wiki model' do
let(:wiki_container) { create(:group, :wiki_repo) }
before do
wiki_container.add_owner(user)
end
it 'does not use Elasticsearch' do
expect(subject).not_to be_a(Elastic::WikiRepositoriesSearch)
end
end
end end
...@@ -72,13 +72,8 @@ module Gitlab ...@@ -72,13 +72,8 @@ module Gitlab
end end
def wiki_url(object, **options) def wiki_url(object, **options)
case object.container if object.container.is_a?(Project)
when Project
instance.project_wiki_url(object.container, Wiki::HOMEPAGE, **options) instance.project_wiki_url(object.container, Wiki::HOMEPAGE, **options)
when Group
# TODO: Use the new route for group wikis once we add it.
# https://gitlab.com/gitlab-org/gitlab/-/issues/211360
instance.group_canonical_url(object.container, **options) + "/-/wikis/#{Wiki::HOMEPAGE}"
else else
raise NotImplementedError.new("No URL builder defined for #{object.inspect}") raise NotImplementedError.new("No URL builder defined for #{object.inspect}")
end end
......
...@@ -51,11 +51,5 @@ FactoryBot.define do ...@@ -51,11 +51,5 @@ FactoryBot.define do
trait :owner_subgroup_creation_only do trait :owner_subgroup_creation_only do
subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS} subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS}
end end
trait :wiki_repo do
after(:create) do |group|
raise 'Failed to create wiki repository!' unless group.create_wiki
end
end
end end
end end
...@@ -17,9 +17,5 @@ FactoryBot.define do ...@@ -17,9 +17,5 @@ FactoryBot.define do
container { project } container { project }
end end
factory :group_wiki do
container { association(:group, :wiki_repo) }
end
end end
end end
...@@ -10,7 +10,6 @@ describe Gitlab::RepositoryUrlBuilder do ...@@ -10,7 +10,6 @@ describe Gitlab::RepositoryUrlBuilder do
:project | ->(project) { project.full_path } :project | ->(project) { project.full_path }
:project_snippet | ->(snippet) { "#{snippet.project.full_path}/snippets/#{snippet.id}" } :project_snippet | ->(snippet) { "#{snippet.project.full_path}/snippets/#{snippet.id}" }
:project_wiki | ->(wiki) { "#{wiki.container.full_path}.wiki" } :project_wiki | ->(wiki) { "#{wiki.container.full_path}.wiki" }
:group_wiki | ->(wiki) { "#{wiki.container.full_path}.wiki" }
:personal_snippet | ->(snippet) { "snippets/#{snippet.id}" } :personal_snippet | ->(snippet) { "snippets/#{snippet.id}" }
end end
......
...@@ -28,7 +28,6 @@ describe Gitlab::UrlBuilder do ...@@ -28,7 +28,6 @@ describe Gitlab::UrlBuilder do
:group | ->(group) { "/groups/#{group.full_path}" } :group | ->(group) { "/groups/#{group.full_path}" }
:group_milestone | ->(milestone) { "/groups/#{milestone.group.full_path}/-/milestones/#{milestone.iid}" } :group_milestone | ->(milestone) { "/groups/#{milestone.group.full_path}/-/milestones/#{milestone.iid}" }
:group_wiki | ->(wiki) { "/groups/#{wiki.container.full_path}/-/wikis/home" }
:user | ->(user) { "/#{user.full_path}" } :user | ->(user) { "/#{user.full_path}" }
:personal_snippet | ->(snippet) { "/snippets/#{snippet.id}" } :personal_snippet | ->(snippet) { "/snippets/#{snippet.id}" }
......
...@@ -27,11 +27,6 @@ describe Group do ...@@ -27,11 +27,6 @@ describe Group do
it { is_expected.to have_many(:milestones) } it { is_expected.to have_many(:milestones) }
it { is_expected.to have_many(:sprints) } it { is_expected.to have_many(:sprints) }
it_behaves_like 'model with wiki' do
let(:container) { create(:group, :nested, :wiki_repo) }
let(:container_without_wiki) { create(:group, :nested) }
end
describe '#members & #requesters' do describe '#members & #requesters' do
let(:requester) { create(:user) } let(:requester) { create(:user) }
let(:developer) { create(:user) } let(:developer) { create(:user) }
......
...@@ -150,18 +150,10 @@ describe WikiPage do ...@@ -150,18 +150,10 @@ describe WikiPage do
enable_front_matter_for(container) enable_front_matter_for(container)
end end
context 'with a project container' do
it_behaves_like 'a page with front-matter'
end
context 'with a group container' do
let(:container) { create(:group) }
it_behaves_like 'a page with front-matter' it_behaves_like 'a page with front-matter'
end end
end end
end end
end
context 'the wiki page does not have front matter' do context 'the wiki page does not have front matter' do
let(:content) { 'My actual content' } let(:content) { 'My actual content' }
...@@ -512,17 +504,9 @@ describe WikiPage do ...@@ -512,17 +504,9 @@ describe WikiPage do
enable_front_matter_for(container) enable_front_matter_for(container)
end end
context 'with a project container' do
it_behaves_like 'able to update front-matter'
end
context 'with a group container' do
let(:container) { create(:group) }
it_behaves_like 'able to update front-matter' it_behaves_like 'able to update front-matter'
end end
end end
end
it 'updates the wiki-page front-matter and content together' do it 'updates the wiki-page front-matter and content together' do
title = subject.title title = subject.title
...@@ -826,22 +810,13 @@ describe WikiPage do ...@@ -826,22 +810,13 @@ describe WikiPage do
expect(subject).not_to eq(other_page) expect(subject).not_to eq(other_page)
end end
it 'returns false for page with the same slug on a different container of the same type' do it 'returns false for page with the same slug on a different container' do
other_page = create(:wiki_page, title: existing_page.slug) other_page = create(:wiki_page, title: existing_page.slug)
expect(subject.slug).to eq(other_page.slug) expect(subject.slug).to eq(other_page.slug)
expect(subject.container).not_to eq(other_page.container) expect(subject.container).not_to eq(other_page.container)
expect(subject).not_to eq(other_page) expect(subject).not_to eq(other_page)
end end
it 'returns false for page with the same slug on a different container type' do
group = create(:group, name: container.name)
other_page = create(:wiki_page, title: existing_page.slug, container: group)
expect(subject.slug).to eq(other_page.slug)
expect(subject.container).not_to eq(other_page.container)
expect(subject).not_to eq(other_page)
end
end end
describe '#last_commit_sha' do describe '#last_commit_sha' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment