usman 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8545e2e5dc538e357611ef4599c6516144efe87
4
- data.tar.gz: 350db031459f0ac0625965a192cf1d2354048f57
3
+ metadata.gz: 305e0b1f3fcbaf48dfa3ef61edcc5fc8f1f735c7
4
+ data.tar.gz: 0f29c10f24fe0a2a18fe7c30b3f48b3f37d57ae8
5
5
  SHA512:
6
- metadata.gz: 057c92a4cc8580cf368bf03d3ce396b44b70e9cdd1e83caeb61c6e35964f04b1baf42cf70d12533ef1f2bfff1d9061cae908140cd1fa00ade3c6f9896ff9836b
7
- data.tar.gz: 50ea37f84bd1e935adc41381b79eccec7aa6be570f938292aefd17b68cb35b99f95fe5cb99ff08851bc2ca0166018b4b012295e108429a96de9445e51bc08831
6
+ metadata.gz: edca824f4e840bd5fd8786455cdd5f598d2543caa35060aca8f221270c0ee3b16800526620f0976d6b600e2f1c3b456a5bb7e4d555a988fcd0b3c264ed2cf730
7
+ data.tar.gz: 929e61aa9eddab89d2658005482b6abbf1e00c28302286f49dafe4adae2dbe534ea4b9e4f20df18456a39d70e58361f0aaa09897f3d75f184fdc89366e0551cc
@@ -8,6 +8,7 @@ module Usman
8
8
  include Usman::ApiHelper
9
9
 
10
10
  before_action :require_api_token
11
+ after_action :store_last_accessed_api
11
12
 
12
13
  end
13
14
  end
@@ -3,6 +3,20 @@ module Usman
3
3
 
4
4
  before_action :require_site_admin
5
5
 
6
+ def update_status
7
+ @registration = @r_object = Registration.find(params[:id])
8
+ case params[:status]
9
+ when "pending"
10
+ @registration.pending!
11
+ when "verified"
12
+ @registration.verify!
13
+ when "suspended"
14
+ @registration.suspend!
15
+ end
16
+ set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @r_object.status))
17
+ render_row
18
+ end
19
+
6
20
  private
7
21
 
8
22
  def get_collections
@@ -39,6 +39,29 @@ module Usman
39
39
  else
40
40
  @current_user = @current_device.try(:registration).try(:user)
41
41
  end
42
+ if @current_user
43
+ if @current_user.pending?
44
+ proc_code = Proc.new do
45
+ @success = false
46
+ @errors = {
47
+ heading: I18n.translate("api.general.user_is_pending.heading"),
48
+ message: I18n.translate("api.general.user_is_pending.message")
49
+ }
50
+ end
51
+ render_json_response(proc_code)
52
+ return
53
+ elsif @current_user.suspended?
54
+ proc_code = Proc.new do
55
+ @success = false
56
+ @errors = {
57
+ heading: I18n.translate("api.general.user_is_suspended.heading"),
58
+ message: I18n.translate("api.general.user_is_suspended.message")
59
+ }
60
+ end
61
+ render_json_response(proc_code)
62
+ return
63
+ end
64
+ end
42
65
  end
43
66
 
44
67
  def require_super_admin_auth_token
@@ -64,5 +87,16 @@ module Usman
64
87
  return
65
88
  end
66
89
  end
90
+
91
+ def store_last_accessed_api
92
+ if @current_device
93
+ # Know what was the last API accessed and when
94
+ # This is to catch the users who are inactive
95
+ @current_device.last_accessed_api = request.original_url
96
+ @current_device.last_accessed_at = Time.now
97
+ @current_device.save
98
+ end
99
+ end
100
+
67
101
  end
68
102
  end
data/app/models/device.rb CHANGED
@@ -169,6 +169,7 @@ class Device < ApplicationRecord
169
169
 
170
170
  self.verify!
171
171
  self.registration.verify!
172
+ self.registration.user.approve! if self.registration.user
172
173
 
173
174
  # Clearing the OTP so that next time if he uses the same, it shows error
174
175
  self.otp = nil
