Commit 615160b1 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'ajk-212987-nil-wiki-page' into 'master'

Resolve "[Wiki] `@page` can be nil during `#edit`"

Closes #212987

See merge request gitlab-org/gitlab!29645
parents e4d69634 5d2e4b53
......@@ -10,8 +10,9 @@ class Projects::WikisController < Projects::ApplicationController
before_action :authorize_admin_wiki!, only: :destroy
before_action :load_project_wiki
before_action :load_page, only: [:show, :edit, :update, :history, :destroy]
before_action :valid_encoding?,
if: -> { %w[show edit update].include?(action_name) && load_page }
before_action only: [:show, :edit, :update] do
@valid_encoding = valid_encoding?
end
before_action only: [:edit, :update], unless: :valid_encoding? do
redirect_to(project_wiki_path(@project, @page))
end
......@@ -167,7 +168,11 @@ class Projects::WikisController < Projects::ApplicationController
end
def load_page
@page ||= @project_wiki.find_page(*page_params)
@page ||= find_page
end
def find_page
@project_wiki.find_page(*page_params)
end
def page_params
......@@ -178,9 +183,11 @@ class Projects::WikisController < Projects::ApplicationController
end
def valid_encoding?
strong_memoize(:valid_encoding) do
@page.content.encoding == Encoding::UTF_8
page_encoding == Encoding::UTF_8
end
def page_encoding
strong_memoize(:page_encoding) { @page&.content&.encoding }
end
def set_encoding_error
......
---
title: Eliminate errors in wiki controller during edit
merge_request: 29645
author:
type: fixed
......@@ -200,7 +200,20 @@ describe Projects::WikisController do
subject
expect(response).to redirect_to(project_wiki_path(project, project_wiki.list_pages.first))
expect(response).to redirect_to_wiki(project, project_wiki.list_pages.first)
end
end
context 'when the page has nil content' do
let(:page) { create(:wiki_page) }
it 'redirects to show' do
allow(page).to receive(:content).and_return(nil)
allow(controller).to receive(:find_page).and_return(page)
subject
expect(response).to redirect_to_wiki(project, page)
end
end
......@@ -235,7 +248,7 @@ describe Projects::WikisController do
allow(controller).to receive(:valid_encoding?).and_return(false)
subject
expect(response).to redirect_to(project_wiki_path(project, project_wiki.list_pages.first))
expect(response).to redirect_to_wiki(project, project_wiki.list_pages.first)
end
end
......@@ -265,4 +278,8 @@ describe Projects::WikisController do
page = wiki.page(title: title, dir: dir)
project_wiki.delete_page(page, "test commit")
end
def redirect_to_wiki(project, page)
redirect_to(controller.project_wiki_path(project, page))
end
end
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