diff --git a/.github/workflows/4_2_11.yml b/.github/workflows/4_2_11.yml index 749b0de..04db344 100644 --- a/.github/workflows/4_2_11.yml +++ b/.github/workflows/4_2_11.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - ruby: ['2.7'] + ruby: ['3.2'] db: ['postgres'] fail-fast: false @@ -37,7 +37,7 @@ jobs: steps: - name: Checkout Redmine - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: redmine/redmine ref: ${{ env.REDMINE_VERSION }} @@ -48,7 +48,7 @@ jobs: - name: Install package dependencies run: > - sudo apt-get install --yes --quiet + sudo apt-get update && sudo apt-get install --yes --quiet build-essential cmake libicu-dev @@ -81,7 +81,7 @@ jobs: run: gem install bundler -v '~> 1.0' - name: Checkout dependencies - Base RSpec plugin - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: jbbarth/redmine_base_rspec path: redmine/plugins/redmine_base_rspec @@ -114,7 +114,7 @@ jobs: bundle exec rails test:scm:setup:subversion - name: Checkout plugin - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: redmine/plugins/${{ env.PLUGIN_NAME }} diff --git a/.github/workflows/5_0_6.yml b/.github/workflows/5_0_6.yml index 8ea8ab5..57d7c3b 100644 --- a/.github/workflows/5_0_6.yml +++ b/.github/workflows/5_0_6.yml @@ -37,7 +37,7 @@ jobs: steps: - name: Checkout Redmine - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: redmine/redmine ref: ${{ env.REDMINE_VERSION }} @@ -48,7 +48,7 @@ jobs: - name: Install package dependencies run: > - sudo apt-get install --yes --quiet + sudo apt-get update && sudo apt-get install --yes --quiet build-essential cmake libicu-dev @@ -81,7 +81,7 @@ jobs: run: gem install bundler -v '~> 1.0' - name: Checkout dependencies - Base RSpec plugin - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: jbbarth/redmine_base_rspec path: redmine/plugins/redmine_base_rspec @@ -114,7 +114,7 @@ jobs: bundle exec rails test:scm:setup:subversion - name: Checkout plugin - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: redmine/plugins/${{ env.PLUGIN_NAME }} diff --git a/.github/workflows/5_1_4.yml b/.github/workflows/5_1_4.yml new file mode 100644 index 0000000..a8ca41d --- /dev/null +++ b/.github/workflows/5_1_4.yml @@ -0,0 +1,147 @@ +name: Tests 5.1.4 + +env: + PLUGIN_NAME: redmine_base_deface + REDMINE_VERSION: 5.1.4 + RAILS_ENV: test + +on: + push: + pull_request: + +jobs: + test: + name: ${{ github.workflow }} ${{ matrix.db }} ruby-${{ matrix.ruby }} + runs-on: ubuntu-latest + + strategy: + matrix: + ruby: ['3.2'] + db: ['postgres'] + fail-fast: false + + services: + postgres: + image: postgres:13 + env: + POSTGRES_DB: redmine + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout Redmine + uses: actions/checkout@v4 + with: + repository: redmine/redmine + ref: ${{ env.REDMINE_VERSION }} + path: redmine + + - name: Update package archives + run: sudo apt-get update --yes --quiet + + - name: Install package dependencies + run: > + sudo apt-get update && sudo apt-get install --yes --quiet + build-essential + cmake + libicu-dev + libpq-dev + ghostscript + gsfonts + + - name: Set up chromedriver + uses: nanasess/setup-chromedriver@master + - run: | + export DISPLAY=:99 + chromedriver --url-base=/wd/hub & + sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional + + - name: Allow imagemagick to read PDF files + run: | + echo '' > policy.xml + echo '' >> policy.xml + echo '' >> policy.xml + sudo rm /etc/ImageMagick-6/policy.xml + sudo mv policy.xml /etc/ImageMagick-6/policy.xml + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + + - name: Setup Bundler + run: gem install bundler -v '~> 1.0' + + - name: Checkout dependencies - Base RSpec plugin + uses: actions/checkout@v4 + with: + repository: jbbarth/redmine_base_rspec + path: redmine/plugins/redmine_base_rspec + + - name: Prepare Redmine source + working-directory: redmine + run: | + sed -i '/rubocop/d' Gemfile + rm -f .rubocop* + cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml + + - name: Install Ruby dependencies + working-directory: redmine + run: | + bundle install --jobs=4 --retry=3 --without development + + - name: Generate session store secret + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle exec rake generate_secret_token + + - name: Run Redmine DB and migration tasks + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle exec rake db:create db:migrate + bundle exec rails test:scm:setup:subversion + + - name: Checkout plugin + uses: actions/checkout@v4 + with: + path: redmine/plugins/${{ env.PLUGIN_NAME }} + + - name: Install plugins dependencies and run plugins migrations + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle install --jobs=4 --retry=3 --without development + bundle exec rake redmine:plugins:migrate + # cp -i plugins/*/spec/fixtures/*yml test/fixtures/ + bundle exec rails db:fixtures:load + + - name: Run core tests + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rails test + + - name: Run plugin tests + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rails redmine:plugins:test NAME=${{ env.PLUGIN_NAME }} RUBYOPT="-W0" + + - name: Run uninstall test + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rake redmine:plugins:migrate NAME=${{ env.PLUGIN_NAME }} VERSION=0 diff --git a/.github/workflows/6_0_1.yml b/.github/workflows/6_0_1.yml new file mode 100644 index 0000000..8533986 --- /dev/null +++ b/.github/workflows/6_0_1.yml @@ -0,0 +1,147 @@ +name: Tests 6.0.1 + +env: + PLUGIN_NAME: redmine_base_deface + REDMINE_VERSION: 6.0.1 + RAILS_ENV: test + +on: + push: + pull_request: + +jobs: + test: + name: ${{ github.workflow }} ${{ matrix.db }} ruby-${{ matrix.ruby }} + runs-on: ubuntu-latest + + strategy: + matrix: + ruby: ['3.3'] + db: ['postgres'] + fail-fast: false + + services: + postgres: + image: postgres:13 + env: + POSTGRES_DB: redmine + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout Redmine + uses: actions/checkout@v4 + with: + repository: redmine/redmine + ref: ${{ env.REDMINE_VERSION }} + path: redmine + + - name: Update package archives + run: sudo apt-get update --yes --quiet + + - name: Install package dependencies + run: > + sudo apt-get update && sudo apt-get install --yes --quiet + build-essential + cmake + libicu-dev + libpq-dev + ghostscript + gsfonts + + - name: Set up chromedriver + uses: nanasess/setup-chromedriver@master + - run: | + export DISPLAY=:99 + chromedriver --url-base=/wd/hub & + sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional + + - name: Allow imagemagick to read PDF files + run: | + echo '' > policy.xml + echo '' >> policy.xml + echo '' >> policy.xml + sudo rm /etc/ImageMagick-6/policy.xml + sudo mv policy.xml /etc/ImageMagick-6/policy.xml + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + + - name: Setup Bundler + run: gem install bundler -v '~> 1.0' + + - name: Checkout dependencies - Base RSpec plugin + uses: actions/checkout@v4 + with: + repository: jbbarth/redmine_base_rspec + path: redmine/plugins/redmine_base_rspec + + - name: Prepare Redmine source + working-directory: redmine + run: | + sed -i '/rubocop/d' Gemfile + rm -f .rubocop* + cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml + + - name: Install Ruby dependencies + working-directory: redmine + run: | + bundle install --jobs=4 --retry=3 --without development + + - name: Generate session store secret + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle exec rake generate_secret_token + + - name: Run Redmine DB and migration tasks + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle exec rake db:create db:migrate + bundle exec rails test:scm:setup:subversion + + - name: Checkout plugin + uses: actions/checkout@v4 + with: + path: redmine/plugins/${{ env.PLUGIN_NAME }} + + - name: Install plugins dependencies and run plugins migrations + env: + RAILS_ENV: test + working-directory: redmine + run: | + bundle install --jobs=4 --retry=3 --without development + bundle exec rake redmine:plugins:migrate + # cp -i plugins/*/spec/fixtures/*yml test/fixtures/ + bundle exec rails db:fixtures:load + + - name: Run core tests + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rails test + + - name: Run plugin tests + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rails redmine:plugins:test NAME=${{ env.PLUGIN_NAME }} RUBYOPT="-W0" + + - name: Run uninstall test + env: + RAILS_ENV: test + working-directory: redmine + run: bundle exec rake redmine:plugins:migrate NAME=${{ env.PLUGIN_NAME }} VERSION=0 diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index ef0e421..08ebb86 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - ruby: ['2.7'] + ruby: ['3.3'] db: ['postgres'] fail-fast: false @@ -37,7 +37,7 @@ jobs: steps: - name: Checkout Redmine - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: redmine/redmine ref: ${{ env.REDMINE_VERSION }} @@ -48,7 +48,7 @@ jobs: - name: Install package dependencies run: > - sudo apt-get install --yes --quiet + sudo apt-get update && sudo apt-get install --yes --quiet build-essential cmake libicu-dev @@ -81,7 +81,7 @@ jobs: run: gem install bundler -v '~> 1.0' - name: Checkout dependencies - Base RSpec plugin - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: jbbarth/redmine_base_rspec path: redmine/plugins/redmine_base_rspec @@ -114,7 +114,7 @@ jobs: bundle exec rails test:scm:setup:subversion - name: Checkout plugin - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: redmine/plugins/${{ env.PLUGIN_NAME }} diff --git a/.gitignore b/.gitignore index c7da51e..942a75d 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,15 @@ -.history +.buildpath .byebug_history +.metadata/ +.project +Gemfile.lock +config/ +db/ +files/ +log/ +public/ +tmp/ + +.history tmp .ruby-lsp diff --git a/PluginGemfile b/PluginGemfile new file mode 100644 index 0000000..3f43f8b --- /dev/null +++ b/PluginGemfile @@ -0,0 +1 @@ +gem 'deface', '~> 1.9.0' diff --git a/README.md b/README.md index 3d6a2fd..1da9896 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Installation This plugin is compatible with Redmine 2.1.0+. -Please apply general instructions for plugins [here](http://www.redmine.org/wiki/redmine/Plugins). +Please apply general instructions for plugins [here](https://www.redmine.org/projects/redmine/wiki/Plugins). First download the source or clone the plugin and put it in the "plugins/" directory of your redmine instance. Note that this is crucial that the directory is named redmine_base_deface ! @@ -24,12 +24,12 @@ Test status |Plugin branch| Redmine Version | Test Status | |-------------|-----------------|-------------------| -|master | 5.0.6 | [![5.0.6][1]][5] | -|master | 4.2.11 | [![4.2.11][2]][5] | +|master | 6.0.1 | [![6.0.1][1]][5] | +|master | 5.1.4 | [![5.1.4][2]][5] | |master | master | [![master][4]][5] | -[1]: https://github.com/jbbarth/redmine_base_deface/actions/workflows/5_0_6.yml/badge.svg -[2]: https://github.com/jbbarth/redmine_base_deface/actions/workflows/4_2_11.yml/badge.svg +[1]: https://github.com/jbbarth/redmine_base_deface/actions/workflows/6_0_1.yml/badge.svg +[2]: https://github.com/jbbarth/redmine_base_deface/actions/workflows/5_1_4.yml/badge.svg [4]: https://github.com/jbbarth/redmine_base_deface/actions/workflows/master.yml/badge.svg [5]: https://github.com/jbbarth/redmine_base_deface/actions diff --git a/init.rb b/init.rb index 3543456..cc0bd90 100755 --- a/init.rb +++ b/init.rb @@ -4,7 +4,7 @@ name 'Redmine Base Deface plugin' author 'Jean-Baptiste BARTH' description 'This is a plugin for Redmine' - version '1.8.2-xmr-1' + version '6.0.1' url 'https://github.com/jbbarth/redmine_base_deface' author_url 'jeanbaptiste.barth@gmail.com' # doesn't work since redmine evaluates dependencies as it loads, and loads in lexical order @@ -23,6 +23,10 @@ load File.expand_path(path, __FILE__) end + Dir.glob("#{Rails.root}/plugins/*/app/overrides/**/*.deface").each do |path| + Deface::DSL::Loader::load File.expand_path(path, __FILE__) + end + Rails.application.config.after_initialize do require_relative 'lib/applicator_patch' end diff --git a/lib/applicator_patch.rb b/lib/applicator_patch.rb index dbbf8ca..034337a 100644 --- a/lib/applicator_patch.rb +++ b/lib/applicator_patch.rb @@ -6,64 +6,45 @@ module Deface module Applicator module ClassMethods - # applies all applicable overrides to given source - # - def apply(source, details, log = true, syntax = :erb) - overrides = find(details) + # applies specified overrides to given source + def apply_overrides(source, overrides:, log: true) - if log && overrides.size > 0 - Rails.logger.debug "\e[1;32mDeface:\e[0m #{overrides.size} overrides found for '#{details[:virtual_path]}'" - end + doc = Deface::Parser.convert(source) - unless overrides.empty? - case syntax - when :haml - #convert haml to erb before parsing before - source = Deface::HamlConverter.new(source.to_param).result - when :slim - source = Deface::SlimConverter.new(source.to_param).result + overrides.each do |override| + if override.disabled? + Rails.logger.debug("\e[1;32mDeface:\e[0m '#{override.name}' is disabled") if log + next end - doc = Deface::Parser.convert(source) - - overrides.each do |override| - if override.disabled? - Rails.logger.debug("\e[1;32mDeface:\e[0m '#{override.name}' is disabled") if log - next - end + override.parsed_document = doc + matches = override.matcher.matches(doc, log) - override.parsed_document = doc - matches = override.matcher.matches(doc, log) + if log + Rails.logger.send(matches.size == 0 ? :error : :debug, "\e[1;32mDeface:\e[0m '#{override.name}' matched #{matches.size} times with '#{override.selector}'") - if log - Rails.logger.send(matches.size == 0 ? :error : :debug, "\e[1;32mDeface:\e[0m '#{override.name}' matched #{matches.size} times with '#{override.selector}'") - - # temporarily check and notify on use of old selector styles. - # - if matches.empty? && override.selector.match(/code|erb-loud|erb-silent/) - Rails.logger.error "\e[1;32mDeface: [WARNING]\e[0m Override '#{override.name}' may be using an invalid selector of '#{override.selector}', tags are now " - end - end - - if matches.empty? - override.failure = "failed to match :#{override.action} selector '#{override.selector}'" - else - override.failure = nil - matches.each { |match| override.execute_action match } + # temporarily check and notify on use of old selector styles. + # + if matches.empty? && override.selector.match(/code|erb-loud|erb-silent/) + Rails.logger.error "\e[1;32mDeface: [WARNING]\e[0m Override '#{override.name}' may be using an invalid selector of '#{override.selector}', tags are now " end end - # Prevents any caching by rails in development mode. - details[:updated_at] = Time.now if Deface.before_rails_6? + if matches.empty? + override.failure = "failed to match :#{override.action} selector '#{override.selector}'" + else + override.failure = nil + matches.each {|match| override.execute_action match } + end + end - ############################### - ### START PATCH - source = CGI.unescapeHTML doc.to_s - ### END PATCH - ############################### + ############################### + ### START PATCH + source = CGI.unescapeHTML doc.to_s + ### END PATCH + ############################### - Deface::Parser.undo_erb_markup!(source) - end + Deface::Parser.undo_erb_markup!(source) source end