Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test
on:
push:
branches-ignore: [debian]

jobs:
test:
name: ${{ matrix.redmine }} on ${{ matrix.ruby }}
runs-on: ubuntu-latest

strategy:
matrix:
include:
- ruby: "2.7"
redmine: "4.2.1"
- ruby: "2.6"
redmine: "4.1.3"
fail-fast: false

env:
BUNDLE_JOBS: 4
BUNDLE_PATH: ${{ github.workspace }}/vendor/bundle
BUNDLE_RETRY: 3
BUNDLE_WITHOUT: development
REDMINE_VERSION: ${{ matrix.redmine }}

steps:
- uses: actions/checkout@master

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- name: setup cache
uses: actions/cache@v1
with:
path: vendor
# Updating v<x> to v<x+1> clear the cache
key: v4-ruby-${{ matrix.ruby }}-redmine-${{ matrix.redmine }}

- name: install ruby dependencies
run: bundle install

- name: setup redmine ${{ matrix.redmine }}
run: ./redmine update

- name: run prepare tests
run: ./redmine exec bundle exec rake db:test:prepare

- name: run plugins tests
run: ./redmine exec bundle exec rake redmine:plugins:test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.bundle
Gemfile.lock
vendor
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
gem 'netaddr'
source 'https://rubygems.org'
# as version 2.0. is A complete rewrite and totally incompatible with 1.x. My main motivation now is to reduce bug reports resulting from the poor code quality of 1.x.
# gem 'netaddr'
gem 'netaddr', '< 2.0.0'
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Redmine Access filters plugin

This plugin allows you to deny web or REST API access from specific IP addresses for specific users and groups

## Requirements

* Redmine 2.3+
* Ruby 1.8.7, 1.9.3, 2.0.0

## Installation and Setup

* Follow the Redmine plugin installation steps at http://www.redmine.org/wiki/redmine/Plugins
* Restart your Redmine web servers (e.g. mongrel, thin, passenger)

## License

This plugin is licensed under the GNU GPL v2. See COPYRIGHT.txt and GPL.txt for details.

## Sponsorship

