-
Couldn't load subscription status.
- Fork 3
wikiリダイレクトのリセット機能 #11 #22
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
base: develop
Are you sure you want to change the base?
Changes from all commits
23692e2
9f9dd8f
65be77d
8d62d4b
63ad7c8
b754d4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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 | ||
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の方が他の書き方にあっていて良いと思います。