Top Menu

Jump to content
Home
    • Projects
    • Work packages
    • News
    • Getting started
    • Introduction video
      Welcome to OpenProject Community
      Get a quick overview of project management and team collaboration with OpenProject. You can restart this video from the help menu.

    • Help and support
    • User guides
    • Videos
    • Shortcuts
    • Community forum
    • Professional support

    • Additional resources
    • Data privacy and security policy
    • Digital accessibility (DE)
    • OpenProject website
    • Security alerts / Newsletter
    • OpenProject blog
    • Release notes
    • Report a bug
    • Development roadmap
    • Add and edit translations
    • API documentation
  • Sign in
      Forgot your password?
      Create a new account

      or sign in with your existing account

      Google

Side Menu

  • Overview
  • Activity
  • Roadmap
  • Work packages
  • Calendars
  • Team planners
  • Boards
  • Forums
  • Wiki
    • Table of contents
      • Expanded. Click to collapseCollapsed. Click to showDeveloper
        • Hierarchy leafAccessibility Checklist
        • Hierarchy leafCode Review Guidelines
        • Expanded. Click to collapseCollapsed. Click to showContribution
          • Hierarchy leafGit Workflow
          • Hierarchy leafTranslations
        • Expanded. Click to collapseCollapsed. Click to showDeveloping Plugins
          • Hierarchy leafDeveloping an OmniAuth Authentication Plugin
        • Hierarchy leafRelease Process
        • Hierarchy leafReport a bug
        • Hierarchy leafSecurity
        • Hierarchy leafSetting up an OpenLDAP server for testing
        • Hierarchy leafTheme Features
      • Hierarchy leafDownload
      • Expanded. Click to collapseCollapsed. Click to showFeature tour
        • Hierarchy leafRelease Notes OpenProject 30
        • Expanded. Click to collapseCollapsed. Click to showRelease Notes OpenProject 30 - Overview
          • Hierarchy leafGlossary
          • Hierarchy leafRelease Notes - Accessibility
          • Hierarchy leafRelease Notes - Accessibility changes
          • Hierarchy leafRelease Notes - Add work package queries as menu items to sidebar
          • Hierarchy leafRelease Notes - Copy projects based on Templates
          • Hierarchy leafRelease Notes - Design changes
          • Hierarchy leafRelease Notes - Fixed Bugs
          • Hierarchy leafRelease Notes - Keyboard Shortcuts
          • Hierarchy leafRelease Notes - Project settings
          • Hierarchy leafRelease Notes - Ruby&Rails Update
          • Hierarchy leafRelease Notes - Security
          • Hierarchy leafRelease Notes - Timelines
          • Hierarchy leafRelease Notes - Work packages
      • Hierarchy leafHowto create animated gifs
      • Hierarchy leafMigration Squashing
      • Hierarchy leafMod security
      • Hierarchy leafNew work package page
      • Hierarchy leafOP3 to OP4 Debian upgrade
      • Hierarchy leafOP4 Ubuntu1404 Stable with MySQL in production
      • Hierarchy leafOpenProject 40 Development Setup
      • Expanded. Click to collapseCollapsed. Click to showOpenProject Foundation
        • Hierarchy leafBoards
        • Hierarchy leafMembers
        • Hierarchy leafOPF-Meetings
        • Hierarchy leafStatutes
      • Expanded. Click to collapseCollapsed. Click to showRelease Notes
        • Hierarchy leafOpenProject released on Bitnami
      • Expanded. Click to collapseCollapsed. Click to showRelease Notes OpenProject 40 - Overview
        • Hierarchy leafRelease Notes OpenProject 40 - Accessibility improvements
        • Hierarchy leafRelease Notes OpenProject 40 - Column header functions in work package table
        • Hierarchy leafRelease Notes OpenProject 40 - Improved Design
        • Hierarchy leafRelease Notes OpenProject 40 - Integrated query title on work package page
        • Hierarchy leafRelease Notes OpenProject 40 - Integrated toolbar on work package page
        • Hierarchy leafRelease Notes OpenProject 40 - OmniAuth integration for OpenProject
        • Hierarchy leafRelease Notes OpenProject 40 - Work package details pane
      • Expanded. Click to collapseCollapsed. Click to showSecurity and privacy
        • Hierarchy leafFAQ
      • Expanded. Click to collapseCollapsed. Click to showSupport
        • Expanded. Click to collapseCollapsed. Click to showDownload and Installation
          • Hierarchy leafInstallation MacOS
          • Expanded. Click to collapseCollapsed. Click to showInstallation OpenProject 3 0
            • Hierarchy leafDebian Stable with MySQL in production
            • Hierarchy leafInstallation Ubuntu
            • Hierarchy leafInstallation Windows
            • Hierarchy leafInstallation on Centos 65 x64 with Apache and PostgreSQL 93
          • Expanded. Click to collapseCollapsed. Click to showInstallation OpenProject 40
            • Hierarchy leafOP4 Debian Stable with MySQL in production
          • Expanded. Click to collapseCollapsed. Click to showMigration paths
            • Hierarchy leafFrom Chilliproject to OpenProject
            • Hierarchy leafMigration 15 to 30
            • Hierarchy leafMigration 24 to 30
            • Hierarchy leafMigration Redmine 2x › OpenProject 30
            • Hierarchy leafOpenProject 3 Migration
          • Hierarchy leafOpenProject 40
        • Expanded. Click to collapseCollapsed. Click to showNews
          • Hierarchy leafNew OpenProject Translations Plugin
          • Hierarchy leafNew Plugin on OpenProjectorg Local Avatars
          • Hierarchy leafNew design for OpenProject
          • Hierarchy leafNews Accessibility workshop for OpenProject
          • Hierarchy leafNews Glossary for OpenProject
          • Hierarchy leafNews Heartbleed fixed
          • Hierarchy leafNews Icon Fonts
          • Hierarchy leafNews OpenProject 30 Release
          • Hierarchy leafNews Release GitHub Integration Plugin
          • Hierarchy leafNews Success Story Deutsche Telekom
          • Hierarchy leafNews Timelines
          • Hierarchy leafOpenProject 3013 released
          • Hierarchy leafOpenProject 3017 released
          • Hierarchy leafOpenProject 40 released
          • Hierarchy leafOpenProject 40 will be coming soon
          • Hierarchy leafOpenProject 405 released
          • Hierarchy leafOpenProject and pkgrio
          • Hierarchy leafOpenProject news moved to a new blog
          • Hierarchy leafOpenProjectBitnami
          • Hierarchy leafPackager version with plugins released ("Community edition")
          • Hierarchy leafRegistration OpenProject-Foundation
          • Hierarchy leafRelease OpenProject AuthPlugins
          • Hierarchy leafUpdates on OpenProject
          • Hierarchy leafWe need your feedback for the the new fullscreen view for work packages
        • Hierarchy leafOpenProject Plug-Ins
      • Expanded. Click to collapseCollapsed. Click to showWiki
        • Hierarchy leaf2nd Level Support
