lib/seek/permissions/policy_based_authorization.rb
#updates or creates the authorization lookup entries for this item and the provided user (nil indicating anonymous user)
updates or creates the authorization lookup entries for this item and the provided user (nil indicating anonymous user)
updates or creates the authorization lookup entries for this item and the provided user ( nil indicating anonymous user )
def update_lookup_table user=nil
        self.class.isolation_level( :repeatable_read ) do 
          self.class.transaction do
            user_id = user.nil? ? 0 : user.id
            can_view = ActiveRecord::Base.connection.quote authorized_for_action(user,"view")
            can_edit = ActiveRecord::Base.connection.quote authorized_for_action(user,"edit")
            can_download = ActiveRecord::Base.connection.quote authorized_for_action(user,"download")
            can_manage = ActiveRecord::Base.connection.quote authorized_for_action(user,"manage")
            can_delete = ActiveRecord::Base.connection.quote authorized_for_action(user,"delete")
            lookup = self.class.lookup_for_asset("view",user_id,self.id)
            insert = lookup.nil?
            if insert
              sql = "insert into #{self.class.lookup_table_name} (user_id,asset_id,can_view,can_edit,can_download,can_manage,can_delete) values (#{user_id},#{id},#{can_view},#{can_edit},#{can_download},#{can_manage},#{can_delete});"
            else
              sql = "update #{self.class.lookup_table_name} set can_view=#{can_view}, can_edit=#{can_edit}, can_download=#{can_download},can_manage=#{can_manage},can_delete=#{can_delete} where user_id=#{user_id} and asset_id=#{id}"
            end
            ActiveRecord::Base.connection.execute(sql)
          end
        end
      end
def update_lookup_table user = nil self . class . isolation_level ( :repeatable_read ) do self . class . transaction do user_id = user . nil? ? 0 : user . id can_view = ActiveRecord :: Base . connection . quote authorized_for_action ( user , "view" ) can_edit = ActiveRecord :: Base . connection . quote authorized_for_action ( user , "edit" ) can_download = ActiveRecord :: Base . connection . quote authorized_for_action ( user , "download" ) can_manage = ActiveRecord :: Base . connection . quote authorized_for_action ( user , "manage" ) can_delete = ActiveRecord :: Base . connection . quote authorized_for_action ( user , "delete" ) lookup = self . class . lookup_for_asset ( "view" , user_id , self . id ) insert = lookup . nil? if insert sql = "insert into #{self.class.lookup_table_name} (user_id,asset_id,can_view,can_edit,can_download,can_manage,can_delete) values (#{user_id},#{id},#{can_view},#{can_edit},#{can_download},#{can_manage},#{can_delete});" else sql = "update #{self.class.lookup_table_name} set can_view=#{can_view}, can_edit=#{can_edit}, can_download=#{can_download},can_manage=#{can_manage},can_delete=#{can_delete} where user_id=#{user_id} and asset_id=#{id}" end ActiveRecord :: Base . connection . execute ( sql ) end end end
updates or creates the authorization lookup entries for this item and the provided user (nil indicating anonymous user)
updates or creates the authorization lookup entries for this item and the provided user ( nil indicating anonymous user )
#ensure it allows it see another worker may have inserted a record already #check to see if an insert of update is needed, action used is arbitary
user