Class: ChefFixie::Sql::Org

Inherits:
SqlObject show all
Includes:
AuthzObjectMixin
Defined in:
lib/chef_fixie/sql_objects.rb

Constant Summary collapse

NAME_FIXUP =

Iterators for objects in authz; using containers to enumerate things It might be better to metaprogram this up instead,

TODO Write some tests to validate that this stuff works, since it depends on a lot of name magic…

{ "data" => "data_bags", "sandboxes" => nil }

Constants included from AuthzUtils

AuthzUtils::ACTIONS, AuthzUtils::TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AuthzObjectMixin

#ace, #ace_add, #ace_add_raw, #ace_delete, #ace_delete_raw, #ace_get_util, #ace_member?, #ace_raw, #acl, #acl_add_from_object, #acl_raw, #authz_api, #authz_delete, #expand_actions, included, #is_authorized, #prefix, #type

Methods included from AuthzUtils

#check_action, #check_actor_or_group, #get_authz_id, #get_type, #resourcify_actor_or_group, #to_resource

Methods inherited from SqlObject

#data, #delete, name_field, ro_access, std_authz, std_timestamp, #table

Constructor Details

#initialize(data) ⇒ Org

Returns a new instance of Org.



144
145
146
# File 'lib/chef_fixie/sql_objects.rb', line 144

def initialize(data)
  super(data)
end

Class Method Details

.scoped_type(*args) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/chef_fixie/sql_objects.rb', line 135

def self.scoped_type(*args)
  args.each do |object|
    funname = Relationships.plural(object)
    # defer evaluation of mapper to make sure we have a chance for everyone to initialize
    fundef = "def #{funname}; Relationships.table_class(:#{object}).new.by_org_id(org_id); end"
    class_eval(fundef)
  end
end

Instance Method Details

#each_authz_objectObject



189
190
191
192
193
194
195
196
# File 'lib/chef_fixie/sql_objects.rb', line 189

def each_authz_object
  each_authz_object_by_class do |objectlist|
    objectlist.each do |object|
      yield object
    end
  end
  nil
end

#each_authz_object_by_classObject



178
179
180
181
182
183
184
185
186
187
# File 'lib/chef_fixie/sql_objects.rb', line 178

def each_authz_object_by_class
  containers = self.containers.all(:all)
  containers.each do |container|
    objects = objects_by_container_type(container.name)
    if block_given?
      yield objects
    end
  end
  nil
end

#global_adminsObject Also known as: read_access_group



152
153
154
155
156
157
158
# File 'lib/chef_fixie/sql_objects.rb', line 152

def global_admins
  name = self.name
  global_admins_name = "#{name}_global_admins"
  read_access_name = "#{name}_read_access_group"
  ChefFixie::Sql::Groups.new[global_admins_name] || \
    ChefFixie::Sql::Groups.new[read_access_name]
end

#objects_by_container_type(container) ⇒ Object



169
170
171
172
173
174
175
176
# File 'lib/chef_fixie/sql_objects.rb', line 169

def objects_by_container_type(container)
  name = NAME_FIXUP.has_key?(container) ? NAME_FIXUP[container] : container
  return [] if name.nil?

  object_type = name.to_sym
  #        raise Exception "No such object_type #{object_type}" unless respond_to?(object_type)
  send(object_type).all(:all)
end

#org_idObject



148
149
150
# File 'lib/chef_fixie/sql_objects.rb', line 148

def org_id
  data[:id]
end