Class: LesliVault::RoleService
- Inherits:
-
Lesli::ApplicationLesliService
- Object
- Lesli::ApplicationLesliService
- LesliVault::RoleService
- Defined in:
- app/services/lesli_vault/role_service.rb
Instance Method Summary collapse
- #create(params) ⇒ Object
- #destroy ⇒ Object
- #find(id) ⇒ Object
-
#index ⇒ Array
Paginated index of users.
- #options ⇒ Object
- #show ⇒ Object
- #update(params) ⇒ Object
Instance Method Details
#create(params) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/services/lesli_vault/role_service.rb', line 83 def create params role = current_user.account.roles.new(params) unless current_user.can_work_with_role?(role) self.error(I18n.t("core.roles.messages_danger_creating_role_object_level_permission_too_high")) end # check if user can work with that object level permission if role..to_f >= current_user.roles.map(&:object_level_permission).max() self.error(I18n.t("core.roles.messages_danger_creating_role_object_level_permission_too_high")) end # do not create if errors found return self unless self.successful? # Try to save role and logs if it went OK if role.save self.resource = role #Role::Activity.log_create(current_user, self.resource) else self.error(role.errors..to_sentence) end self end |
#destroy ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/services/lesli_vault/role_service.rb', line 133 def destroy unless self.resource.destroy self.error(self.resource.errors..to_sentence) end if self.successful? LesliVault::Role::Activity.log_destroy(current_user, self.resource) end self end |
#find(id) ⇒ Object
148 149 150 151 |
# File 'app/services/lesli_vault/role_service.rb', line 148 def find id #self.resource = current_user.account.roles.find_by_id(id) #self end |
#index ⇒ Array
Returns Paginated index of users.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/services/lesli_vault/role_service.rb', line 40 def index current_user.account.roles.where.not( :name => ["owner"] ).joins(" left join ( select count(1) users, role_id from lesli_user_powers inner join lesli_users as u on u.id = lesli_user_powers.user_id and u.deleted_at is null where lesli_user_powers.deleted_at is null group by (role_id) ) users on users.role_id = lesli_roles.id ").where("lesli_roles.object_level_permission <= ?", current_user.) .select( :id, :name, :active, :isolated, :description, :path_default, :object_level_permission, "users.users" ) .page(query[:pagination][:page]) .per(query[:pagination][:perPage]) .order(object_level_permission: :desc, name: :asc) end |
#options ⇒ Object
153 154 155 156 157 |
# File 'app/services/lesli_vault/role_service.rb', line 153 def { :object_level_permissions => self. } end |
#show ⇒ Object
75 76 77 |
# File 'app/services/lesli_vault/role_service.rb', line 75 def show self.resource end |
#update(params) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/services/lesli_vault/role_service.rb', line 114 def update params old_attributes = self.resource.attributes unless self.resource.update(params) self.error(self.resource.errors..to_sentence) end if self.successful? new_attributes = self.resource.attributes LesliVault::Role::Activity.log_update(current_user, role, old_attributes, new_attributes) end self end |