mix-rails-auth 0.16.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ class Admix::RolesController < Admix::InheritedController
2
+
3
+ end
@@ -0,0 +1,14 @@
1
+ class Admix::RolesDatagrid
2
+
3
+ include Datagrid
4
+ extend AdmixHelper
5
+
6
+ scope do
7
+ Role.all
8
+ end
9
+
10
+ column :name, header: input_label(:role, :name)
11
+
12
+ include Admix::TableActions
13
+
14
+ end
@@ -0,0 +1,19 @@
1
+ class Role
2
+ include Mongoid::Document
3
+
4
+ has_and_belongs_to_many :users
5
+ belongs_to :resource, :polymorphic => true
6
+
7
+ field :name, :type => String
8
+ index({ :name => 1 }, { :unique => true })
9
+
10
+
11
+ index({
12
+ :name => 1,
13
+ :resource_type => 1,
14
+ :resource_id => 1
15
+ },
16
+ { :unique => true})
17
+
18
+ scopify
19
+ end
data/app/models/user.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  class User
2
2
  include Mongoid::Document
3
+ rolify
4
+ include Authority::UserAbilities
3
5
 
4
- ROLES = %w[admin content_manager]
5
-
6
- #attr_accessible :roles
6
+ ROLES = %w[admin manager]
7
7
 
8
8
  # Include default devise modules. Others available are:
9
9
  # :token_authenticatable, :confirmable,
@@ -46,23 +46,7 @@ class User
46
46
 
47
47
  ## Token authenticatable
48
48
  # field :authentication_token, :type => String
49
-
50
-
51
- #field :role, :type => String
52
- field :roles_mask, :type => Integer
53
-
54
- def roles=(roles)
55
- self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.inject(0, :+)
56
- end
57
-
58
- def roles
59
- ROLES.reject do |r|
60
- ((roles_mask || 0) & 2**ROLES.index(r)).zero?
61
- end
62
- end
63
-
64
- def is?(role)
65
- roles.include?(role.to_s)
66
- end
49
+
50
+ #has_and_belongs_to_many :roles
67
51
 
68
52
  end
@@ -0,0 +1,2 @@
1
+ = f.input :name, as: 'string'
2
+ = f.association :users, as: :check_boxes, collection: User.all, label_method: :email, value_method: :id
@@ -0,0 +1,4 @@
1
+ %dl
2
+ %dt= input_label(:roles, :name)
3
+ %dd= resource.name
4
+
@@ -0,0 +1,3 @@
1
+ = link_to image_tag('admix/zoom.png'), resource_url(resource), class: 'btn', title:'Visualizar'
2
+ = link_to image_tag('admix/page_edit.png'), edit_resource_url(resource), class: 'btn', title:'Editar'
3
+ = link_to image_tag('admix/cancel.png'), resource_url(resource), method: :delete, data: { confirm: t('admix.crud.destroy_confirm') }, class: 'btn', title:'Deletar'
@@ -1,10 +1,3 @@
1
1
  = f.input :email, as: 'string'
2
2
  = f.input :password, as: 'password'
3
-
4
- - User::ROLES.each do |role|
5
- .control-group
6
- = label_tag "user_roles_#{role}", role.humanize, class: 'control-label'
7
- .controls
8
- = check_box_tag "user[roles][#{role}]", role, @user.roles.include?(role), {:name => "user[roles][]"}
9
-
10
- = hidden_field_tag "user[roles][]", ""
3
+ = f.input :roles, :as => :select, :collection => Role.all
@@ -0,0 +1,8 @@
1
+ Rolify.configure do |config|
2
+ # By default ORM adapter is ActiveRecord. uncomment to use mongoid
3
+ config.use_mongoid
4
+
5
+ # Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
6
+ # Enable this feature _after_ running rake db:migrate as it relies on the roles table
7
+ # config.use_dynamic_shortcuts
8
+ end
@@ -22,3 +22,5 @@ pt-BR:
22
22
  fields:
23
23
  last_sign_in_at: 'Último login'
24
24
  email: 'E-mail'
25
+ roles:
26
+ roles: 'Papéis'
data/config/routes.rb CHANGED
@@ -5,6 +5,7 @@ Rails.application.routes.draw do
5
5
  scope Admix::namespace_path, as: :admix, module: :admix do
6
6
  devise_for :users, sign_out_via: 'get', controllers: {sessions: 'admix/sessions', passwords: 'admix/passwords'}, :path_names => { :sign_in => 'login', :sign_out => 'logout' }
7
7
  resources :users
8
+ resources :roles
8
9
  end
9
10
 
10
11
  end
@@ -11,7 +11,7 @@ module MixRailsAuth
11
11
 
12
12
  submenu.instance_eval do
13
13
  def can_render?(current_user)
14
- current_user.is?(:admin)
14
+ current_user.has_role? :admin
15
15
  end
16
16
  end
17
17
 
