-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wikiリダイレクトのリセット機能 #11 #22
Open
ishikawa999
wants to merge
6
commits into
develop
Choose a base branch
from
task/1024
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
23692e2
Show links to delete redirect (no function)
kfischer-okarin 9f9dd8f
Add WikiRedirectsController with destroy action
kfischer-okarin 65be77d
Redirect to Wiki page + show success message
kfischer-okarin 8d62d4b
Add functionality to delete link
kfischer-okarin 63ad7c8
Hide links without permission
kfischer-okarin b754d4d
Add locale
kfischer-okarin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
# Redmine - project management software | ||
# Copyright (C) 2006-2020 Jean-Philippe Lang | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
class WikiRedirectsController < ApplicationController | ||
before_action :find_wiki_redirect, :authorize | ||
|
||
def destroy | ||
if @wiki_redirect.destroy | ||
flash[:notice] = l(:notice_successful_delete) | ||
redirect_to project_wiki_page_path(@page.project, @page.title) | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_wiki_redirect | ||
@project = Project.find(params[:project_id]) | ||
@page = Wiki.find_page(params[:wiki_page_id], project: @project) | ||
@wiki_redirect=WikiRedirect.where(redirects_to: @page.title).find(params[:id]) | ||
render_404 unless @wiki_redirect | ||
rescue ActiveRecord::RecordNotFound | ||
render_404 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,11 @@ | |
<%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :id => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if [email protected]? %> | ||
<%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :id => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %> | ||
<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :id => @page.title}, :class => 'icon icon-move') %> | ||
<% if User.current.allowed_to?(:rename_wiki_pages, @project) %> | ||
<% @redirects_to_self.map { |redirect| %> | ||
<%= link_to(l(:button_delete_redirect, :page_title => WikiPage.pretty_title(redirect.title)), {:controller => 'wiki_redirects', :action => 'destroy', :project_id => @project.identifier, :wiki_page_id => @page.title, :id => redirect.id}, :method => :delete, :class => 'icon icon-link-break') %> | ||
<% } %> | ||
<% end %> | ||
<%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :id => @page.title}, :method => :delete, :data => {:confirm => l(:text_are_you_sure)}, :class => 'icon icon-del') %> | ||
<% else %> | ||
<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :id => @page.title, :version => @content.version }, :class => 'icon icon-cancel') %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# frozen_string_literal: true | ||
|
||
# Redmine - project management software | ||
# Copyright (C) 2006-2020 Jean-Philippe Lang | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
require File.expand_path('../../test_helper', __FILE__) | ||
|
||
class WikiRedirectsControllerTest < Redmine::ControllerTest | ||
fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, | ||
:enabled_modules, :wikis, :wiki_pages, :wiki_contents, | ||
:wiki_content_versions, :attachments, | ||
:issues, :issue_statuses, :trackers | ||
|
||
def setup | ||
User.current = nil | ||
@request.session[:user_id] = 1 | ||
end | ||
|
||
def test_destroy | ||
wiki_page = WikiPage.find(2) | ||
old_title = wiki_page.title | ||
wiki_page.title = 'Test' | ||
wiki_page.save | ||
|
||
wiki_redirect = WikiRedirect.find_by(title: old_title, redirects_to: 'Test') | ||
|
||
delete :destroy, params: {id: wiki_redirect.id, project_id: wiki_page.wiki.project_id, wiki_page_id: 'Test'} | ||
|
||
assert_redirected_to '/projects/ecookbook/wiki/Test' | ||
assert_equal 'Successful deletion.', flash[:notice] | ||
assert_not WikiRedirect.exists?(id: wiki_redirect.id) | ||
end | ||
|
||
def test_destroy_without_permission | ||
@request.session[:user_id] = User.generate!.id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
という2点が気になりました。 diff --git a/test/functional/wiki_redirects_controller_test.rb b/test/functional/wiki_redirects_controller_test.rb
index 7949ec3b5..e9ae9f2f7 100644
--- a/test/functional/wiki_redirects_controller_test.rb
+++ b/test/functional/wiki_redirects_controller_test.rb
@@ -31,6 +31,8 @@ class WikiRedirectsControllerTest < Redmine::ControllerTest
end
def test_destroy
+ @request.session[:user_id] = 2
+
wiki_page = WikiPage.find(2)
old_title = wiki_page.title
wiki_page.title = 'Test'
@@ -45,8 +47,9 @@ class WikiRedirectsControllerTest < Redmine::ControllerTest
assert_not WikiRedirect.exists?(id: wiki_redirect.id)
end
- def test_destroy_without_permission
- @request.session[:user_id] = User.generate!.id
+ def test_destroy_without_rename_wiki_pages_permission
+ @request.session[:user_id] = 2
+ Role.find(1).remove_permission! :rename_wiki_pages # User 2 role
wiki_page = WikiPage.find(2)
old_title = wiki_page.title (気になった点としてコメントしただけなので、この書き方でも問題なくコミットされると思います。) |
||
|
||
wiki_page = WikiPage.find(2) | ||
old_title = wiki_page.title | ||
wiki_page.title = 'Test' | ||
wiki_page.save | ||
|
||
wiki_redirect = WikiRedirect.find_by(title: old_title, redirects_to: 'Test') | ||
|
||
delete :destroy, params: {id: wiki_redirect.id, project_id: wiki_page.wiki.project_id, wiki_page_id: 'Test'} | ||
|
||
assert_response :forbidden | ||
assert WikiRedirect.exists?(id: wiki_redirect.id) | ||
end | ||
|
||
def test_invalid_redirect_should_respond_with_404 | ||
wiki_page = WikiPage.find(1) | ||
old_title = wiki_page.title | ||
wiki_page.title = 'New_Title' | ||
wiki_page.save | ||
|
||
other_wiki_page = WikiPage.find(2) | ||
other_wiki_page.title = 'Other_New_Title' | ||
other_wiki_page.save | ||
|
||
wiki_redirect = WikiRedirect.find_by(title: old_title, redirects_to: 'New_Title') | ||
|
||
delete :destroy, params: {id: wiki_redirect.id, project_id: other_wiki_page.wiki.project_id, wiki_page_id: 'Other_New_Title'} | ||
|
||
assert_response :not_found | ||
assert WikiRedirect.exists?(id: wiki_redirect.id) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かいのですが、ここのブロックはdo...endの方が他の書き方にあっていて良いと思います。