usman 0.1.5dev3 → 0.1.5dev4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 282cec83d33da8573012b77b4317338c0e15ad69
4
- data.tar.gz: b5af5bb9d890bbcdd9fa401d85af2e4d06cf3125
3
+ metadata.gz: 908dce0296be6976f2db177e9586962af623052d
4
+ data.tar.gz: b5b7162ad3de55dc217bdb1057d27c2a87b0ca9d
5
5
  SHA512:
6
- metadata.gz: eb9ebdd170834a60847044c811dc3be70da654237d0ba7a8d7ae355ae1c79d1136012e5b3f13ba8fdaf46239172ca19b9f69c353ab28a059b14cc84dc1e1951f
7
- data.tar.gz: 148a16128404efd56fb2990ae0b664ab68946bf2c8fc7780b3dfb7580df687d43e77c84e42bf50cbaa0a7690454dc704fbd230e43553f163005ec39819cb69f5
6
+ metadata.gz: f27ef6f08daeeade4c7d67e6f4408f9cd78cb275c4590388258f26eec4e0e0c7316f9a5c09b7aa3cb5d5c34b5518a296af2591813033989f2832350e1af9d5b7
7
+ data.tar.gz: a7e54900294fd49152a56307ad33725837f39b9ed1794ac747036650df08621ae3e7012d0eb310df8e4493e029c33d3ab197e51279613e60319eea2cc74de15f
@@ -59,7 +59,7 @@ module Usman
59
59
 
60
60
  # Normal users should not be able to view super admins
61
61
  # He should not be seeing admins even while searching
62
- if @current_user.is_super_admin?
62
+ if @current_user.super_admin?
63
63
  @relation = @relation.where("super_admin IS #{@super_admin.to_s.upcase}") if @super_admin.nil? == false && @query.nil?
64
64
  else
65
65
  @relation = @relation.where("super_admin IS FALSE")
@@ -89,7 +89,7 @@ module Usman
89
89
  redirect_or_popup_to_default_sign_in_page
90
90
  return
91
91
  else
92
- @current_user.update_token if @current_user.token_about_to_expire?
92
+ @current_user.update_token! if @current_user.token_about_to_expire?
93
93
  end
94
94
  else
95
95
  text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
@@ -102,7 +102,7 @@ module Usman
102
102
 
103
103
  # This method is usually used as a before filter from admin controllers to ensure that the logged in user is a super admin
104
104
  def require_super_admin
105
- unless @current_user.is_super_admin?
105
+ unless @current_user.super_admin?
106
106
  text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
107
107
  set_flash_message(text, :error, false) if defined?(flash) && flash
108
108
 
@@ -23,7 +23,7 @@ class Feature < Usman::ApplicationRecord
23
23
  has_one :feature_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::FeatureImage"
24
24
 
25
25
  # Validations