@@ -1,7 +1,7 @@
1
1
  module MixRailsAuth
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 16
4
+ MINOR = 22
5
5
  TINY = 0
6
6
  PRE = nil
7
7
 
@@ -1,5 +1,6 @@
1
1
  require "mix-rails-auth/engine"
2
2
  require 'devise'
3
+ require 'rolify'
3
4
 
4
5
  module Auth
5
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mix-rails-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.22.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-27 00:00:00.000000000 Z
13
+ date: 2013-02-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -60,54 +60,6 @@ dependencies:
60
60
  - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
- - !ruby/object:Gem::Dependency
64
- name: mongoid
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ~>
69
- - !ruby/object:Gem::Version
70
- version: 3.0.15
71
- type: :runtime
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ~>
77
- - !ruby/object:Gem::Version
78
- version: 3.0.15
79
- - !ruby/object:Gem::Dependency
80
- name: cancan
81
- requirement: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - ! '>='
85
- - !ruby/object:Gem::Version
86
- version: '0'
87
- type: :runtime
88
- prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
95
- - !ruby/object:Gem::Dependency
96
- name: will_paginate_mongoid
97
- requirement: !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ! '>='
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- type: :runtime
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
63
  description: This is the auth module of mix-rails
112
64
  email:
113
65
  - sadjow@gmail.com
@@ -116,25 +68,31 @@ executables: []
116
68
  extensions: []
117
69
  extra_rdoc_files: []
118
70
  files:
71
+ - app/controllers/admix/roles_controller.rb
72
+ - app/controllers/admix/users_controller.rb
119
73
  - app/assets/stylesheets/admix/users.css
120
74
  - app/assets/javascripts/admix/users.js
121
- - app/views/admix/users/_form_fields.html.haml
122
- - app/views/admix/users/_table_actions.html.haml
123
- - app/views/admix/users/_show.html.haml
124
- - app/controllers/admix/users_controller.rb
125
- - app/models/user.rb
126
- - app/models/admix/users_datagrid.rb
127
- - app/models/ability.rb
128
75
  - app/helpers/admix/users_helper.rb
129
- - config/initializers/devise.rb
130
- - config/routes.rb
76
+ - app/models/admix/roles_datagrid.rb
77
+ - app/models/admix/users_datagrid.rb
78
+ - app/models/user.rb
79
+ - app/models/role.rb
80
+ - app/views/admix/roles/_show.html.haml
81
+ - app/views/admix/roles/_table_actions.html.haml
82
+ - app/views/admix/roles/_form_fields.html.haml
83
+ - app/views/admix/users/_show.html.haml
84
+ - app/views/admix/users/_table_actions.html.haml
85
+ - app/views/admix/users/_form_fields.html.haml
131
86
  - config/sessions.rb
87
+ - config/locales/auth.en.yml
132
88
  - config/locales/devise.pt-BR.yml
133
- - config/locales/auth.pt-BR.yml
134
89
  - config/locales/devise.en.yml
135
- - config/locales/auth.en.yml
136
- - lib/mix-rails-auth.rb
90
+ - config/locales/auth.pt-BR.yml
91
+ - config/initializers/rolify.rb
92
+ - config/initializers/devise.rb
93
+ - config/routes.rb
137
94
  - lib/tasks/auth_tasks.rake
95
+ - lib/mix-rails-auth.rb
138
96
  - lib/mix-rails-auth/version.rb
139
97
  - lib/mix-rails-auth/engine.rb
140
98
  - MIT-LICENSE
@@ -154,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
112
  version: '0'
155
113
  segments:
156
114
  - 0
157
- hash: 3132266013216500903
115
+ hash: -1563147382618436220
158
116
  required_rubygems_version: !ruby/object:Gem::Requirement
159
117
  none: false
160
118
  requirements:
@@ -163,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
121
  version: '0'
164
122
  segments:
165
123
  - 0
166
- hash: 3132266013216500903
124
+ hash: -1563147382618436220
167
125
  requirements: []
168
126
  rubyforge_project:
169
127
  rubygems_version: 1.8.24
@@ -1,28 +0,0 @@
1
- class Ability
2
- include CanCan::Ability
3
-
4
- def initialize(user)
5
- # Define abilities for the passed in user here. For example:
6
- #
7
- user ||= User.new # guest user (not logged in)
8
- if true #user.is?(:admin)
9
- can :manage, :all
10
- else
11
- can :read, :all
12
- end
13
- #
14
- # The first argument to `can` is the action you are giving the user permission to do.
15
- # If you pass :manage it will apply to every action. Other common actions here are
16
- # :read, :create, :update and :destroy.
17
- #
18
- # The second argument is the resource the user can perform the action on. If you pass
19
- # :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
20
- #
21
- # The third argument is an optional hash of conditions to further filter the objects.
22
- # For example, here the user can only update published articles.
23
- #
24
- # can :update, Article, :published => true
25
- #
26
- # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
27
- end
28
- end