Hello, I recently started exploring Doorkeeper. How do I build on the Doorkeeper models i.e.
1) Add say a logo and description columns to Applications
2) I want each application to define some more configuration e.g. 1 application has many process_maps. I want to add has_many :process_maps to Application model.
Is all this possible?
There's not best way to do this. You can easily add any field with active record migration and then monkey patch the Doorkeeper::Application model.
Another way to do that is to use ActiveSupport::Concern
module ApplicationExtension
extend ActiveSupport::Concern
included do
has_many :things
end
end
Doorkeeper::Application.send :include, ApplicationExtension
Of course this doesn't change that much, you still have to inject behaviour on the model.
For the next gem version, the application model would be moved out from doorkeeper so you'll be able to customize anything easily. It will be a similar approach of what devise does to the User model, for example.
Hope I answered your question. If you find out a better solution or have any more questions, please let me know.
Thank you :)
+1 for the modular version :)
@debreczeni it's currently working on branch 1.0, check it out
Hi, is there today any other way to add fields to application model more easily ?
I'm using mongoid and concerns doesn't appear to be working.
For anyone trying out the Rails concerns method, it looks like the line "Doorkeeper::Application.send :include, ApplicationExtension" isn't executed if you leave it at the end of the concern file. To make it work, I had to move it to a before_action ApplicationController method (probably not the better place for that - I don't know).
@dfabreguette-ap I would guess that you could just move it to an initializer?
@danschultzer Yes that's what I've done in the end, thank you !
Thanks.
For anyone still lost on this, this is how I got a logo column working on the OAuthApplication model:
rails g migration AddImageUrlToOauthApplications image_url:string and run rake db:migraterails generate doorkeeper:views this will copy the default Doorkeeper templates into your views folder so you can change them (see: https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-views)doorkeeper/authorizations/new.html.erb template<%= @pre_auth.client.application.image_url %><img class="client-logo" src="<%= @pre_auth.client.application.image_url %>" alt="" />Of course you have to add an image url to the record in the database, I just added it directly to the DB column using Postico, I think if you want to include this new field in the new/edit templates of the application you'd have to add it as a permitted parameter, see: https://github.com/doorkeeper-gem/doorkeeper/issues/391
my solution
# config/initializers/doorkeeper_extend.rb
doorkeeper_extend_dir = File.join(Rails.root, "app", "models", "doorkeeper")
Dir.glob("#{doorkeeper_extend_dir}/*.rb").each { |f| require(f) }
# app/models/doorkeeper/application.rb
module Doorkeeper
class Application < ActiveRecord::Base
has_many :things
end
end
Most helpful comment
my solution