mix-auth 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
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 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
data/app/models/user.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  class User
2
2
  include Mongoid::Document
3
+
4
+ ROLES = %w[admin content_manager]
5
+
6
+ attr_accessible :roles
7
+
3
8
  # Include default devise modules. Others available are:
4
9
  # :token_authenticatable, :confirmable,
5
10
  # :lockable, :timeoutable and :omniauthable
@@ -26,6 +31,7 @@ class User
26
31
  field :last_sign_in_at, :type => Time
27
32
  field :current_sign_in_ip, :type => String
28
33
  field :last_sign_in_ip, :type => String
34
+
29
35
 
30
36
  ## Confirmable
31
37
  # field :confirmation_token, :type => String
@@ -40,4 +46,23 @@ class User
40
46
 
41
47
  ## Token authenticatable
42
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
67
+
43
68
  end
@@ -0,0 +1,7 @@
1
+ = f.input :email, as: 'string'
2
+ = f.input :password, as: 'password'
3
+ - for role in User::ROLES
4
+ = check_box_tag "user[roles][#{role}]", role, @user.roles.include?(role), {:name => "user[roles][]"}
5
+ = label_tag "user_roles_#{role}", role.humanize
6
+ %br
7
+ = hidden_field_tag "user[roles][]", ""
@@ -0,0 +1,7 @@
1
+ %dl
2
+ %dt= t('albums.name')
3
+ %dd= resource.name
4
+ %dt= t('albums.date')
5
+ %dd= resource.date
6
+
7
+ = render('admix/photos/upload')
@@ -0,0 +1,4 @@
1
+ = link_to image_tag('albums/photos.png'), resource_url([resource, :photos])
2
+ = link_to image_tag('admix/zoom.png'), resource_url(resource)
3
+ = link_to image_tag('admix/page_edit.png'), edit_resource_url(resource)
4
+ = link_to image_tag('admix/cancel.png'), resource_url(resource), method: :delete, data: { confirm: t('admix.crud.destroy_confirm') }
data/lib/auth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Auth
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mix-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.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-10 00:00:00.000000000 Z
13
+ date: 2013-01-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -76,6 +76,22 @@ dependencies:
76
76
  - - ~>
77
77
  - !ruby/object:Gem::Version
78
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'
79
95
  - !ruby/object:Gem::Dependency
80
96
  name: mix-rails
81
97
  requirement: !ruby/object:Gem::Requirement
@@ -121,7 +137,11 @@ files:
121
137
  - app/assets/javascripts/admix/users.js
122
138
  - app/helpers/admix/users_helper.rb
123
139
  - app/models/admix/users_datagrid.rb
140
+ - app/models/ability.rb
124
141
  - app/models/user.rb
142
+ - app/views/admix/users/_show.html.haml
143
+ - app/views/admix/users/_table_actions.html.haml
144
+ - app/views/admix/users/_form_fields.html.haml
125
145
  - config/locales/auth.en.yml
126
146
  - config/locales/devise.pt-BR.yml
127
147
  - config/locales/devise.en.yml
@@ -150,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
170
  version: '0'
151
171
  segments:
152
172
  - 0
153
- hash: -1870393188419666116
173
+ hash: 2479283267806110614
154
174
  required_rubygems_version: !ruby/object:Gem::Requirement
155
175
  none: false
156
176
  requirements:
@@ -159,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
179
  version: '0'
160
180
  segments:
161
181
  - 0
162
- hash: -1870393188419666116
182
+ hash: 2479283267806110614
163
183
  requirements: []
164
184
  rubyforge_project:
165
185
  rubygems_version: 1.8.24