Browse Source

- Corrected with rubocop cop 'Style/PredicateName'.
- Removed application_module method 'is_not_role', was never used.
- Renamed Sessions::Backend::Collections methods is_role_set to roles_add.
- Renamed Sessions::Backend::Collections methods is_not_role_set to not_roles_add.

Thorsten Eckel 9 years ago
parent
commit
7f67e6f00a

+ 0 - 2
.rubocop.yml

@@ -200,8 +200,6 @@ Rails/TimeZone:
   Enabled: false
 Lint/RescueException:
   Enabled: false
-Style/PredicateName:
-  Enabled: false
 Style/ClassVars:
   Enabled: false
 Lint/UselessAssignment:

+ 4 - 9
app/controllers/application_controller.rb

@@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
                 :authentication_check,
                 :authentication_check_action_token,
                 :config_frontend,
-                :is_role,
+                :role?,
                 :model_create_render,
                 :model_update_render,
                 :model_restory_render,
@@ -215,10 +215,9 @@ class ApplicationController < ActionController::Base
     true
   end
 
-  def is_role( role_name )
+  def role?( role_name )
     return false if !current_user
-    return true if current_user.is_role( role_name )
-    false
+    current_user.role?( role_name )
   end
 
   def ticket_permission(ticket)
@@ -227,12 +226,8 @@ class ApplicationController < ActionController::Base
     false
   end
 
-  def is_not_role( role_name )
-    deny_if_not_role( role_name )
-  end
-
   def deny_if_not_role( role_name )
-    return false if is_role( role_name )
+    return false if role?( role_name )
     response_access_deny
     true
   end

+ 3 - 3
app/controllers/organizations_controller.rb

@@ -50,7 +50,7 @@ curl http://localhost/api/v1/organizations.json -v -u #{login}:#{password}
 
     # only allow customer to fetch his own organization
     organizations = []
-    if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role(Z_ROLENAME_AGENT)
+    if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?(Z_ROLENAME_AGENT)
       if current_user.organization_id
         organizations = Organization.where( id: current_user.organization_id )
       end
@@ -80,7 +80,7 @@ curl http://localhost/api/v1/organizations/#{id}.json -v -u #{login}:#{password}
   def show
 
     # only allow customer to fetch his own organization
-    if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role(Z_ROLENAME_AGENT)
+    if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?(Z_ROLENAME_AGENT)
       if !current_user.organization_id
         render json: {}
         return
@@ -178,7 +178,7 @@ Test:
   def history
 
     # permissin check
-    if !is_role(Z_ROLENAME_ADMIN) && !is_role(Z_ROLENAME_AGENT)
+    if !role?(Z_ROLENAME_ADMIN) && !role?(Z_ROLENAME_AGENT)
       response_access_deny
       return
     end

+ 1 - 1
app/controllers/search_controller.rb

@@ -7,7 +7,7 @@ class SearchController < ApplicationController
   def search_user_org
 
     # enable search only for agents and admins
-    if !current_user.is_role(Z_ROLENAME_AGENT) && !current_user.is_role(Z_ROLENAME_ADMIN)
+    if !current_user.role?(Z_ROLENAME_AGENT) && !current_user.role?(Z_ROLENAME_ADMIN)
       response_access_deny
       return true
     end

+ 1 - 1
app/controllers/sessions/collection_base.rb

@@ -26,7 +26,7 @@ module ExtraCollection
     Group.all.each {|item|
       assets = item.assets(assets)
     }