@@ -5,15 +5,18 @@ class Registration < ApplicationRecord
5
5
 
6
6
  PENDING = "pending"
7
7
  VERIFIED = "verified"
8
+ SUSPENDED = "suspended"
8
9
 
9
10
  STATUS = {
10
11
  PENDING => "Pending",
11
- VERIFIED => "Verified"
12
+ VERIFIED => "Verified",
13
+ SUSPENDED => "Suspended"
12
14
  }
13
15
 
14
16
  STATUS_REVERSE = {
15
17
  "Pending" => PENDING,
16
- "Verified" => VERIFIED
18
+ "Verified" => VERIFIED,
19
+ "Suspended" => SUSPENDED
17
20
  }
18
21
 
19
22
  # Associations
@@ -37,12 +40,15 @@ class Registration < ApplicationRecord
37
40
  # >>> registration.search(query)
38
41
  # => ActiveRecord::Relation object
39
42
  scope :search, lambda {|query| joins("LEFT JOIN users on users.id = registrations.user_id").
40
- where("LOWER(registrations.mobile_number) LIKE LOWER('%#{query}%') OR
41
- LOWER(users.name) LIKE LOWER('%#{query}%')")}
43
+ where("LOWER(registrations.mobile_number) LIKE LOWER('%#{query}%') OR
44
+ LOWER(users.name) LIKE LOWER('%#{query}%') OR
45
+ LOWER(users.email) LIKE LOWER('%#{query}%') OR
46
+ LOWER(users.username) LIKE LOWER('%#{query}%')")}
42
47
  scope :status, lambda { |status| where("LOWER(status)='#{status}'") }
43
48
 
44
49
  scope :pending, -> { where(status: PENDING) }
45
50
  scope :verified, -> { where(status: VERIFIED) }
51
+ scope :suspended, -> { where(status: SUSPENDED) }
46
52
 
47
53
  # ------------------
48
54
  # Instance Methods
@@ -77,6 +83,14 @@ class Registration < ApplicationRecord
77
83
  (status == VERIFIED)
78
84
  end
79
85
 
86
+ # * Return true if the user is suspended, else false.
87
+ # == Examples
88
+ # >>> registration.suspended?
89
+ # => true
90
+ def suspended?
91
+ (status == SUSPENDED)
92
+ end
93
+
80
94
  # change the status to :verified
81
95
  # Return the status
82
96
  # == Examples
@@ -84,6 +98,7 @@ class Registration < ApplicationRecord
84
98
  # => "pending"
85
99
  def pending!
86
100
  self.update_attribute(:status, PENDING)
101
+ self.user.update_attribute(:status, PENDING) if self.user
87
102
  end
88
103
 
89
104
  # change the status to :verified
@@ -93,6 +108,17 @@ class Registration < ApplicationRecord
93
108
  # => "verified"
94
109
  def verify!
95
110
  self.update_attribute(:status, VERIFIED)
111
+ self.user.update_attribute(:status, VERIFIED) if self.user
112
+ end
113
+
114
+ # change the status to :suspended
115
+ # Return the status
116
+ # == Examples
117
+ # >>> registration.suspend!
118
+ # => "suspended"
119
+ def suspend!
120
+ self.update_attribute(:status, SUSPENDED)
121
+ self.user.update_attribute(:status, SUSPENDED) if self.user
96
122
  end
97
123
 
98
124
  # Permission Methods
data/app/models/user.rb CHANGED
@@ -173,6 +173,7 @@ class User < Usman::ApplicationRecord
173
173
  # => "pending"
174
174
  def pending!
175
175
  self.update_attribute(:status, PENDING)
176
+ self.registration.update_attribute(:status, PENDING) if self.registration
176
177
  end
177
178
 
178
179
  # change the status to :approved
@@ -182,6 +183,7 @@ class User < Usman::ApplicationRecord
182
183
  # => "approved"
183
184
  def approve!
184
185
  self.update_attribute(:status, APPROVED)
186
+ self.registration.update_attribute(:status, Registration::VERIFIED) if self.registration
185
187
  end
186
188
 
187
189
  # change the status to :suspended
@@ -191,6 +193,7 @@ class User < Usman::ApplicationRecord
191
193
  # => "suspended"
192
194
  def suspend!
193
195
  self.update_attribute(:status, SUSPENDED)
196
+ self.registration.update_attribute(:status, SUSPENDED) if self.registration
194
197
  end
195
198
 
196
199
  # Gender Methods
@@ -52,7 +52,10 @@
52
52
 
53
53
  <ul>
54
54
  <li class="<%= nav_class("admin/users") %>">
55
- <%= link_to raw("<i class=\"linecons-user\"></i> <span class='title'>Manage Users</span>"), usman.users_url %>
55
+ <%= link_to raw("<i class=\"fa-user\"></i> <span class='title'>Manage Users</span>"), usman.users_url %>
56
+ </li>
57
+ <li class="<%= nav_class("admin/registrations") %>">
58
+ <%= link_to raw("<i class=\"fa-mobile\"></i> <span class='title'>Manage Registrations</span>"), usman.registrations_url %>
56
59
  </li>
57
60
  </ul>
58
61
  </li>
@@ -88,6 +91,10 @@
88
91
  <%= link_to raw("<i class=\"linecons-diamond\"></i> <span class='title'>Manage Features</span>"), usman.features_url %>
89
92
  </li>
90
93
 
94
+ <li class="">
95
+ <%= link_to raw("<i class=\"linecons-graduation-cap\"></i> <span class='title'>Manage Roles</span>"), usman.roles_url %>
96
+ </li>
97
+
91
98
  <li class="<%= nav_class("admin/users") %>">
92
99
  <%= link_to raw("<i class=\"linecons-lock\"></i> <span class='title'>Manage Permissions</span>"), usman.permissions_url %>
93
100
  </li>
@@ -6,7 +6,7 @@ api_input = <<-eos
6
6
  Example:
7
7
 
8
8
  Authorization: nil
9
- GET #{request.base_url}/api/v1/profile/profile_picture
9
+ GET #{request.base_url}/api/v1/profile_info
10
10
  eos
11
11
 
12
12
  api_output = <<-eos
@@ -6,7 +6,7 @@ api_input = <<-eos
6
6
  Example:
7
7
 
8
8
  Authorization: Token token="87b01adbba90824b57add8cc06ad8738"
9
- GET #{request.base_url}/api/v1/profile/profile_picture
9
+ GET #{request.base_url}/api/v1/profile_info
10
10
  eos
11
11
 
12
12
  api_output = <<-eos
@@ -6,7 +6,7 @@ api_input = <<-eos
6
6
  Example:
7
7
 
8
8
  Authorization: Token token="87b01adbba90824b57add8cc06ad8738"
9
- GET #{request.base_url}/api/v1/profile/profile_picture
9
+ GET #{request.base_url}/api/v1/profile_info
10
10
  eos
11
11
 
12
12
  api_output = <<-eos
@@ -10,6 +10,16 @@
10
10
  text: "Users",
11
11
  icon_class: "fa-user",
12
12
  url: usman.users_url
13
+ },
14
+ registrations: {
15
+ counts: {
16
+ total: Registration.count,
17
+ pending: Registration.pending.count,
18
+ verified: Registration.verified.count
19
+ },
20
+ text: "Registrations",
21
+ icon_class: "fa-mobile",
22
+ url: usman.registrations_url
13
23
  }
14
24
  }
15
25
  %>
@@ -116,3 +126,12 @@
116
126
 
117
127
  </div>
118
128
  <% end %>
129
+
130
+
131
+ <div class="dx-warning">
132
+ <div>
133
+ <h2>Usman - API Documentation</h2>
134
+ <p>All APIs are documented with all cases and examples.</p>
135
+ <a class="btn btn-success" href="/docs/api/v1/register" target="_blank">Go to the API Documentation</a>
136
+ </div>
137
+ </div>
@@ -2,11 +2,12 @@
2
2
  <table class="table table-hover members-table middle-align">
3
3
  <thead>
4
4
  <tr>
5
- <th style="text-align: center;width:50px;">#</th>
5
+ <th style="text-align: center;width:5%;">#</th>
6
6
  <th style="text-align: left;">User</th>
7
- <th style="text-align: left;width:200px;">Mobile</th>
8
- <th style="text-align: left;width:200px;">Location</th>
9
- <th style="text-align: left;width:200px;">Status</th>
7
+ <th style="text-align: left;width:15%;">Mobile</th>
8
+ <th style="text-align: left;width:15%;">Location</th>
9
+ <th>Status</th>
10
+ <th style="text-align: center;width:15%;">Actions</th>
10
11
  </tr>
11
12
  </thead>
12
13
 
@@ -41,8 +42,23 @@
41
42
  <span class="ml-5 mt-5 label label-default">Pending</span>
42
43
  <% elsif registration.verified? %>
43
44
  <span class="ml-5 mt-5 label label-success">Verified</span>
45
+ <% elsif registration.suspended? %>
46
+ <span class="ml-5 mt-5 label label-danger">Suspended</span>
44
47
  <% end %>
45
48
  </td>
49
+
50
+ <td class="action-links" style="width:15%">
51
+
52
+ <!-- Mark as Pending -->
53
+ <%= link_to raw("<i class=\"fa fa-circle mr-5\"></i> Mark as Pending"), update_status_registration_path(:id =>registration.id, :status =>'pending'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1" unless registration.pending? %>
54
+
55
+ <!-- Verify -->
56
+ <%= link_to raw("<i class=\"fa fa-circle-o mr-5\"></i> Verify"), update_status_registration_path(:id =>registration.id, :status =>'verified'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1" unless registration.verified? %>
57
+
58
+ <!-- Suspend -->
59
+ <%= link_to raw("<i class=\"fa fa-edit mr-5\"></i> Suspend"), update_status_registration_path(:id =>registration.id, :status =>'suspended'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1" unless registration.suspended? %>
60
+
61
+ </td>
46
62
 
47
63
  <!-- <td class="action-links" style="width:10%">
48
64
  <%#= link_to raw("<i class=\"linecons-pencil\"></i> Edit Registration"), edit_link, :remote=>true, class: "edit" if @current_user.super_admin? and registration.can_be_edited? %>
@@ -1,8 +1,5 @@
1
- <% edit_link = edit_registration_path(id: registration.id) %>
2
- <% delete_link = registration_path(id: registration.id) %>
3
-
4
1
  <tr id="tr_registration_<%= registration.id %>">
5
-
2
+
6
3
  <th scope="row" style="text-align: center;">
7
4
  <% if i < 0 %>
8
5
  <i class="fa fa-check text-success"></i>
@@ -11,14 +8,43 @@
11
8
  <% end %>
12
9
  </th>
13
10
 
14
- <td class="registration-name"><%= link_to registration.name, registration_path(registration), remote: true %></td>
11
+ <% if registration.user %>
12
+ <td class="registration-name"><%= link_to registration.user.display_name, registration_path(registration), remote: true %></td>
13
+ <% else %>
14
+ <td class="registration-name"><%= link_to registration.display_name, registration_path(registration), remote: true %></td>
15
+ <% end %>
16
+
17
+ <td class="registration-name"><%= link_to registration.display_name, registration_path(registration), remote: true %></td>
18
+
19
+ <td class="registration-name"><%= link_to registration.display_location, registration_path(registration), remote: true %></td>
20
+
21
+ <td>
22
+ <% if registration.pending? %>
23
+ <span class="ml-5 mt-5 label label-default">Pending</span>
24
+ <% elsif registration.verified? %>
25
+ <span class="ml-5 mt-5 label label-success">Verified</span>
26
+ <% elsif registration.suspended? %>
27
+ <span class="ml-5 mt-5 label label-danger">Suspended</span>
28
+ <% end %>
29
+ </td>
15
30
 
16
- <td class="action-links" style="width:10%">
31
+ <td class="action-links" style="width:15%">
17
32
 
18
- <%= link_to raw("<i class=\"linecons-pencil\"></i> Edit Registration"), edit_link, :remote=>true, class: "edit" if @current_user.super_admin? and registration.can_be_edited? %>
33
+ <!-- Mark as Pending -->
34
+ <%= link_to raw("<i class=\"fa fa-circle mr-5\"></i> Mark as Pending"), update_status_registration_path(:id =>registration.id, :status =>'pending'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1" unless registration.pending? %>
35
+
36
+ <!-- Verify -->
37
+ <%= link_to raw("<i class=\"fa fa-circle-o mr-5\"></i> Verify"), update_status_registration_path(:id =>registration.id, :status =>'verified'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1" unless registration.verified? %>
19
38
 
20
- <%= link_to raw("<i class=\"linecons-trash\"></i> Delete"), delete_link, method: :delete, registration: "menuitem", tabindex: "-1", data: { confirm: 'Are you sure?' }, :remote=>true, class: "delete" if @current_user.super_admin? and registration.can_be_deleted? %>
39
+ <!-- Suspend -->
40
+ <%= link_to raw("<i class=\"fa fa-edit mr-5\"></i> Suspend"), update_status_registration_path(:id =>registration.id, :status =>'suspended'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1" unless registration.suspended? %>
21
41
 
22
42
  </td>
43
+
44
+ <!-- <td class="action-links" style="width:10%">
45
+ <%#= link_to raw("<i class=\"linecons-pencil\"></i> Edit Registration"), edit_link, :remote=>true, class: "edit" if @current_user.super_admin? and registration.can_be_edited? %>
46
+
47
+ <%#= link_to raw("<i class=\"linecons-trash\"></i> Delete"), delete_link, method: :delete, registration: "menuitem", tabindex: "-1", data: { confirm: 'Are you sure?' }, :remote=>true, class: "delete" if @current_user.super_admin? and registration.can_be_deleted? %>
48
+ </td> -->
23
49
 
24
50
  </tr>
@@ -5,7 +5,17 @@
5
5
 
6
6
  <div class="row">
7
7
 
8
- <div class="col-md-9 col-sm-12 col-xs-12" style="border-right:1px solid #f1f1f1;">
8
+ <% if @user %>
9
+ <div class="col-md-3 col-sm-6 col-xs-6" style="border-right:1px solid #f1f1f1;">
10
+ <%= edit_image(@user,
11
+ "profile_picture.image.large.url",
12
+ upload_image_link(@user, :profile_picture, nil ),
13
+ remove_image_link(@user, :profile_picture, nil ),
14
+ image_options: {assoc_name: :profile_picture }) %>
15
+ </div>
16
+ <% end %>
17
+
18
+ <div class="col-md-9 col-sm-6 col-xs-6" style="border-right:1px solid #f1f1f1;">
9
19
 
10
20
  <div class="visible-sm visible-xs mt-50"></div>
11
21
 
@@ -11,7 +11,7 @@ en:
11
11
  message: "Invalid Username/Email or password."
12
12
  user_is_pending:
13
13
  heading: "Account Pending"
14
- message: "Your account is not yet approved, please contact administrator to activate your account"
14
+ message: "Your account is not yet to be approved, please contact administrator to activate your account"
15
15
  user_is_suspended:
16
16
  heading: "Account Suspended"
17
17
  message: "Your account is suspended, please contact administrator"
@@ -21,5 +21,8 @@ en:
21
21
  logged_out:
22
22
  heading: "Signed Out"
23
23
  message: "You have successfully signed out"
24
+ login_required:
25
+ heading: "Login Required"
26
+ message: "You need to login to access this page."
24
27
  masquerade: "لقد سجلت الدخول بنجاح - %{user}"
25
28
  sign_in_back: "You have successfully signed in back as %{user}"
data/config/routes.rb CHANGED
@@ -18,6 +18,9 @@ Usman::Engine.routes.draw do
18
18
 
19
19
  resources :registrations, only: [:index, :show] do
20
20
  resources :devices, :controller => "registration_devices", only: [:index, :show]
21
+ member do
22
+ put :update_status, as: :update_status
23
+ end
21
24
  end
22
25
 
23
26
  resources :users do
data/lib/usman/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Usman
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kpvarma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-24 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails