Class: RbacRls::GroupPermission

Inherits:
ApplicationRecord show all
Includes:
ManageRlsMigrationConcern
Defined in:
app/models/rbac_rls/group_permission.rb

Instance Method Summary collapse

Methods included from ManageRlsMigrationConcern

#delete_file, #delete_nested_policy, #down_migrate, #get_migration_file_path

Instance Method Details

#create_group_rls_policyObject

rails generate rbac_rls:group_permission table_name description:table_key ‘produto’:table_value



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/rbac_rls/group_permission.rb', line 11

def create_group_rls_policy
  if permission.table_name.present? and table_key.present? and table_value.present?
    cmd = -> { "rails generate rbac_rls:group_permission #{permission.table_name} '#{table_key}':table_key '#{table_value}':table_value" }
    migraion_generated = false
    migraion_generated = system(cmd.===) if new_record?
    migraion_generated = system(cmd.===) if persisted? and database_changed? and drop_policy()
    if migraion_generated
      system(RbacRls::Settings.run_migrate_command)
      self.migration_version = ActiveRecord::Migrator.current_version
    end
  end
end

#database_changed?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'app/models/rbac_rls/group_permission.rb', line 34

def database_changed?
  attrs_in_database = self.class.find(id).attributes
  attributes != attrs_in_database
end

#drop_policyObject



24
25
26
27
28
29
30
31
32
# File 'app/models/rbac_rls/group_permission.rb', line 24

def drop_policy()
  r_value = false
  r_value = true if migration_version.nil?
  if persisted? && delete_nested_policy()
    self.migration_version = nil
    r_value = true
  end
  r_value
end