lib/seek/permissions/policy_based_authorization.rb
#allows access to each permission in a single database call (rather than calling can_download? can_edit? etc individually)
allows access to each permission in a single database call (rather than calling can_download.
allows access to each permission in a single database call ( rather than calling can_download .
def authorization_permissions user=User.current_user
        @@expected_true_value ||= ActiveRecord::Base.connection.quoted_true.gsub("'","")
        permissions = AuthPermissions.new
        user_id = user.nil? ? 0 : user.id
        if Seek::Config.auth_lookup_enabled && self.class.lookup_table_consistent?(user_id)
          sql = "SELECT can_view,can_edit,can_download,can_manage,can_delete FROM #{self.class.lookup_table_name} WHERE user_id=#{user_id} AND asset_id=#{self.id}"
          res = ActiveRecord::Base.connection.select_one(sql)
          unless res.nil?
            permissions.can_view = res["can_view"].to_s==@@expected_true_value && state_allows_manage?(user)
            permissions.can_download = res["can_download"].to_s==@@expected_true_value && state_allows_manage?(user)
            permissions.can_edit = res["can_edit"].to_s==@@expected_true_value && state_allows_manage?(user)
            permissions.can_manage = res["can_manage"].to_s==@@expected_true_value && state_allows_manage?(user)
            permissions.can_delete = res["can_delete"].to_s==@@expected_true_value && state_allows_manage?(user)
          else
            raise "Expected to find record in auth lookup table"
          end
        else
          permissions.can_view = self.can_view?
          permissions.can_download = self.can_download?
          permissions.can_edit = self.can_edit?
          permissions.can_manage = self.can_manage?
          permissions.can_delete = self.can_delete?
      end
        permissions
      end
def authorization_permissions user = User . current_user @@expected_true_value ||= ActiveRecord :: Base . connection . quoted_true . gsub ( "'" , "" ) permissions = AuthPermissions . new user_id = user . nil? ? 0 : user . id if Seek :: Config . auth_lookup_enabled && self . class . lookup_table_consistent? ( user_id ) sql = "SELECT can_view,can_edit,can_download,can_manage,can_delete FROM #{self.class.lookup_table_name} WHERE user_id=#{user_id} AND asset_id=#{self.id}" res = ActiveRecord :: Base . connection . select_one ( sql ) unless res . nil? permissions . can_view = res [ "can_view" ] . to_s == @@expected_true_value && state_allows_manage? ( user ) permissions . can_download = res [ "can_download" ] . to_s == @@expected_true_value && state_allows_manage? ( user ) permissions . can_edit = res [ "can_edit" ] . to_s == @@expected_true_value && state_allows_manage? ( user ) permissions . can_manage = res [ "can_manage" ] . to_s == @@expected_true_value && state_allows_manage? ( user ) permissions . can_delete = res [ "can_delete" ] . to_s == @@expected_true_value && state_allows_manage? ( user ) else raise "Expected to find record in auth lookup table" end else permissions . can_view = self . can_view? permissions . can_download = self . can_download? permissions . can_edit = self . can_edit? permissions . can_manage = self . can_manage? permissions . can_delete = self . can_delete? end permissions end
allows access to each permission in a single database call (rather than calling can_download?
allows access to each permission in a single database call ( rather than calling can_download?
user
current_user