Pluing development was sponsored by MEDEVIT (http://www.medevit.at)

## Testing

Checkout a redmine version, clone this plugin under plugins/redmine_acess_filters
and run

export RAILS_ENV=test
bundle install
bundle exec rake redmine:plugins NAME=redmine_access_filters
bundle exec rake db:test:prepare
bundle exec rake redmine:plugins:test
# run a single test
bundle exec ruby plugins/redmine_access_filters/test/functional/access_filter_test.rb -n test_works_if_no_rules_exist

## github Actions

For unknown reason Niklaus was unable to make the github actions pass (August 21).
Running the tests locally worked fine, but on github I got always the error
messages containing `redirect to <http://test.host`. Have no idea, where and why
this redirection takes place.
21 changes: 0 additions & 21 deletions README.rdoc

This file was deleted.

4 changes: 2 additions & 2 deletions app/controllers/access_filters_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AccessFiltersController < ApplicationController
before_filter :require_admin
before_action :require_admin

def index
@access_filters = AccessFilter.order(:position).all
Expand Down Expand Up @@ -36,4 +36,4 @@ def destroy
@access_filter.destroy
redirect_to access_filters_path
end
end
end
4 changes: 2 additions & 2 deletions app/models/access_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AccessFilter < ActiveRecord::Base

validate :parsable_cidrs

acts_as_list
acts_as_tree

# That is to clear cache on startup
Rails.cache.delete(:access_filters)
Expand Down Expand Up @@ -50,4 +50,4 @@ def parsable_cidrs
end
end
end
end
end
4 changes: 2 additions & 2 deletions app/views/access_filters/_access_filter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
<%= access_filter.cidrs %>
</td>
<td>
<%= reorder_links('access_filter', {:action => 'update', :id => access_filter }, :put) %>
<%= reorder_handle(access_filter, :param => :put) %>
</td>
<td>
<%= link_to l(:label_access_filters_edit), edit_access_filter_path(access_filter), :class => 'icon icon-edit' %>
<%= link_to l(:label_access_filters_delete), access_filter_path(access_filter), :method => :delete, :confirm => l(:label_access_filters_delete_confirmation), :class => 'icon icon-del' %>
</td>
</tr>
</tr>
4 changes: 2 additions & 2 deletions db/migrate/001_create_access_filters.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateAccessFilters < ActiveRecord::Migration
class CreateAccessFilters < ActiveRecord::Migration[5.2]
def change
create_table :access_filters do |t|
t.references :user
Expand All @@ -7,4 +7,4 @@ def change
t.text :cidrs
end
end
end
end
4 changes: 2 additions & 2 deletions db/migrate/002_add_active_flag_to_access_filters.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AddActiveFlagToAccessFilters < ActiveRecord::Migration
class AddActiveFlagToAccessFilters < ActiveRecord::Migration[5.2]
def change
add_column :access_filters, :active, :boolean, :default => true
end
end
end
4 changes: 2 additions & 2 deletions db/migrate/003_add_position_to_access_filters.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AddPositionToAccessFilters < ActiveRecord::Migration
class AddPositionToAccessFilters < ActiveRecord::Migration[5.2]
def change
add_column :access_filters, :position, :integer, :default => 0
end
end
end
4 changes: 2 additions & 2 deletions db/migrate/004_add_polymorphism_to_access_filters.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class AddPolymorphismToAccessFilters < ActiveRecord::Migration
class AddPolymorphismToAccessFilters < ActiveRecord::Migration[5.2]
def change
add_column :access_filters, :owner_type, :string
add_column :access_filters, :owner_id, :integer
remove_column :access_filters, :user_id
end
end
end
8 changes: 4 additions & 4 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
name 'Redmine Access Filters plugin'
author 'Redmine CRM'
description 'Allows setting access filters for API and regular browser access per user'
version '0.0.1'
url 'http://redminecrm.com'
author_url 'mailto:[email protected]'
version '1.0.1'
url 'https://github.com/ngiger/redmine_access_filters'
author_url 'mailto:[email protected]'
menu :admin_menu, :access_filters,
{:controller => 'access_filters', :action => 'index'},
:caption => :label_access_filters_plural

end

require 'redmine_access_filters'
require 'redmine_access_filters'
2 changes: 1 addition & 1 deletion lib/redmine_access_filters.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require 'redmine_access_filters/patches/application_controller_patch'
require 'redmine_access_filters/hooks/view_layouts_hook'
require 'redmine_access_filters/hooks/view_layouts_hook'
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.included(base)
base.send(:include, InstanceMethods)

base.class_eval do
before_filter :apply_access_filters
before_action :apply_access_filters
end
require "#{Rails.root}/plugins/redmine_access_filters/app/models/access_filter"
end
Expand Down Expand Up @@ -55,4 +55,4 @@ def access_filters

unless ApplicationController.included_modules.include?(RedmineAccessFilters::Patches::ApplicationControllerPatch)
ApplicationController.send(:include, RedmineAccessFilters::Patches::ApplicationControllerPatch)
end
end
53 changes: 53 additions & 0 deletions redmine
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

REDMINE_VERSION = ENV['REDMINE_VERSION'] = ENV['REDMINE_VERSION'] || ENV['VERSION'] || '4.1.3'
REDMINE_PATH = ENV['REDMINE_PATH'] = File.expand_path("../vendor/redmine/#{REDMINE_VERSION}/", __FILE__)
REDMINE_EXEC = ENV['REDMINE_EXEC'] = File.expand_path(__FILE__)
PLUGIN_PATH = ENV['PLUGIN_PATH'] = File.expand_path(__dir__)

require 'pathname'

SCRIPT_PATH = Pathname.new(__FILE__).expand_path.parent.join('scripts')

def help
<<-HELP.gsub(/^\s{4}/, '')
Available commands:
#{available_commands.join("\n ")}
HELP
end

def available_commands
SCRIPT_PATH.children
.select(&:file?)
.select(&:executable?)
.map(&:basename)
.map(&:to_s)
end

def handle_command(cmd, _argv)
unless ARGV[0] =~ /\A(\w+)\z/
warn "Invalid command: #{ARGV[0]}"
warn help
Kernel.exit 1
end

command = SCRIPT_PATH.join(cmd.to_s)

if command.file? && command.executable?
Kernel.exec command.to_s, *ARGV[1..-1]
else
warn "Unknown command: #{ARGV[0]}"
warn help
Kernel.exit 1
end
end

case ARGV[0]
when '-h', '--help', nil
$stdout.puts help
when 'exec'
Dir.chdir(REDMINE_PATH) { Kernel.exec(*ARGV[1..-1]) }
else
handle_command ARGV[0], ARGV[1..-1]
end
55 changes: 55 additions & 0 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

set -e

[ -z "$PLUGIN_PATH" ] && exit 1
[ -z "$REDMINE_EXEC" ] && exit 1
[ -z "$REDMINE_PATH" ] && exit 1
[ -z "$REDMINE_VERSION" ] && exit 1

mkdir -p "${REDMINE_PATH}"
mkdir -p tmp log

case ${REDMINE_VERSION} in
master)
REDMINE_SOURCE="http://svn.redmine.org/redmine/trunk"
;;