26
- validates :name, presence: true
26
+ validates :name, presence: true, length: {minimum: 3, maximum: 250}
27
27
  validates :status, :presence => true, :inclusion => {:in => STATUS.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
28
28
 
29
29
  # ------------------
@@ -67,13 +67,12 @@ class Feature < Usman::ApplicationRecord
67
67
  return error_object
68
68
  end
69
69
 
70
- # * Return full name
71
- # == Examples
72
- # >>> feature.display_name
73
- # => "Products"
74
- def display_name
75
- "#{name}"
76
- end
70
+ # ------------------
71
+ # Instance Methods
72
+ # ------------------
73
+
74
+ # Status Methods
75
+ # --------------
77
76
 
78
77
  # * Return true if the user is not published, else false.
79
78
  # == Examples
@@ -126,6 +125,9 @@ class Feature < Usman::ApplicationRecord
126
125
  self.update_attribute(:status, DISABLED)
127
126
  end
128
127
 
128
+ # Permission Methods
129
+ # ------------------
130
+
129
131
  def can_be_destroyed?
130
132
  return true
131
133
  end
@@ -141,5 +143,16 @@ class Feature < Usman::ApplicationRecord
141
143
  def can_be_removed?
142
144
  published? or unpublished? or disabled?
143
145
  end
146
+
147
+ # Other Methods
148
+ # -------------
149
+
150
+ # * Return full name
151
+ # == Examples
152
+ # >>> feature.display_name
153
+ # => "Products"
154
+ def display_name
155
+ "#{name}"
156
+ end
144
157
 
145
158
  end
data/app/models/user.rb CHANGED
@@ -25,7 +25,7 @@ class User < Usman::ApplicationRecord
25
25
  SESSION_TIME_OUT = 120.minutes
26
26
 
27
27
  # Validations
28
- validates :name, presence: true
28
+ validates :name, presence: true, length: {minimum: 3, maximum: 250}
29
29
  validate_username :username
30
30
  validate_email :email
31
31
  validate_password :password, condition_method: :should_validate_password?
@@ -105,14 +105,9 @@ class User < Usman::ApplicationRecord
105
105
  # ------------------
106
106
  # Instance variables
107
107
  # ------------------
108
-
109
- # * Return full name
110
- # == Examples
111
- # >>> user.display_name
112
- # => "Joe Black"
113
- def display_name
114
- "#{name}"
115
- end
108
+
109
+ # Status Methods
110
+ # --------------
116
111
 
117
112
  # * Return true if the user is not approved, else false.
118
113
  # == Examples
@@ -165,9 +160,8 @@ class User < Usman::ApplicationRecord
165
160
  self.update_attribute(:status, SUSPENDED)
166
161
  end
167
162
 
168
- def is_super_admin?
169
- super_admin
170
- end
163
+ # Authentication Methods
164
+ # ----------------------
171
165
 
172
166
  def start_session
173
167
  # FIX ME - specs are not written to ensure that all these data are saved
@@ -185,11 +179,12 @@ class User < Usman::ApplicationRecord
185
179
 
186
180
  def end_session
187
181
  # Reseting the auth token for user when he logs out.
182
+ # Resetting the token_created_at to nil
188
183
  # (Time.now - 1.second)
189
184
  self.update_attributes auth_token: SecureRandom.hex, token_created_at: nil
190
185
  end
191
186
 
192
- def update_token
187
+ def update_token!
193
188
  self.update_attribute(:token_created_at, Time.now)
194
189
  end
195
190
 
@@ -215,9 +210,8 @@ class User < Usman::ApplicationRecord
215
210
  self.reset_password_sent_at = Time.now unless self.reset_password_sent_at
216
211
  end
217
212
 
218
- def default_image_url(size="small")
219
- "/assets/kuppayam/defaults/user-#{size}.png"
220
- end
213
+ # Permission Methods
214
+ # ------------------
221
215
 
222
216
  def set_permission(feature_name, **options)
223
217
  options.reverse_merge!(
@@ -282,6 +276,9 @@ class User < Usman::ApplicationRecord
282
276
  !suspended?
283
277
  end
284
278
 
279
+ # Role Methods
280
+ # ------------
281
+
285
282
  def add_role(role)
286
283
  return false unless self.approved?
287
284
  role = Role.find_by_name(role) if role.is_a?(String)
@@ -306,7 +303,21 @@ class User < Usman::ApplicationRecord
306
303
  else
307
304
  return false
308
305
  end
309
-
306
+ end
307
+
308
+ # Other Methods
309
+ # -------------
310
+
311
+ # * Return full name
312
+ # == Examples
313
+ # >>> user.display_name
314
+ # => "Joe Black"
315
+ def display_name
316
+ "#{name}"
317
+ end
318
+
319
+ def default_image_url(size="small")
320
+ "/assets/kuppayam/defaults/user-#{size}.png"
310
321
  end
311
322
 
312
323
  private
@@ -2,8 +2,7 @@ module Usman
2
2
  class ApplicationRecord < ActiveRecord::Base
3
3
  self.abstract_class = true
4
4
 
5
- require 'kuppayam/importer.rb'
6
5
  extend Kuppayam::Importer
7
- extend KuppayamValidators
6
+ extend Kuppayam::Validators
8
7
  end
9
8
  end
@@ -44,7 +44,7 @@
44
44
 
45
45
  <td class="hidden-xs hidden-sm"><%= link_to user.email, admin_user_path(user), remote: true, class: "email" %></td>
46
46
 
47
- <% if @current_user.is_super_admin? %>
47
+ <% if @current_user.super_admin? %>
48
48
  <td class="hidden-xs hidden-sm">
49
49
  <% if user.super_admin? %>
50
50
  <span class="mr-10 mt-5 label label-warning">Super Admin</span>
@@ -27,7 +27,7 @@
27
27
 
28
28
  <td class="hidden-xs hidden-sm"><%= link_to user.email, admin_user_path(user), remote: true, class: "email" %></td>
29
29
 
30
- <% if @current_user.is_super_admin? %>
30
+ <% if @current_user.super_admin? %>
31
31
  <td class="hidden-xs hidden-sm">
32
32
  <% if user.super_admin %>
33
33
  <span class="mr-10 mt-5 label label-warning">Super Admin</span>
@@ -4,7 +4,7 @@
4
4
  <ul class="nav nav-tabs">
5
5
 
6
6
  <%# Show Admin tab only for admins %>
7
- <% if @current_user.is_super_admin? %>
7
+ <% if @current_user.super_admin? %>
8
8
  <li class="<%= @super_admin == false ? 'active' : '' %>">
9
9
  <%= link_to "Users", admin_users_path(sa: '0') %>
10
10
  </li>
@@ -25,7 +25,7 @@
25
25
  </div>
26
26
 
27
27
  <div class="login-header text-center">
28
- <p>Sign in to access the admin area!</p>
28
+ <p>Merchandise Application</p>
29
29
  </div>
30
30
 
31
31
  <div class="form-group">
data/lib/usman/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Usman
2
- VERSION = '0.1.5dev3'
2
+ VERSION = '0.1.5dev4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5dev3
4
+ version: 0.1.5dev4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kpvarma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-07 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -90,14 +90,14 @@ dependencies:
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: 0.1.5dev3
93
+ version: 0.1.5dev4
94
94
  type: :runtime
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: 0.1.5dev3
100
+ version: 0.1.5dev4
101
101
  - !ruby/object:Gem::Dependency
102
102
  name: bcrypt
103
103
  requirement: !ruby/object:Gem::Requirement