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

Redmine 4.0 support #45

Closed
dktcoding opened this Issue Dec 10, 2018 · 26 comments

Comments

Projects
None yet
4 participants
@dktcoding
Copy link
Contributor

dktcoding commented Dec 10, 2018

Hi!

Are there any plans on supporting Redmine 4.0?

rake aborted!
NoMethodError: undefined method `attr_accessible' for #<Class:0x0000561b2eb17110>
Did you mean?  attr_accessor
/var/lib/gems/2.5.0/gems/activerecord-5.2.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/home/redmine/redmine-4.0.0/plugins/vault/app/models/vault/key.rb:10:in `<class:Key>'
/home/redmine/redmine-4.0.0/plugins/vault/app/models/vault/key.rb:5:in `<module:Vault>'
/home/redmine/redmine-4.0.0/plugins/vault/app/models/vault/key.rb:1:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/redmine/redmine-4.0.0/plugins/vault/lib/vault.rb:1:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:378:in `block in require_or_load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `block in load_interlock'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:13:in `loading'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `load_interlock'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:356:in `require_or_load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:334:in `depend_on'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:246:in `require_dependency'
/home/redmine/redmine-4.0.0/plugins/vault/lib/project_patch.rb:2:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:378:in `block in require_or_load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `block in load_interlock'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies/interlock.rb:13:in `loading'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:37:in `load_interlock'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:356:in `require_or_load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:334:in `depend_on'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:246:in `require_dependency'
/home/redmine/redmine-4.0.0/plugins/vault/init.rb:2:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
/home/redmine/redmine-4.0.0/lib/redmine/plugin.rb:173:in `block in load'
/home/redmine/redmine-4.0.0/lib/redmine/plugin.rb:164:in `each'
/home/redmine/redmine-4.0.0/lib/redmine/plugin.rb:164:in `load'
/home/redmine/redmine-4.0.0/config/initializers/30-redmine.rb:21:in `<top (required)>'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:657:in `block in load_config_initializer'
/var/lib/gems/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:170:in `instrument'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:656:in `load_config_initializer'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:613:in `each'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:613:in `block in <class:Engine>'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `each'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `tsort_each_child'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
/home/redmine/redmine-4.0.0/config/environment.rb:14:in `<top (required)>'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:337:in `require_environment!'
/var/lib/gems/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/var/lib/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
Tasks: TOP => redmine:plugins:migrate => environment
(See full trace by running task with --trace)
@dktcoding

This comment has been minimized.

Copy link
Contributor Author

dktcoding commented Dec 11, 2018

I've been playing a little bit with this:

Since attr_accessible was deprecated I added the protected_attributes_continued gem

diff --git a/Gemfile b/Gemfile
index 88fa2de..caaf4ba 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,4 @@
+gem 'protected_attributes_continued'
 gem 'roo'
 gem 'iconv'
 group :test, :development do

before_filter was also deprecated, but as I understand it, it's an "alias" of before_action, so:

diff --git a/app/controllers/vault_settings_controller.rb b/app/controllers/vault_settings_controller.rb
index 748454b..aaf25f2 100644
--- a/app/controllers/vault_settings_controller.rb
+++ b/app/controllers/vault_settings_controller.rb
@@ -6,7 +6,7 @@ class VaultSettingsController < ApplicationController
   menu_item :vault_settings

   layout 'admin'
-  before_filter :require_admin
+  before_action :require_admin

   def index

Now class_name requieres a string:

diff --git a/lib/project_patch.rb b/lib/project_patch.rb
index 8f7573b..cb7e929 100644
--- a/lib/project_patch.rb
+++ b/lib/project_patch.rb
@@ -4,7 +4,7 @@ require_dependency "#{Rails.root}/plugins/vault/lib/vault"
 module ProjectPatch
   def self.included(base)
     base.class_eval do
-      has_many :keys, class_name: Vault::Key
+      has_many :keys, class_name: Vault::Key.to_s
     end
   end
 end

This changes allowed installing but every time I click on the Keys tab:

Started GET "/projects/test-vault/keys" for 181.***.***.*** at 2018-12-10 21:19:34 -0300
Processing by KeysController#index as HTML
  Parameters: {"project_id"=>"test-vault"}
  Current user: fede (id=431)
Completed 500 Internal Server Error in 313ms (ActiveRecord: 302.2ms)

NameError (uninitialized constant #<Class:0x0000557e34102478>::Encryptor):

plugins/vault/app/models/vault/password.rb:13:in `decrypt!'
plugins/vault/app/controllers/keys_controller.rb:66:in `map'
plugins/vault/app/controllers/keys_controller.rb:66:in `index'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'

Any ideas?

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Dec 11, 2018

Sure we will implement this compatibility

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Dec 22, 2018

gem 'protected_attributes_continued' would't solve all problems
westonganger/protected_attributes_continued#9
we will continue working to migrate

@w0k3

This comment has been minimized.

Copy link

w0k3 commented Jan 5, 2019

@noshutdown-ru-user any news on this issue, please? We are very eager to run Redmine 4 and this is our only blocker. Is there anything we can do to help?

@w0k3

This comment has been minimized.

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 8, 2019

this is cool, then soon we will publish fix, hope in couple of days

@exsonox

This comment has been minimized.

Copy link

exsonox commented Jan 8, 2019

Is this related to v3.4 as well? Installed the plugin and when trying to access UI:

/usr/lib/ruby/vendor_ruby/rails/application.rb:352:in initialize!' /usr/share/redmine/config/environment.rb:14:in <top (required)>'
config.ru:3:in require' config.ru:3:in block in

'

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 9, 2019

Is this related to v3.4 as well? Installed the plugin and when trying to access UI:

/usr/lib/ruby/vendor_ruby/rails/application.rb:352:in initialize!' /usr/share/redmine/config/environment.rb:14:in <top (required)>'
config.ru:3:in require' config.ru:3:in block in

'

it shouldn't, can you paste more env details ?

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 9, 2019

you can try this branch

@exsonox

This comment has been minimized.

Copy link

exsonox commented Jan 9, 2019

Ah apologies and thank you!

@w0k3

This comment has been minimized.

Copy link

w0k3 commented Jan 9, 2019

Thank you @noshutdown-ru-user, tomorrow I'll give it a try.

@dktcoding

This comment has been minimized.

Copy link
Contributor Author

dktcoding commented Jan 9, 2019

Hi!

Just tried the redmine_v4 branch, it installs correctly, but on attempting to look at keys I got the following error (on a project that already had keys):

Started GET "/projects/**********/keys" for 181.---.---.--- at 2019-01-09 19:15:18 -0300
Processing by KeysController#index as HTML
  Parameters: {"project_id"=>"**********"}
  Current user: fede (id=10)
Completed 500 Internal Server Error in 26ms (ActiveRecord: 6.1ms)

NameError (uninitialized constant #<Class:0x000055dbd517e420>::Encryptor):

plugins/vault/app/models/vault/password.rb:14:in `decrypt!'
plugins/vault/app/controllers/keys_controller.rb:66:in `map'
plugins/vault/app/controllers/keys_controller.rb:66:in `index'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'

I tried again in a new project and got the following:

Started POST "/projects/*********/keys" for 181.---.---.--- at 2019-01-09 19:17:46 -0300
Processing by KeysController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"zmdLdAGsignZdyv8KK0G7X0NQHq3wzHlyKNnokaoM0Q/xuQze1HCzHKXNshuGLv3/DsKwaXem0zXZjoRkOFebA==", "vault_key"=>{"name"=>"Test", "login"=>"TestUser", "url"=>"https://www.example.com", "type"=>"Vault::Password", "body"=>"1234567890", "tags"=>"", "comment"=>""}, "commit"=>"Guardar", "project_id"=>"*********"}
  Current user: fede (id=10)
WARNING: Can't mass-assign protected attributes for Vault::Password: tags
	plugins/vault/app/controllers/keys_controller.rb:82:in `create'
	lib/redmine/sudo_mode.rb:63:in `sudo_mode'
