Class: Anoubis::Tenant::ApplicationController

Inherits:
Core::ApplicationController show all
Defined in:
app/controllers/anoubis/tenant/application_controller.rb

Direct Known Subclasses

IndexController

Instance Attribute Summary

Attributes inherited from Core::ApplicationController

#current_user, #etc, #exports, #locale, #output, #version, #writer

Instance Method Summary collapse

Methods inherited from Core::ApplicationController

#access_allowed?, #after_initialization, #anubis_core_initialization, #authenticate?, #authentication, #bin_to_uuid, #check_menu_access?, #default_locale, #error_exit, #new_session_id, #new_uuid, #options, #redis, #redis_prefix, #redis_save_user, #set_access_control_headers, #token, #uuid_to_bin

Instance Method Details

#get_user_modelActiveRecord

Get current user model

Returns:

  • (ActiveRecord)

    defined user model. It is used for get current user data. May be redefined when user model is changed



5
6
7
# File 'app/controllers/anoubis/tenant/application_controller.rb', line 5

def get_user_model
  Anoubis::Tenant::User
end

#get_user_model_exceptArray

Get current user model filed json exception

Returns:

  • (Array)

    defined user exception for to_json function



12
13
14
# File 'app/controllers/anoubis/tenant/application_controller.rb', line 12

def get_user_model_except
  [:uuid_bin]
end

Check menu access for current user of current controller

Returns:

  • (Boolean)

    if true, then user have access for this controller.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/anoubis/tenant/application_controller.rb', line 19

def menu_access(controller, exit = true)
  menu_access_status = redis.get self.redis_prefix + self.current_user.uuid+'_'+controller

  if !menu_access_status
    access = Anoubis::Tenant::GroupMenu.accesses[:read].to_s+','+Anoubis::Tenant::GroupMenu.accesses[:write].to_s
    query = "        SELECT `t`.* FROM\n          (SELECT `menus`.`id`, `menus`.`mode`, `menus`.`action`, `menus`.`menu_id`,\n            MAX(`group_menus`.`access`) AS `access`, `user_groups`.`user_id`\n          FROM `menus`, `group_menus`, `groups`, `user_groups`\n          WHERE `menus`.`mode` = '\#{controller}' AND `menus`.`id` = `group_menus`.`menu_id` AND\n            `menus`.`status` = 0 AND `group_menus`.`group_id` = `groups`.`id` AND `groups`.`id` = `user_groups`.`group_id` AND \n            `user_groups`.`user_id` = \#{self.current_user.id}\n          GROUP BY `menus`.`id`) AS `t`\n          WHERE `t`.`access` IN (\#{access})\n          ORDER BY `t`.`menu_id`\n    SQL\n    menu = Anoubis::Tenant::GroupMenu.find_by_sql(query).first\n    if (!menu)\n      redis.set self.redis_prefix + self.current_user.uuid+'_'+controller, 'not'\n      self.error_exit({ error: I18n.t('errors.access_not_allowed') }) if exit\n      return false\n    end\n\n    menu_access_status = menu.access\n    redis.set self.redis_prefix + self.current_user.uuid+'_'+controller, menu_access_status\n  else\n    if menu_access_status == 'not'\n      self.error_exit({ error: I18n.t('errors.access_not_allowed') }) if exit\n      return false\n    end\n  end\n  self.writer = true if menu_access_status == 'write'\n  return true\nend\n"