-    if !user.is_role(Z_ROLENAME_CUSTOMER)
+    if !user.role?(Z_ROLENAME_CUSTOMER)
       collections[ Organization.to_app_model ] = []
       Organization.all.each {|item|
         assets = item.assets(assets)

+ 1 - 1
app/controllers/sessions/collection_ticket.rb

@@ -24,7 +24,7 @@ module ExtraCollection
     Ticket::Article::Sender.all.each {|item|
       assets = item.assets(assets)
     }
-    if !user.is_role(Z_ROLENAME_CUSTOMER)
+    if !user.role?(Z_ROLENAME_CUSTOMER)
 
       # all signatures
       collections[ Signature.to_app_model ] = []

+ 1 - 1
app/controllers/tickets_controller.rb

@@ -239,7 +239,7 @@ class TicketsController < ApplicationController
     articles.each {|article|
 
       # ignore internal article if customer is requesting
-      next if article.internal == true && is_role(Z_ROLENAME_CUSTOMER)
+      next if article.internal == true && role?(Z_ROLENAME_CUSTOMER)
 
       # load article ids
       article_ids.push article.id

+ 11 - 11
app/controllers/users_controller.rb

@@ -15,7 +15,7 @@ class UsersController < ApplicationController
   def index
 
     # only allow customer to fetch him self
-    if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role('Agent')
+    if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
       users = User.where( id: current_user.id )
     else
       users = User.all
@@ -203,17 +203,17 @@ class UsersController < ApplicationController
       user.update_attributes( User.param_cleanup(params) )
 
       # only allow Admin's and Agent's
-      if is_role(Z_ROLENAME_ADMIN) && is_role('Agent') && params[:role_ids]
+      if role?(Z_ROLENAME_ADMIN) && role?('Agent') && params[:role_ids]
         user.role_ids = params[:role_ids]
       end
 
       # only allow Admin's
-      if is_role(Z_ROLENAME_ADMIN) && params[:group_ids]
+      if role?(Z_ROLENAME_ADMIN) && params[:group_ids]
         user.group_ids = params[:group_ids]
       end
 
       # only allow Admin's and Agent's
-      if is_role(Z_ROLENAME_ADMIN) && is_role('Agent') && params[:organization_ids]
+      if role?(Z_ROLENAME_ADMIN) && role?('Agent') && params[:organization_ids]
         user.organization_ids = params[:organization_ids]
       end
 
@@ -260,7 +260,7 @@ class UsersController < ApplicationController
   # @response_message 401               Invalid session.
   def search
 
-    if is_role(Z_ROLENAME_CUSTOMER) && !is_role(Z_ROLENAME_ADMIN) && !is_role('Agent')
+    if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
       response_access_deny
       return
     end
@@ -324,7 +324,7 @@ class UsersController < ApplicationController
   def history
 
     # permissin check
-    if !is_role(Z_ROLENAME_ADMIN) && !is_role('Agent')
+    if !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
       response_access_deny
       return
     end
@@ -715,19 +715,19 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content
   end
 
   def permission_check_by_role
-    return true if is_role(Z_ROLENAME_ADMIN)
-    return true if is_role('Agent')
+    return true if role?(Z_ROLENAME_ADMIN)
+    return true if role?('Agent')
 
     response_access_deny
     false
   end
 
   def permission_check
-    return true if is_role(Z_ROLENAME_ADMIN)
-    return true if is_role('Agent')
+    return true if role?(Z_ROLENAME_ADMIN)
+    return true if role?('Agent')
 
     # allow to update customer by him self
-    return true if is_role(Z_ROLENAME_CUSTOMER) && params[:id].to_i == current_user.id
+    return true if role?(Z_ROLENAME_CUSTOMER) && params[:id].to_i == current_user.id
 
     response_access_deny
     false

+ 1 - 1
app/models/object_manager.rb

@@ -191,7 +191,7 @@ returns:
           roles_options.each {|role, options|
             if role == '-all-'
               data[:screen][screen] = options
-            elsif user && user.is_role(role)
+            elsif user && user.role?(role)
               data[:screen][screen] = options
             end
           }

+ 3 - 3
app/models/organization/permission.rb

@@ -19,7 +19,7 @@ returns
     def permission (data)
 
       # check customer
-      if data[:current_user].is_role('Customer')
+      if data[:current_user].role?('Customer')
 
         # access ok if its own organization
         return false if data[:type] != 'ro'
@@ -31,8 +31,8 @@ returns
       end
 
       # check agent
-      return true if data[:current_user].is_role(Z_ROLENAME_ADMIN)
-      return true if data[:current_user].is_role('Agent')
+      return true if data[:current_user].role?(Z_ROLENAME_ADMIN)
+      return true if data[:current_user].role?('Agent')
       false
     end
   end

Some files were not shown because too many files changed in this diff