-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Authorizy | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
desc 'Creates Initializer and Migration for Authorizy' | ||
|
||
def create_initializer | ||
copy_file 'config/initializers/authorizy.rb', 'config/initializers/authorizy.rb' | ||
end | ||
|
||
def create_migration | ||
copy_file 'db/migrate/add_authorizy_on_users.rb', "db/migrate/#{timestamp(0)}_add_authorizy_on_users.rb" | ||
end | ||
|
||
private | ||
|
||
def timestamp(seconds) | ||
(Time.current + seconds.seconds).strftime('%Y%m%d%H%M%S') | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
lib/generators/authorizy/templates/config/initializers/authorizy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
Authorizy.configure do |config| | ||
# Creates aliases to automatically allow permission for another action. | ||
# https://github.com/wbotelhos/authorizy#aliases | ||
# config.aliases = {} | ||
|
||
# An interceptor to filter the request and decide if the request will be authorized | ||
# https://github.com/wbotelhos/authorizy#cop | ||
# config.cop = Authorizy::BaseCop | ||
|
||
# The current user from we fetch the permissions | ||
# https://github.com/wbotelhos/authorizy#current-user | ||
# config.current_user = -> (context) { context.respond_to?(:current_user) ? context.current_user : nil } | ||
|
||
# Inherited permissions from some other permission the user already has | ||
# https://github.com/wbotelhos/authorizy#dependencies | ||
# config.dependencies = {} | ||
|
||
# URL to be redirect when user has no permission to access some resource | ||
# https://github.com/wbotelhos/authorizy#dependencies | ||
# config.redirect_url = -> (context) { context.respond_to?(:root_url) ? context.root_url : '/' } | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/generators/authorizy/templates/db/migrate/add_authorizy_on_users.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddAuthorizyOnUsers < ActiveRecord::Migration[6.0] | ||
def change | ||
add_column :users, :authorizy, :jsonb, default: {}, null: false | ||
end | ||
end |