Commit 333e39d4 authored by TM Lee's avatar TM Lee

[#28991] Wiki page edit button only appears on the current commit page

- Added method to check if the current Page version is the current latest version
- Conditionally checks for current version when showing Edit button
- Added feature specs for viewing project wiki page and expect edit button
- Added Changelog
parent 8fddde5b
......@@ -148,6 +148,12 @@ class WikiPage
@page.historical? && versions.first.sha != version.sha
end
# Returns boolean True or False if this instance
# is the latest commit version of the page.
def latest?
!historical?
end
# Returns boolean True or False if this instance
# has been fully saved to disk or not.
def persisted?
......
......@@ -4,6 +4,6 @@
New Page
= link_to namespace_project_wiki_history_path(@project.namespace, @project, @page), class: "btn" do
Page History
- if can?(current_user, :create_wiki, @project)
- if can?(current_user, :create_wiki, @project) && @page.latest?
= link_to namespace_project_wiki_edit_path(@project.namespace, @project, @page), class: "btn" do
Edit
---
title: When viewing old wiki page version, edit button should be disabled
merge_request: 9966
author: TM Lee
require 'spec_helper'
feature 'Projects > Wiki > User views the wiki page', feature: true do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let(:old_page_version_id) { wiki_page.versions.last.id }
let(:wiki_page) do
WikiPages::CreateService.new(
project,
user,
title: 'home',
content: '[some link](other-page)'
).execute
end
background do
project.team << [user, :master]
login_as(user)
WikiPages::UpdateService.new(
project,
user,
message: 'updated home',
content: 'updated [some link](other-page)',
format: :markdown
).execute(wiki_page)
end
scenario 'Visit Wiki Page Current Commit' do
visit namespace_project_wiki_path(project.namespace, project, wiki_page)
expect(page).to have_selector('a.btn', text: 'Edit')
end
scenario 'Visit Wiki Page Historical Commit' do
visit namespace_project_wiki_path(
project.namespace,
project,
wiki_page,
version_id: old_page_version_id
)
expect(page).not_to have_selector('a.btn', text: 'Edit')
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