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
include WithUploads
include Gitlab::Utils::StrongMemoize
include GroupAPICompatibility
include HasWiki
ACCESS_REQUEST_APPROVERS_TO_BE_NOTIFIED_LIMIT = 10
......
......@@ -13,6 +13,7 @@ module EE
include TokenAuthenticatable
include InsightsFeature
include HasTimelogsReport
include HasWiki
add_authentication_token_field :saml_discovery_token, unique: false, token_generator: -> { Devise.friendly_token(8) }
......
......@@ -35,6 +35,17 @@ module EE
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)
size, ref = options.values_at(: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
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
factory :group_with_members, parent: :group do
after(:create) do |group, evaluator|
......
......@@ -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_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
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
it { is_expected.to have_one(:dependency_proxy_setting) }
it { is_expected.to have_one(:deletion_schedule) }
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
describe 'scopes' do
......
......@@ -35,4 +35,16 @@ describe GroupWiki do
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
......@@ -72,13 +72,8 @@ module Gitlab
end
def wiki_url(object, **options)
case object.container
when Project
if object.container.is_a?(Project)
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
raise NotImplementedError.new("No URL builder defined for #{object.inspect}")
end
......
......@@ -51,11 +51,5 @@ FactoryBot.define do
trait :owner_subgroup_creation_only do
subgroup_creation_level { ::Gitlab::Access::OWNER_SUBGROUP_ACCESS}
end
trait :wiki_repo do
after(:create) do |group|
raise 'Failed to create wiki repository!' unless group.create_wiki
end
end
end
end
......@@ -17,9 +17,5 @@ FactoryBot.define do
container { project }
end
factory :group_wiki do
container { association(:group, :wiki_repo) }
end
end
end
......@@ -10,7 +10,6 @@ describe Gitlab::RepositoryUrlBuilder do
:project | ->(project) { project.full_path }
:project_snippet | ->(snippet) { "#{snippet.project.full_path}/snippets/#{snippet.id}" }
:project_wiki | ->(wiki) { "#{wiki.container.full_path}.wiki" }
:group_wiki | ->(wiki) { "#{wiki.container.full_path}.wiki" }
:personal_snippet | ->(snippet) { "snippets/#{snippet.id}" }
end
......
......@@ -28,7 +28,6 @@ describe Gitlab::UrlBuilder do
:group | ->(group) { "/groups/#{group.full_path}" }
: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}" }
:personal_snippet | ->(snippet) { "/snippets/#{snippet.id}" }
......
......@@ -27,11 +27,6 @@ describe Group do
it { is_expected.to have_many(:milestones) }
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
let(:requester) { create(:user) }
let(:developer) { create(:user) }
......
......@@ -150,15 +150,7 @@ describe WikiPage do
enable_front_matter_for(container)
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'
end
it_behaves_like 'a page with front-matter'
end
end
end
......@@ -512,15 +504,7 @@ describe WikiPage do
enable_front_matter_for(container)
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'
end
it_behaves_like 'able to update front-matter'
end
end
......@@ -826,22 +810,13 @@ describe WikiPage do
expect(subject).not_to eq(other_page)
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)
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
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
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