You are here:
  • Forums
  • Development

Content

Proper way to patching / overriding classes

Added by Oliver Günther almost 9 years ago

In the other existing plugins, there exist several examples of patches to controllers.
However, I’m looking into porting/rewriting the git hosting plugin for OP and that requires patching the corresponding Redmine SCM adapter class.
The plugin loaded the patch through ActionDispatch::Calbacks.to_prepare.

I’m wondering whether I can specify the patch within the registration of the plugin in engine.rb, i.e., patches [:GitAdapter] with the patch residing under patches/git_adapter_patch.rb.
But in this case, the lookup in ActiveSupport.constantize fails for the class to be patched (Redmine::Scm::Adapters::GitAdapter), even though lib/ is currently added to autoloading in config/applications.rb

 ~/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:230:in `block in constantize': uninitialized constant GitAdapter (NameError)
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:229:in `each'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:229:in `constantize'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.17/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/openproject-plugins-1.0.3/lib/open_project/plugins/acts_as_op_engine.rb:52:in `block (3 levels) in included'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/openproject-plugins-1.0.3/lib/open_project/plugins/acts_as_op_engine.rb:49:in `each'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/openproject-plugins-1.0.3/lib/open_project/plugins/acts_as_op_engine.rb:49:in `block (2 levels) in included'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.17/lib/active_support/callbacks.rb:429:in `_run__69145852393605330__prepare__810845249135798481__callbacks'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.17/lib/active_support/callbacks.rb:405:in `__run_callback'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.17/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-3.2.17/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.17/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.17/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `instance_exec'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `run'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/initializable.rb:55:in `block in run_initializers'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `each'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `run_initializers'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/application.rb:136:in `initialize!'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from ~/openproject/config/environment.rb:36:in `block in <top (required)>'
    from ~/openproject/config/application.rb:44:in `block in bench'
    from ~/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/benchmark.rb:281:in `measure'
    from ~/openproject/config/application.rb:43:in `bench'
    from ~/openproject/config/environment.rb:34:in `<top (required)>'
    from ~/openproject/config.ru:32:in `block in <main>'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
    from ~/openproject/config.ru:in `new'
    from ~/openproject/config.ru:in `<main>'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/commands/server.rb:46:in `app'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/commands/server.rb:70:in `start'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/commands.rb:55:in `block in <top (required)>'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/commands.rb:50:in `tap'
    from ~/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.17/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

The original plugin manually pulled in all patches and used require_dependency beforehand to make sure the class was loaded.
Is there a way to make achieve this using the OP plugin structure?

Greets,
Oliver


Replies (1)

RE: Proper way to patching / overriding classes - Added by Michael Frister almost 9 years ago

Hi Oliver,

at the moment, the openproject-plugins plugin only supports patches of classes that are not nested in a module. We’ll probably fix that in the future, but for now you can patch the classes manually.

You can find an example in our global-roles plugin that loads a few patches via the standard mechanism (line 36) and some others manually (line 38 and following). One of the manual patches is implemented in patches/access_control_patch.rb.

I don’t think you’ll need a manual require_dependency here, but I’m not absolutely sure, so just try without.

If you don’t like the manual patches and don’t want to wait for us, feel free to create a pull request against openproject-plugins yourself :)

Cheers,
Michael

  • (1 - 1/1)
Loading...