rails_admin_user_abilities 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7e281f1fcbb6f702bb46c3c657c4a2053c5acdfc
4
+ data.tar.gz: cbb69df93a8e091b5a9aa9cf79711ea45ccfe0eb
5
+ SHA512:
6
+ metadata.gz: 97c791c4d89a79901638dedf6e897b3690b67a84ea5c95c3f5d148c99642a1b940e80b25cb0e562d456d89f494e186b034aaca7233db6f5b2beb1a829697ace5
7
+ data.tar.gz: 025cc9d8deea840b080ac233a629b03f607e1816988077fbab23f3a8ad5f8c2909575bbca9c6ef5321dcc3aba4816dfa009974788a523a8f63ced37bec77679b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_admin_user_abilities.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alexander Kiseliev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # RailsAdminUserAbilities
2
+
3
+ That will add fields for access to models, objects and actions in rails_admin panel for specific users.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rails_admin_user_abilities'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rails_admin_user_abilities
20
+
21
+ ## Usage
22
+
23
+ Add in app/models/user.rb (temporary decision, it will be more configurable in future)
24
+ ```ruby
25
+ has_one :ability, class_name: "RailsAdminUserAbilities::UserAbility", as: :rails_admin_user_abilitable
26
+ scope :for_rails_admin, -> { where(:roles.in => ['admin', 'manager']) } # could be any you want, just need to
27
+ ```
28
+
29
+ Add actions for rails_admin panel (in initializers/raisl_admin.rb)
30
+ ```ruby
31
+ RailsAdmin.config do |config|
32
+ # some code
33
+ config.actions do
34
+ # some code
35
+
36
+ user_abilities do
37
+ visible do
38
+ render_object = (bindings[:controller] || bindings[:view])
39
+ render_object and render_object.current_user.admin? and
40
+ ["User"].include? bindings[:abstract_model].model_name
41
+ end
42
+ end
43
+ model_accesses do
44
+ visible do
45
+ render_object = (bindings[:controller] || bindings[:view])
46
+ render_object and render_object.current_user.admin? and
47
+ ["SomeModel1", "SomeModel2"].include? bindings[:abstract_model].model_name
48
+ end
49
+ end
50
+ end
51
+ end
52
+ ```
53
+
54
+ Also add method for set CanCanCan rules (in app/models/ability.rb)
55
+ ```ruby
56
+ class Ability
57
+ include CanCan::Ability
58
+
59
+ def initialize(user)
60
+ # some code
61
+ user.ability.to_cancancan(self) if user.ability
62
+ end
63
+ end
64
+ ```
65
+
66
+ ## Development
67
+
68
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
69
+
70
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
71
+
72
+ ## Contributing
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/enjoycreative/rails_admin_user_abilities.
75
+
76
+
77
+ ## License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ $(document).delegate ".user_abilities_trigger, .model_accesses_trigger", 'change', (e)->
2
+ _target = $(e.currentTarget)
3
+ $.post _target.closest("[data-url]").data("url"), _target.siblings().andSelf().serializeArray(), (data)->
4
+ _label = _target.siblings('label')
5
+ _label.find(".message").remove()
6
+ _label.append(data)
@@ -0,0 +1,14 @@
1
+ #rails_admin_user_abilities, #rails_admin_model_accesses
2
+ .hidden
3
+ display: none
4
+
5
+ .error
6
+ color: red
7
+
8
+ .success
9
+ color: green
10
+
11
+ input
12
+ height: 20px
13
+ label
14
+ font-size: 18px
@@ -0,0 +1,20 @@
1
+ if RailsAdminUserAbilities.active_record?
2
+ module RailsAdminUserAbilities
3
+ class UserAbility < ActiveRecord::Base
4
+ end
5
+ end
6
+ end
7
+
8
+ module RailsAdminUserAbilities
9
+ class UserAbility
10
+ #binding.pry
11
+ if RailsAdminUserAbilities.mongoid?
12
+ include RailsAdminUserAbilities::Models::UserAbility
13
+ end
14
+
15
+ if RailsAdminUserAbilities.active_record?
16
+ self.table_name = "rails_admin_user_abilities"
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ - if request.get?
2
+ - _model = @abstract_model.model
3
+ - _model_str = _model.name.underscore
4
+
5
+ #rails_admin_model_accesses_wrapper
6
+ = stylesheet_link_tag 'rails_admin/rails_admin_user_abilities'
7
+ = javascript_include_tag 'rails_admin/rails_admin_user_abilities'
8
+
9
+ #rails_admin_model_accesses.col-md-12
10
+ .col-md-3
11
+ ul.nav.nav-pills.nav-stacked
12
+ - @users.each do |u|
13
+ li= link_to u.email, "#user_abilities_#{u._id}", title: u._id, "data-toggle" => "tab"
14
+ .cf
15
+
16
+ .tab-content.col-md-9
17
+ - @users.each do |u|
18
+ ruby:
19
+ url = model_accesses_path(model_name: @abstract_model, id: @object.id, user_id: u._id)
20
+ user_abilities = ::Ability.new(u)
21
+ _id = "user_abilities_#{u._id}"
22
+ .tab-pane{id=_id data-url=url}
23
+ .row-fluid
24
+ .controls
25
+ - [:manage, :read].each do |_action_str|
26
+ div
27
+ = check_box "model_accesses[][#{u._id}]#{_model_str}", _action_str, {checked: user_abilities.can?(_action_str, @object), class: "model_accesses_trigger"}, "can", "cannot"
28
+ = label("model_accesses[][#{u._id}]#{_model_str}", _action_str, "#{I18n.t("admin.user_abilities.global_actions.#{_action_str}")} (#{_action_str})")
29
+ hr
30
+ ruby:
31
+ _bindings = {
32
+ abstract_model: @abstract_model,
33
+ view: self
34
+ }
35
+ - RailsAdmin::Config::Actions.all(:all, _bindings).select { |a| a.http_methods.include?(:get) and a.member? }.map do |a|
36
+ - _action = a.class.name.demodulize
37
+ - _action_str = _action.underscore
38
+ - next if @excluded_actions.include?(_action_str)
39
+ - next unless a.visible
40
+
41
+ div
42
+ = check_box "model_accesses[][#{u._id}]#{_model_str}", _action_str, {checked: user_abilities.can?(_action_str.to_sym, @object), class: "model_accesses_trigger"}, "can", "cannot"
43
+ = label("model_accesses[][#{u._id}]#{_model_str}", _action_str, "#{wording_for(:menu, a, @abstract_model)} (#{_action_str})")
44
+
45
+ - if u.ability
46
+ .col-md-12
47
+ hr
48
+ button(data-toggle="collapse" data-target="#model_accesses_hash_#{u.id}")= "Чистый код"
49
+ .collapse(id="model_accesses_hash_#{u.id}")
50
+ pre= JSON.pretty_generate({"#{_model.name}": (u.ability.accesses[_model.name] || {}) })
51
+
52
+ - elsif request.post?
53
+ - uniq_id = "rails_admin_model_accesses_#{(Time.new.to_f * 1000).to_i}"
54
+ span(class="message #{@_class}" id=uniq_id)
55
+ = @message
56
+ javascript:
57
+ setTimeout(function(){
58
+ $('##{uniq_id}').fadeOut(100, function(){
59
+ $('##{uniq_id}').remove();
60
+ });
61
+ }, 1000);
62
+
@@ -0,0 +1,67 @@
1
+ - if request.get?
2
+ - url = user_abilities_path(model_name: @abstract_model, id: @object.id)
3
+
4
+ #rails_admin_user_abilities_wrapper
5
+ = stylesheet_link_tag 'rails_admin/rails_admin_user_abilities'
6
+ = javascript_include_tag 'rails_admin/rails_admin_user_abilities'
7
+
8
+ #rails_admin_user_abilities.col-md-12{data-url=url}
9
+ .col-md-3
10
+ ul.nav.nav-pills.nav-stacked
11
+ - @models.each do |m|
12
+ ruby:
13
+ _model = m.abstract_model.model
14
+ _content = m.abstract_model.config.label
15
+ _title = m.abstract_model.config.label
16
+ _link = "#user_abilities_#{_model.name.gsub("::", "").underscore}"
17
+ li= link_to _content, _link, title: _title, "data-toggle" => "tab"
18
+ .cf
19
+
20
+ .tab-content.col-md-9
21
+ - @models.each do |m|
22
+ ruby:
23
+ _model = m.abstract_model.model
24
+ _model_str = _model.name.underscore
25
+ _content = m.abstract_model.config.label
26
+ _title = m.abstract_model.config.label
27
+ _id = "user_abilities_#{_model.name.gsub("::", "").underscore}"
28
+ .tab-pane{id=_id}
29
+ .row-fluid
30
+ .controls
31
+ - [:manage, :read].each do |_action_str|
32
+ div
33
+ = check_box "user_abilities[]#{_model_str}", _action_str, {checked: @user_abilities.can?(_action_str, _model), class: "user_abilities_trigger"}, "can", "cannot"
34
+ = label("user_abilities[]#{_model_str}", _action_str, "#{I18n.t("admin.user_abilities.global_actions.#{_action_str}")} (#{_action_str})")
35
+ hr
36
+ ruby:
37
+ _bindings = {
38
+ abstract_model: m.abstract_model,
39
+ view: self
40
+ }
41
+ - RailsAdmin::Config::Actions.all(:all, _bindings).select { |a| a.http_methods.include?(:get) }.map do |a|
42
+ - _action = a.class.name.demodulize
43
+ - _action_str = _action.underscore
44
+ - next if @excluded_actions.include?(_action_str)
45
+ - next unless a.visible
46
+
47
+ div
48
+ = check_box "user_abilities[]#{_model_str}", _action_str, {checked: @user_abilities.can?(_action_str.to_sym, _model), class: "user_abilities_trigger"}, "can", "cannot"
49
+ = label("user_abilities[]#{_model_str}", _action_str, "#{wording_for(:menu, a, m.abstract_model)} (#{_action_str})")
50
+
51
+ - if @object.ability
52
+ .col-md-12
53
+ hr
54
+ button(data-toggle="collapse" data-target="#abilities_hash")= "Чистый код"
55
+ #abilities_hash.collapse
56
+ pre= JSON.pretty_generate @object.ability.abilities
57
+
58
+ - elsif request.post?
59
+ - uniq_id = "rails_admin_user_abilities_#{(Time.new.to_f * 1000).to_i}"
60
+ span(class="message #{@_class}" id=uniq_id)
61
+ = @message
62
+ javascript:
63
+ setTimeout(function(){
64
+ $('##{uniq_id}').fadeOut(100, function(){
65
+ $('##{uniq_id}').remove();
66
+ });
67
+ }, 1000);
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails_admin_user_abilities"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ ru:
2
+ mongoid: &mongoid
3
+ models:
4
+ rails_admin_user_abilities/user_ability: Права доступа
5
+ rails_admin_user_abilities/model_access: Права доступа
6
+ activerecord:
7
+ <<: *mongoid
8
+
9
+ admin:
10
+ actions:
11
+ user_abilities:
12
+ menu: Права доступа
13
+ breadcrumb: Права доступа
14
+ error: Ошибка
15
+ error_no_data: Нет данных
16
+ success: Успешно
17
+ title: Права доступа
18
+
19
+ model_accesses:
20
+ menu: Права доступа
21
+ breadcrumb: Права доступа
22
+ error: Ошибка
23
+ error_no_data: Нет данных
24
+ success: Успешно
25
+ title: Права доступа
26
+
27
+ user_abilities:
28
+ global_actions:
29
+ manage: "Делать все"
30
+ read: "Видеть"
@@ -0,0 +1,150 @@
1
+ module RailsAdmin
2
+ module Config
3
+ module Actions
4
+ class UserAbilities < Base
5
+ RailsAdmin::Config::Actions.register(self)
6
+
7
+ # Is the action acting on the root level (Example: /admin/contact)
8
+ register_instance_option :root? do
9
+ false
10
+ end
11
+
12
+ register_instance_option :collection? do
13
+ false
14
+ end
15
+
16
+ # Is the action on an object scope (Example: /admin/team/1/edit)
17
+ register_instance_option :member? do
18
+ true
19
+ end
20
+
21
+ register_instance_option :route_fragment do
22
+ 'user_abilities'
23
+ end
24
+
25
+ register_instance_option :controller do
26
+ Proc.new do |klass|
27
+ @config = ::RailsAdminUserAbilities::Configuration.new @abstract_model
28
+
29
+ if params['id'].present?
30
+ if request.get?
31
+ @user_abilities = ::Ability.new(@object)
32
+ @models = RailsAdmin::Config.visible_models({})
33
+ @excluded_actions = ["dashboard"]
34
+ @action_aliases = {
35
+ show: :read
36
+ }
37
+ render action: @action.template_name
38
+
39
+ elsif request.post?
40
+ ability = @object.ability || RailsAdminUserAbilities::UserAbility.new(rails_admin_user_abilitable: @object)
41
+ params[:user_abilities].each do |a|
42
+ _model = a.keys.first.camelcase
43
+ _model_rules = ability.abilities[_model] || {}
44
+ _model_rules.merge!(a.values.first)
45
+ ability.abilities[_model] = _model_rules
46
+ end
47
+ if ability.save
48
+ @_class = "success"
49
+ @message = "Успешно!"
50
+ else
51
+ @_class = "error"
52
+ @message = "Нихера!"
53
+ end
54
+ render action: @action.template_name, layout: false
55
+
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ register_instance_option :link_icon do
62
+ 'icon-tasks'
63
+ end
64
+
65
+ register_instance_option :http_methods do
66
+ [:get, :post]
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ module RailsAdmin
74
+ module Config
75
+ module Actions
76
+ class ModelAccesses < Base
77
+ RailsAdmin::Config::Actions.register(self)
78
+
79
+ # Is the action acting on the root level (Example: /admin/contact)
80
+ register_instance_option :root? do
81
+ false
82
+ end
83
+
84
+ register_instance_option :collection? do
85
+ false
86
+ end
87
+
88
+ # Is the action on an object scope (Example: /admin/team/1/edit)
89
+ register_instance_option :member? do
90
+ true
91
+ end
92
+
93
+ register_instance_option :route_fragment do
94
+ 'model_accesses'
95
+ end
96
+
97
+ register_instance_option :controller do
98
+ Proc.new do |klass|
99
+ @config = ::RailsAdminUserAbilities::Configuration.new @abstract_model
100
+
101
+ if params['id'].present?
102
+ if request.get?
103
+ @users = ::User.for_rails_admin.all.to_a || []
104
+ @excluded_actions = ["dashboard", "index", "history_index", "model_comments"]
105
+ @action_aliases = {
106
+ show: :read
107
+ }
108
+ render action: @action.template_name
109
+
110
+ elsif request.post? and params[:user_id].present?
111
+ @user = ::User.for_rails_admin.where(id: params[:user_id]).first
112
+ obj_id = @object.id.to_s
113
+ unless @user.nil?
114
+ ability = @user.ability || RailsAdminUserAbilities::UserAbility.new(rails_admin_user_abilitable: @user)
115
+ params[:model_accesses].each do |a|
116
+ next if a.keys.first != @user.id.to_s
117
+ a = a.values.first
118
+ _model = a.keys.first.camelcase
119
+ _model_rules = ability.accesses[_model] || {}
120
+ _object_rules = _model_rules[obj_id] || {}
121
+ _object_rules.merge!(a.values.first)
122
+ _model_rules[obj_id] ||= {}
123
+ _model_rules[obj_id].merge!(a.values.first)
124
+ ability.accesses[_model] = _model_rules
125
+ end
126
+ end
127
+ if ability and ability.save
128
+ @_class = "success"
129
+ @message = "Успешно!"
130
+ else
131
+ @_class = "error"
132
+ @message = "Нихера!"
133
+ end
134
+ render action: @action.template_name, layout: false
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ register_instance_option :link_icon do
141
+ 'icon-user'
142
+ end
143
+
144
+ register_instance_option :http_methods do
145
+ [:get, :post]
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,24 @@
1
+ module RailsAdminUserAbilities
2
+ class Configuration
3
+ def initialize(abstract_model)
4
+ @abstract_model = abstract_model
5
+ end
6
+
7
+ def options
8
+ # @options ||= {
9
+ # fields: [{}],
10
+ # thumbnail_fields: [:image, :cover],
11
+ # label_methods: [:name, :label],
12
+ # hint_fields: [],
13
+ # thumbnail_size: :thumb,
14
+ # thumbnail_gem: :paperclip,
15
+ # }.merge(config || {})
16
+ @options ||= {}
17
+ end
18
+
19
+ protected
20
+ def config
21
+ ::RailsAdmin::Config.model(@abstract_model.model).user_abilities || {}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module RailsAdminUserAbilities
2
+ class Engine < ::Rails::Engine
3
+
4
+ initializer "RailsAdminUserAbilities precompile hook", group: :all do |app|
5
+ app.config.assets.precompile += %w(rails_admin/rails_admin_user_abilities.js rails_admin/rails_admin_user_abilities.css)
6
+ end
7
+
8
+ initializer 'Include RailsAdminUserAbilities::Helper' do |app|
9
+ ActionView::Base.send :include, RailsAdminUserAbilities::Helper
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module RailsAdminUserAbilities
2
+ module Helper
3
+ def rails_admin_user_abilities_form
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ module RailsAdminUserAbilities
2
+ module Models
3
+ module Mongoid
4
+ module UserAbility
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ include ::Mongoid::Document
8
+ include ::Mongoid::Timestamps::Short
9
+ # include ::Mongoid::Userstamp
10
+
11
+ belongs_to :rails_admin_user_abilitable, polymorphic: true
12
+
13
+ store_in collection: "rails_admin_user_abilities"
14
+
15
+ field :enabled, type: ::Mongoid::VERSION.to_i < 4 ? Boolean : ::Mongoid::Boolean, default: true
16
+ scope :enabled, -> { where(enabled: true) }
17
+
18
+ field :abilities, type: Hash, default: {}
19
+ field :accesses, type: Hash, default: {}
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ module RailsAdminUserAbilities
2
+ module Models
3
+ module UserAbility
4
+ extend ActiveSupport::Concern
5
+ include RailsAdminUserAbilities.orm_specific('UserAbility')
6
+
7
+ included do
8
+
9
+ def to_cancancan(ability_object)
10
+ abilities.each_pair do |model_name, rules|
11
+ _model = model_name.constantize
12
+ rules.each_pair do |act, meth|
13
+ ability_object.send(meth, act.to_sym, _model)
14
+ end
15
+ end
16
+
17
+ accesses.each_pair do |model_name, ids_rules|
18
+ _model = model_name.constantize
19
+ ids_rules.each_pair do |obj_id, rules|
20
+ rules.each_pair do |act, meth|
21
+ ability_object.send(meth, act.to_sym, _model, {id: BSON::ObjectId.from_string(obj_id)})
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminUserAbilities
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,50 @@
1
+
2
+ require "rails_admin_comments/version"
3
+
4
+ require 'mongoid'
5
+ require 'mongoid_userstamp'
6
+
7
+ require "rails_admin_user_abilities/engine"
8
+
9
+ require 'rails_admin_user_abilities/configuration'
10
+
11
+ require 'rails_admin/config/actions'
12
+ require 'rails_admin/config/model'
13
+ require 'rails_admin_user_abilities/action'
14
+ # require 'rails_admin_user_abilities/model'
15
+ require 'rails_admin_user_abilities/helper'
16
+
17
+ module RailsAdminUserAbilities
18
+ class << self
19
+ def orm
20
+ :mongoid
21
+ # if defined?(::Mongoid)
22
+ # :mongoid
23
+ # else
24
+ # :active_record
25
+ # end
26
+ end
27
+ def mongoid?
28
+ orm == :mongoid
29
+ end
30
+ def active_record?
31
+ orm == :active_record
32
+ end
33
+
34
+ def model_namespace
35
+ "RailsAdminUserAbilities::Models::#{RailsAdminUserAbilities.orm.to_s.camelize}"
36
+ end
37
+ def orm_specific(name)
38
+ "#{model_namespace}::#{name}".constantize
39
+ end
40
+ end
41
+
42
+ module Models
43
+ autoload :UserAbility, "rails_admin_user_abilities/models/user_ability"
44
+
45
+ module Mongoid
46
+ autoload :UserAbility, "rails_admin_user_abilities/models/mongoid/user_ability"
47
+ end
48
+ end
49
+ # autoload :RailsAdminConfig, "rails_admin_comments/rails_admin_config"
50
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_admin_user_abilities/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_admin_user_abilities"
8
+ spec.version = RailsAdminUserAbilities::VERSION
9
+ spec.authors = ["Alexander Kiseliev"]
10
+ spec.email = ["dev@enjoycreate.ru"]
11
+
12
+ spec.summary = %q{CanCanCan fields for rails_admin}
13
+ spec.description = %q{CanCanCan fields for rails_admin}
14
+ spec.homepage = "https://github.com/enjoycreative/rails_admin_user_abilities"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+
33
+ spec.add_dependency 'rails_admin', "~> 0.8.1"
34
+ end
data/release.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/bash
2
+ bundle update
3
+ git add --all .
4
+ git commit -am "${*:1}"
5
+ git push
6
+ git push gh master
7
+ rake release
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_user_abilities
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kiseliev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails_admin
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ description: CanCanCan fields for rails_admin
56
+ email:
57
+ - dev@enjoycreate.ru
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - app/assets/javascripts/rails_admin/rails_admin_user_abilities.coffee
69
+ - app/assets/stylesheets/rails_admin/rails_admin_user_abilities.sass
70
+ - app/models/rails_admin_user_abilities/user_ability.rb
71
+ - app/views/rails_admin/main/model_accesses.html.slim
72
+ - app/views/rails_admin/main/user_abilities.html.slim
73
+ - bin/console
74
+ - bin/setup
75
+ - config/locales/ru.rails_admin_user_abilities.yml
76
+ - lib/rails_admin_user_abilities.rb
77
+ - lib/rails_admin_user_abilities/action.rb
78
+ - lib/rails_admin_user_abilities/configuration.rb
79
+ - lib/rails_admin_user_abilities/engine.rb
80
+ - lib/rails_admin_user_abilities/helper.rb
81
+ - lib/rails_admin_user_abilities/models/mongoid/user_ability.rb
82
+ - lib/rails_admin_user_abilities/models/user_ability.rb
83
+ - lib/rails_admin_user_abilities/version.rb
84
+ - rails_admin_user_abilities.gemspec
85
+ - release.sh
86
+ homepage: https://github.com/enjoycreative/rails_admin_user_abilities
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.8
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: CanCanCan fields for rails_admin
110
+ test_files: []