From 4a0a8df4fbcff65346a095ed26e34ce19667daf8 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Tue, 29 Mar 2022 12:54:48 +0000 Subject: [PATCH 1/5] Add Redmine 5.0 test environment --- .devcontainer/docker-compose.yml | 4 ++-- .github/workflows/build.yml | 10 ++++++++-- build-scripts/install.sh | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 887a2c4..e6f7b2c 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -9,10 +9,10 @@ services: # Update 'VARIANT' to pick a version of Ruby: 3, 3.0, 2, 2.7, 2.6 # Append -bullseye or -buster to pin to an OS version. # Use -bullseye variants on local arm64/Apple Silicon. - VARIANT: "2.7" + VARIANT: "3.0" # Optional Node.js version to install NODE_VERSION: "lts/*" - REDMINE_VERSION: "4.2-stable" + REDMINE_VERSION: "5.0-stable" volumes: - ..:/usr/local/redmine/plugins/redmine_wiki_extensions:cached diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29ae2f3..794519a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,17 +11,23 @@ jobs: strategy: matrix: db: [sqlite3, mysql, postgres] - ruby_version: [2.4, 2.5, 2.6, 2.7, 3.0] - redmine_version: [4.1-stable, 4.2-stable, master] + ruby_version: [2.4, 2.5, 2.6, 2.7, 3.0, 3.1] + redmine_version: [4.1-stable, 4.2-stable, 5.0-stable, master] exclude: - ruby_version: 2.4 redmine_version: master + - ruby_version: 2.4 + redmine_version: 5.0-stable - ruby_version: 2.7 redmine_version: 4.1-stable - ruby_version: 3.0 redmine_version: 4.1-stable - ruby_version: 3.0 redmine_version: 4.2-stable + - ruby_version: 3.1 + redmine_version: 4.1-stable + - ruby_version: 3.1 + redmine_version: 4.2-stable services: mysql: image: mysql:5.7 diff --git a/build-scripts/install.sh b/build-scripts/install.sh index 64b7af4..71afc09 100644 --- a/build-scripts/install.sh +++ b/build-scripts/install.sh @@ -34,7 +34,7 @@ fi mkdir -p $TESTSPACE -export REDMINE_GIT_REPO=git://github.com/redmine/redmine.git +export REDMINE_GIT_REPO=https://github.com/redmine/redmine.git export REDMINE_GIT_TAG=$REDMINE_VER export BUNDLE_GEMFILE=$PATH_TO_REDMINE/Gemfile From f2c264afccee1747b5c8c0d5790c3696a593c095 Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Fri, 8 Jul 2022 07:42:58 +0900 Subject: [PATCH 2/5] add gitpod configutration --- .gitpod.yml | 21 +++++++++++++++++++++ .gitpod/database.yml | 19 +++++++++++++++++++ .gitpod/gitpod.code-workspace | 11 +++++++++++ .gitpod/ignore | 2 ++ .gitpod/launch.json | 32 ++++++++++++++++++++++++++++++++ .gitpod/setup.sh | 30 ++++++++++++++++++++++++++++++ .gitpod/start.sh | 17 +++++++++++++++++ 7 files changed, 132 insertions(+) create mode 100644 .gitpod.yml create mode 100644 .gitpod/database.yml create mode 100644 .gitpod/gitpod.code-workspace create mode 100644 .gitpod/ignore create mode 100644 .gitpod/launch.json create mode 100644 .gitpod/setup.sh create mode 100644 .gitpod/start.sh diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..dcec345 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,21 @@ +--- +# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/ +tasks: + - init: sh -x ./.gitpod/setup.sh + command: pwd; sh -x /workspace/*/.gitpod/start.sh + env: + REDMINE_VERSION: '5.0-stable' + +# List the ports to expose. Learn more https://www.gitpod.io/docs/config-ports/ +ports: + - port: 3000 + onOpen: open-browser + +workspaceLocation: "./redmine" + +vscode: + extensions: + - bung87.rails + - rebornix.ruby + - aliariff.vscode-erb-beautify + - mbessey.vscode-rufo diff --git a/.gitpod/database.yml b/.gitpod/database.yml new file mode 100644 index 0000000..1a3e46e --- /dev/null +++ b/.gitpod/database.yml @@ -0,0 +1,19 @@ +# Default setup is given for MySQL 5.7.7 or later. +# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end. +# Line indentation must be 2 spaces (no tabs). + +production: + adapter: sqlite3 + database: db/redmine.sqlite3 + +development: + adapter: sqlite3 + database: db/redmine_dev.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: sqlite3 + database: db/redmine_test.sqlite3 + diff --git a/.gitpod/gitpod.code-workspace b/.gitpod/gitpod.code-workspace new file mode 100644 index 0000000..a1c8c10 --- /dev/null +++ b/.gitpod/gitpod.code-workspace @@ -0,0 +1,11 @@ +{ + "folders": [ + { + "path": "." + }, + { + "path": "../__PLUGIN__NAME" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/.gitpod/ignore b/.gitpod/ignore new file mode 100644 index 0000000..0cebdb5 --- /dev/null +++ b/.gitpod/ignore @@ -0,0 +1,2 @@ +.vscode/launch.json +/gitpod.code-workspace diff --git a/.gitpod/launch.json b/.gitpod/launch.json new file mode 100644 index 0000000..92eeb72 --- /dev/null +++ b/.gitpod/launch.json @@ -0,0 +1,32 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Rails server", + "type": "Ruby", + "request": "launch", + "program": "${workspaceRoot}/bin/rails", + "args": [ + "server" + ], + "useBundler": true + }, + { + "name": "Plugin test", + "type": "Ruby", + "request": "launch", + "program": "${workspaceRoot}/bin/rake", + "args": [ + "redmine:plugins:test" + ], + "env": { + "RAILS_ENV": "test" + }, + "useBundler": true + } + ] +} \ No newline at end of file diff --git a/.gitpod/setup.sh b/.gitpod/setup.sh new file mode 100644 index 0000000..cb518eb --- /dev/null +++ b/.gitpod/setup.sh @@ -0,0 +1,30 @@ +#!/bin/sh +cd $(dirname "$0") || exit +GITPODDIR=$(pwd) +IGNOREDIR="$HOME"/.config/git +mkdir -p "$IGNOREDIR" +cp "$GITPODDIR"/ignore "$IGNOREDIR" +cd .. +BASEDIR=$(pwd) + +if [ -f Gemfile_for_test ]; then + cp Gemfile_for_test Gemfile +fi +cd .. +REDMINEDIR=$(pwd)/redmine +if [ ! -d redmine ]; then + git clone https://github.com/redmine/redmine.git -b "$REDMINE_VERSION" + cd redmine || exit + mv .git .git.org + cd "$REDMINEDIR"/plugins || exit + ln -s "$BASEDIR" . + cp "$GITPODDIR"/database.yml "$REDMINEDIR"/config/ + mkdir "$REDMINEDIR"/.vscode + cd "$REDMINEDIR"/.vscode || exit + ln -s "$GITPODDIR"/launch.json . + echo "gem 'ruby-debug-ide'" >> "$REDMINEDIR"/Gemfile + echo "gem 'debase'" >> "$REDMINEDIR"/Gemfile + sed -i 's/^end$/ config.hosts.clear\nend/' "$REDMINEDIR"/config/environments/development.rb +fi + + diff --git a/.gitpod/start.sh b/.gitpod/start.sh new file mode 100644 index 0000000..48ddb29 --- /dev/null +++ b/.gitpod/start.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +REDMINEDIR=/workspace/redmine +cd $(dirname "$0") || exit +GITPODDIR=$(pwd) +cd .. +BASEDIR=$(pwd) +PLUGIN_NAME=$(basename "$BASEDIR") + +cd "$REDMINEDIR" || exit +sed "s/__PLUGIN__NAME/$PLUGIN_NAME/" "$GITPODDIR"/gitpod.code-workspace > "$REDMINEDIR"/gitpod.code-workspace +gem install ruby-debug-ide +bundle install --path vendor/bundle +bundle exec rake db:migrate +bundle exec rake redmine:plugins:migrate +bundle exec rake db:migrate RAILS_ENV=test +bundle exec rake redmine:plugins:migrate RAILS_ENV=test \ No newline at end of file From 988604626e240444d44d961a774f69fa775799da Mon Sep 17 00:00:00 2001 From: Haruyuki Iida Date: Fri, 8 Jul 2022 07:52:46 +0900 Subject: [PATCH 3/5] remove ruby 2.5 from master branch test environment. --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 794519a..41d17ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,8 @@ jobs: redmine_version: master - ruby_version: 2.4 redmine_version: 5.0-stable + - ruby_version: 2.5 + redmine_version: master - ruby_version: 2.7 redmine_version: 4.1-stable - ruby_version: 3.0 From f95ceca7868aca6a706a412fc2e650fc0a5aff08 Mon Sep 17 00:00:00 2001 From: Haru Iida Date: Sat, 16 Jul 2022 06:11:26 +0000 Subject: [PATCH 4/5] fix javascript injection problem --- .gitpod/launch.json | 1 + app/controllers/wiki_extensions_controller.rb | 17 ++++++++++++++++- app/views/wiki_extensions/_html_header.html.erb | 4 +--- config/routes.rb | 1 + .../wiki_extensions_controller_test.rb | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/.gitpod/launch.json b/.gitpod/launch.json index 92eeb72..f2f4335 100644 --- a/.gitpod/launch.json +++ b/.gitpod/launch.json @@ -4,6 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": "Rails server", diff --git a/app/controllers/wiki_extensions_controller.rb b/app/controllers/wiki_extensions_controller.rb index 896e6c3..146b595 100644 --- a/app/controllers/wiki_extensions_controller.rb +++ b/app/controllers/wiki_extensions_controller.rb @@ -19,7 +19,8 @@ class WikiExtensionsController < ApplicationController unloadable menu_item :wiki - before_action :find_project, :authorize, :find_user + before_action :find_project, :find_user + before_action :authorize, except: :stylesheet def add_comment @@ -101,6 +102,20 @@ def vote render :inline => " #{vote.count}" end + + def stylesheet + stylesheet = WikiPage.find_by(wiki_id: @project.wiki.id, title: "StyleSheet") + unless stylesheet + render_404 + return + end + + unless stylesheet.visible? + render_403 + return + end + render plain: stylesheet.content.text, content_type: 'text/css' + end private def find_project diff --git a/app/views/wiki_extensions/_html_header.html.erb b/app/views/wiki_extensions/_html_header.html.erb index 0e49469..123c9fa 100644 --- a/app/views/wiki_extensions/_html_header.html.erb +++ b/app/views/wiki_extensions/_html_header.html.erb @@ -24,9 +24,7 @@ -%> <% if style_sheet -%> - + <%= stylesheet_link_tag( wiki_extensions_stylesheet_path(@project)) %> <% end -%> diff --git a/config/routes.rb b/config/routes.rb index 6ff0a88..b9603a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do + match 'projects/:id/wiki_extensions/stylesheet', to: 'wiki_extensions#stylesheet', via: [:get, :post], as: 'wiki_extensions_stylesheet' match 'projects/:id/wiki_extensions/:action', :controller => 'wiki_extensions', :via => [:get, :post] match 'projects/:id/wiki_extensions_settings/:action', :controller => 'wiki_extensions_settings', :via => [:get, :post, :put, :patch] end diff --git a/test/functional/wiki_extensions_controller_test.rb b/test/functional/wiki_extensions_controller_test.rb index 106885c..41b86ec 100644 --- a/test/functional/wiki_extensions_controller_test.rb +++ b/test/functional/wiki_extensions_controller_test.rb @@ -93,6 +93,20 @@ def test_forwad_wiki_page assert_response :redirect end + def test_stylesheet + @project.is_public = false + @project.save! + get :stylesheet, :params => { :id => 1 } + assert_response 403 + + @request.session[:user_id] = 1 + get :stylesheet, :params => { :id => 1 } + assert_response :success + + get :stylesheet, :params => { :id => 2 } + assert_response 404 + end + context 'vote' do should 'success if new vote.' do @request.session[:user_id] = 1 From bf86ce6b82fab99e0295e737d646335cd7fd1a31 Mon Sep 17 00:00:00 2001 From: Haru Iida Date: Sat, 16 Jul 2022 06:26:14 +0000 Subject: [PATCH 5/5] change version to 0.9.4 --- init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.rb b/init.rb index c7064c8..c3e9196 100644 --- a/init.rb +++ b/init.rb @@ -42,7 +42,7 @@ author_url 'http://twitter.com/haru_iida' description 'This is a Wiki Extensions plugin for Redmine' url 'http://www.r-labs.org/projects/r-labs/wiki/Wiki_Extensions_en' - version '0.9.3' + version '0.9.4' requires_redmine :version_or_higher => '4.0.0' project_module :wiki_extensions do