Completed 500 Internal Server Error in 28ms (ActiveRecord: 6.6ms)

NameError (uninitialized constant #<Class:0x000055dbd517e420>::Encryptor):

plugins/vault/app/models/vault/password.rb:8:in `encrypt!'
plugins/vault/app/controllers/keys_controller.rb:91:in `block in create'
plugins/vault/app/controllers/keys_controller.rb:90:in `create'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 10, 2019

Aha so problem only with existed keys ?
In new project everything is ok ?

@w0k3

This comment has been minimized.

Copy link

w0k3 commented Jan 10, 2019

Looks like the main problem is the same with both new (empty) projects and old projects (with keys) - Encryptor is inaccessible.

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 10, 2019

Strange we tested it on clear installation by this repo: https://github.com/noshutdown-ru/vagrant_redmine
We will check it again

@w0k3

This comment has been minimized.

Copy link

w0k3 commented Jan 13, 2019

I gave it a shot and I got the error (NameError (uninitialized constant #<Class:0x00555a09e67c48>::Encryptor)) in following cases:

  • when I open Keys tab in existing project
  • when I try to save a new Key in new (empty) project
    • (displaying empty Keys list and New Key form works)
@w0k3

This comment has been minimized.

Copy link

w0k3 commented Jan 13, 2019

Until there is an official fix available, I've replaced 2 lines in app/models/vault/password.rb (WARNING: Obviously this only works if you are using Redmine encryption in Vault settings):

     def encrypt!
-      self.body = Encryptor::encrypt(self.body)
+      self.body = Redmine::Ciphering.encrypt_text(self.body).gsub(/\n/, '')
       self
     end
 
     #TODO: all data should be stored in UTF-8
     def decrypt!
-      self.body = Encryptor::decrypt(self.body).force_encoding('UTF-8')
+      self.body = Redmine::Ciphering.decrypt_text(self.body).force_encoding('UTF-8')
       self
     end

As we are using Redmine encryption in Vault settings, it looks like it works just fine, I am able to open existing project's Keys and also create new keys.

I am not sure why the Encryptor is unavailable tho, so I might not be of any help in the official solution.

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 13, 2019

we fixed issues with uninitialized constant Encryptor, can you pull branch

@dktcoding

This comment has been minimized.

Copy link
Contributor Author

dktcoding commented Jan 13, 2019

Just pulled branch redmine_4.0 and everything seems to be working! (Old databases, new databases, adding/removing/modifying keys).

Great work!

@w0k3

This comment has been minimized.

Copy link

w0k3 commented Jan 13, 2019

Works here too. So something is changed in Redmine 4.x and lib autoloading?

@w0k3

This comment has been minimized.

Copy link

w0k3 commented Jan 13, 2019

I believe the correct require "#{Rails.root}/plugins/vault/lib/encryptor" should not contain .rb.

Anyway, should this require also be added to following files, as they all use Encryptor?

app/models/vault/key.rb
test/integration/plugin_test.rb
test/integration/keys_test.rb
test/unit/lib/encryptor_test.rb
lib/tasks/ciphering.rake
@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 14, 2019

it quite strange because in development mode autoload working properly, we will check what different

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 14, 2019

Anyway, should this require also be added to following files, as they all use Encryptor?

app/models/vault/key.rb
test/integration/plugin_test.rb
test/integration/keys_test.rb
test/unit/lib/encryptor_test.rb
lib/tasks/ciphering.rake

they no needed, but we will check

@dktcoding

This comment has been minimized.

Copy link
Contributor Author

dktcoding commented Jan 20, 2019

Redmine 4.0.1 is out and it includes a fix for issue #30171 which is basically the same as #43.

If someone upgrades, could please confirm if vault is still working?

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Jan 20, 2019

we will check it

@noshutdown-ru-user

This comment has been minimized.

Copy link
Member

noshutdown-ru-user commented Feb 10, 2019

Added small changes and merged to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment