Class: Group
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Group
- Defined in:
- app/models/group.rb
Overview
Security Group
Class Method Summary collapse
Instance Method Summary collapse
-
#add_party(a_party) ⇒ Object
add party to group group lives on TO side of relationship.
- #add_role(role) ⇒ Object
-
#add_user(user) ⇒ Object
add user to group.
- #all_class_capabilities ⇒ Object
- #all_uniq_class_capabilities ⇒ Object
- #class_capabilities_to_hash ⇒ Object
- #create_party ⇒ Object
- #destroy_party ⇒ Object
- #destroy_party_relationships ⇒ Object
- #get_relationship(a_party) ⇒ Object
- #has_role?(role) ⇒ Boolean
- #members ⇒ Object
-
#party_relationships ⇒ Object
group lives on TO side of relationship.
- #remove_all_roles ⇒ Object
-
#remove_party(a_party) ⇒ Object
remove party from group group lives on TO side of relationship.
- #remove_role(role) ⇒ Object
-
#remove_user(user) ⇒ Object
remove user from group.
- #role_class_capabilities ⇒ Object
-
#roles ⇒ Object
roles this group has.
-
#roles_not ⇒ Object
roles this group does NOT have.
- #save_party ⇒ Object
- #to_data_hash ⇒ Object
-
#users ⇒ Object
get users in this group.
-
#users_not ⇒ Object
get users not in this group.
Class Method Details
.add(description) ⇒ Object
21 22 23 |
# File 'app/models/group.rb', line 21 def self.add(description) Group.create(:description => description) end |
Instance Method Details
#add_party(a_party) ⇒ Object
add party to group group lives on TO side of relationship
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/models/group.rb', line 112 def add_party(a_party) # check and see if party is already a member of this group rel = get_relationship(a_party).first unless rel.nil? # if so, return relationship return rel else # if not then build party_relationship rt = RelationshipType.find_by_internal_identifier('group_membership') pr = PartyRelationship.new pr.description = rt.description pr.relationship_type = rt pr.from_role = RoleType.find_by_internal_identifier('group_member') pr.to_role = RoleType.find_by_internal_identifier('group') pr.from_party = a_party pr.to_party = self.party pr.save return pr end end |
#add_role(role) ⇒ Object
40 41 42 |
# File 'app/models/group.rb', line 40 def add_role(role) party.add_role(role) end |
#add_user(user) ⇒ Object
add user to group
96 97 98 |
# File 'app/models/group.rb', line 96 def add_user(user) add_party(user.party) end |
#all_class_capabilities ⇒ Object
152 153 154 155 156 157 158 159 160 |
# File 'app/models/group.rb', line 152 def all_class_capabilities scope_type = ScopeType.find_by_internal_identifier('class') Capability.includes(:capability_type).joins(:capability_type).joins(:capability_accessors). where("(capability_accessors.capability_accessor_record_type = 'Group' AND capability_accessor_record_id = (#{self.id})) OR (capability_accessors.capability_accessor_record_type = 'SecurityRole' AND capability_accessor_record_id IN (#{roles.select('security_roles.id').to_sql}))"). where(:scope_type_id => scope_type.id) end |
#all_uniq_class_capabilities ⇒ Object
162 163 164 |
# File 'app/models/group.rb', line 162 def all_uniq_class_capabilities all_class_capabilities.all.uniq end |
#class_capabilities_to_hash ⇒ Object
166 167 168 169 170 171 172 |
# File 'app/models/group.rb', line 166 def class_capabilities_to_hash all_uniq_class_capabilities.map {|capability| { :capability_type_iid => capability.capability_type.description, :capability_resource_type => capability.capability_resource_type } }.compact end |
#create_party ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'app/models/group.rb', line 52 def create_party pty = Party.new pty.description = self.description pty.business_party = self pty.save self.save end |
#destroy_party ⇒ Object
66 67 68 69 70 |
# File 'app/models/group.rb', line 66 def destroy_party if self.party self.party.destroy end end |
#destroy_party_relationships ⇒ Object
72 73 74 |
# File 'app/models/group.rb', line 72 def destroy_party_relationships party_relationships.destroy_all end |
#get_relationship(a_party) ⇒ Object
105 106 107 108 |
# File 'app/models/group.rb', line 105 def get_relationship(a_party) role_type = RoleType.find_by_internal_identifier('group') PartyRelationship.where(:party_id_to => self.party.id, :party_id_from => a_party.id, :role_type_id_to => role_type.id) end |
#has_role?(role) ⇒ Boolean
35 36 37 38 |
# File 'app/models/group.rb', line 35 def has_role?(role) role = role.is_a?(SecurityRole) ? role : SecurityRole.find_by_internal_identifier(role.to_s) roles.include?(role) end |
#members ⇒ Object
81 82 83 |
# File 'app/models/group.rb', line 81 def members Party.joins("JOIN #{group_member_join}") end |
#party_relationships ⇒ Object
group lives on TO side of relationship
77 78 79 |
# File 'app/models/group.rb', line 77 def party_relationships PartyRelationship.where(:party_id_to => self.party.id) end |
#remove_all_roles ⇒ Object
48 49 50 |
# File 'app/models/group.rb', line 48 def remove_all_roles party.remove_all_roles end |
#remove_party(a_party) ⇒ Object
remove party from group group lives on TO side of relationship
135 136 137 138 139 140 141 142 |
# File 'app/models/group.rb', line 135 def remove_party(a_party) begin get_relationship(a_party).first.destroy rescue => e Rails.logger.error e. return nil end end |
#remove_role(role) ⇒ Object
44 45 46 |
# File 'app/models/group.rb', line 44 def remove_role(role) party.remove_role(role) end |
#remove_user(user) ⇒ Object
remove user from group
101 102 103 |
# File 'app/models/group.rb', line 101 def remove_user(user) remove_party(user.party) end |
#role_class_capabilities ⇒ Object
144 145 146 147 148 149 150 |
# File 'app/models/group.rb', line 144 def role_class_capabilities scope_type = ScopeType.find_by_internal_identifier('class') Capability.includes(:capability_type).joins(:capability_type).joins(:capability_accessors). where(:capability_accessors => { :capability_accessor_record_type => "SecurityRole" }). where("capability_accessor_record_id IN (#{roles.select('security_roles.id').to_sql})"). where(:scope_type_id => scope_type.id) end |
#roles ⇒ Object
roles this group has
31 32 33 |
# File 'app/models/group.rb', line 31 def roles party.security_roles end |
#roles_not ⇒ Object
roles this group does NOT have
26 27 28 |
# File 'app/models/group.rb', line 26 def roles_not party.roles_not end |
#save_party ⇒ Object
61 62 63 64 |
# File 'app/models/group.rb', line 61 def save_party self.party.description = self.description self.party.save end |
#to_data_hash ⇒ Object
174 175 176 |
# File 'app/models/group.rb', line 174 def to_data_hash self.to_hash(only: [:id, :description, :created_at, :updated_at]) end |
#users ⇒ Object
get users in this group
86 87 88 |
# File 'app/models/group.rb', line 86 def users User.joins(:party).joins("JOIN #{group_member_join}") end |
#users_not ⇒ Object
get users not in this group
91 92 93 |
# File 'app/models/group.rb', line 91 def users_not User.joins(:party).joins("LEFT JOIN #{group_member_join}").where("party_relationships.id IS NULL") end |