Skip to content

Instantly share code, notes, and snippets.

View dchandekstark's full-sized avatar

David Chandek-Stark dchandekstark

  • Duke University Libraries
  • Durham, North Carolina USA
View GitHub Profile
@dchandekstark
dchandekstark / base_decorator.rb
Created May 15, 2013 17:16
ActiveFedora decorators
ActiveFedora::Base.class_eval do
# method_missing is defined, so adding methods
def auditable?
begin
self.is_a? ActiveFedora::Auditable
rescue
false
end
@dchandekstark
dchandekstark / datastream.rb
Last active December 17, 2015 11:09
Extensions to Rubydora digital object and datastream APIs
ACTIVE = 'A'
INACTIVE = 'I'
DELETED = 'D'
def active?
dsState == ACTIVE
end
def inactive?
dsState == INACTIVE
@dchandekstark
dchandekstark / gist:6794732
Last active December 24, 2015 11:59
Proposal: Add backward-compatible API to Hydra rights metadata permissions using a SQL-like grant/revoke syntax

Grant

grant [permission], to: [grantees] -> result

Arguments

permission - Symbol (required) - one of [:discover|:read|:edit]

def get_objects_for_solr_field_values(solr_field, values, opts = {})
extra_solr_params = opts.delete(:extra_solr_params) || {}
documents = get_solr_response_for_field_values(solr_field, values, extra_solr_params)[1]
method = opts.delete(:lazy) ? :lazy_reify_solr_results : :reify_solr_results
ActiveFedora::SolrService.send(method, documents, opts)
end
class HasContentValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.has_content?
record.errors[attribute] << "The \"#{value.dsid}\" datastream does not have content"
end
end
end
@dchandekstark
dchandekstark / README.md
Last active August 29, 2015 14:00
Hydra Roles for Users and Groups

Hydra Roles for Users and Groups

Why

Hydra's current authorization model accounts for user- and group-based permissions (what I am calling groups are sometimes in Hydra called "roles", such as in the RoleMapper class or hydra-role-management). Authorization data is stored in the repository (as rightsMetadata or policy-based defaultRights) and provides a simple set of permissions ("discover", "read", and "edit") which are applied atomically at the object level. Adding other kinds of permissions (such as the ability to add child objects to a parent) or ones that don't depend on repository data (such as the ability to create new objects) involves custom coding using the current authorization library (CanCan, or CanCanCan in hydra-head 7).

It would seem beneficial to the Hydra community and/or individual adopters to explore the possibility of a common approach to extending Hydra's native authorization API.

What

@dchandekstark
dchandekstark / example.rb
Created April 19, 2014 01:57
ActiveFedora / ActiveRecord
class Foo < ActiveRecord::Base
belongs_to_af :bar
end
class Bar < ActiveFedora::Base
has_many_ar :foos
end
@dchandekstark
dchandekstark / Roles.md
Last active August 29, 2015 14:00
Role Metadata

Manager

CHUNK = 1024**2
def add_file(file, dsid, file_name)
return add_external_file(file, file_name) if dsid == 'content'
super
end
def add_external_file(file, original_filename)
external_file_path = generate_external_file_path
@dchandekstark
dchandekstark / dcterms.rdf
Last active August 29, 2015 14:01
RDF query
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfsns 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY dcns 'http://purl.org/dc/elements/1.1/'>
<!ENTITY dctermsns 'http://purl.org/dc/terms/'>
<!ENTITY dctypens 'http://purl.org/dc/dcmitype/'>
<!ENTITY dcamns 'http://purl.org/dc/dcam/'>
<!ENTITY skosns 'http://www.w3.org/2004/02/skos/core#'>
<!ENTITY owlns 'http://www.w3.org/2002/07/owl#'>