*)
REDMINE_SOURCE="http://svn.redmine.org/redmine/tags/${REDMINE_VERSION}"
;;
esac

(set -x; svn export --quiet --force "${REDMINE_SOURCE}" "${REDMINE_PATH}")

echo "Symlink plugin, assets and specs..."

mkdir -p ${REDMINE_PATH}/public/plugin_assets

if [ ! -L "${REDMINE_PATH}/plugins/redmine_access_filters" ]; then
ln -s "${PLUGIN_PATH}" "${REDMINE_PATH}/plugins/redmine_access_filters"
fi

if [ ! -L "${REDMINE_PATH}/spec" ]; then
ln -s "${PLUGIN_PATH}/spec" "${REDMINE_PATH}/spec"
fi

if [ ! -L "${REDMINE_PATH}/test/fixtures/rdb" ]; then
ln -s "${PLUGIN_PATH}/spec/fixtures" "${REDMINE_PATH}/test/fixtures/rdb"
fi

if [ ! -L "${REDMINE_PATH}/public/plugin_assets/redmine_access_filters_linked" ]; then
ln -s "${PLUGIN_PATH}/assets" "${REDMINE_PATH}/public/plugin_assets/redmine_access_filters_linked"
fi

echo "Copy database configuration..."

(set -x; cp -v $PLUGIN_PATH/test/database.yml "$REDMINE_PATH"/config/ )

pushd "${REDMINE_PATH}"

(set -x; bundle config set --local without 'rmagick' ${BUNDLE_OPTS})
(set -x; bundle install --without rmagick --jobs=3 --retry=3 ${BUNDLE_OPTS})
(set -x; bundle exec rake generate_secret_token db:create:all db:migrate redmine:plugins:migrate db:test:prepare)

popd
22 changes: 22 additions & 0 deletions scripts/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

[ -z "$PLUGIN_PATH" ] && exit 1
[ -z "$REDMINE_EXEC" ] && exit 1
[ -z "$REDMINE_PATH" ] && exit 1
[ -z "$REDMINE_VERSION" ] && exit 1

if [ ! -d "${REDMINE_PATH}" ]; then
exec $REDMINE_EXEC install
fi

pushd "${REDMINE_PATH}"

if [ "${REDMINE_VERSION}" == "master" ]; then
(set -x; svn export --quiet --force "${REDMINE_SOURCE}" .)
fi

(set -x; bundle update --jobs=3 --retry=3)
pwd
(set -x; bundle exec rake db:create:all db:migrate redmine:plugins:migrate db:test:prepare)
13 changes: 13 additions & 0 deletions test/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Line indentation must be 2 spaces (no tabs).
production:
adapter: sqlite3
database: db/redmine_production.sqlite3

development:
adapter: sqlite3
database: db/redmine_development.sqlite3

test:
adapter: sqlite3
database: db/redmine_test.sqlite3

Loading