def clean(self): import util2 self.type = self.prefix.split(":")[0].upper() self.name = self.name.strip() if self.isDoi: if self.crossrefEnabled: if self.datacenter != None: raise django.core.exceptions.ValidationError({ "datacenter": "Non-DataCite DOI shoulder has datacenter." }) else: if self.datacenter == None: raise django.core.exceptions.ValidationError( {"datacenter": "Missing datacenter."}) else: if self.datacenter != None: raise django.core.exceptions.ValidationError( {"datacenter": "Non-DOI shoulder has datacenter."}) if self.crossrefEnabled: raise django.core.exceptions.ValidationError({ "crossrefEnabled": "Only DOI shoulders may be Crossref enabled." }) self.isTest = util2.isTestIdentifier(self.prefix)
def cleanAgentPid(self): # Checks applicable to agent PIDs only. import config import util2 if not self.isArk: raise django.core.exceptions.ValidationError( {"identifier": "Agent PID is not an ARK."}) if self.owner == None or self.owner.username != config.get( "auth.admin_username"): raise django.core.exceptions.ValidationError( {"owner": "Agent PID is not owned by the EZID administrator."}) if not self.isPublic: raise django.core.exceptions.ValidationError( {"status": "Agent PID is not public."}) if self.exported: raise django.core.exceptions.ValidationError( {"exported": "Agent PID is exported."}) if self.target != self.defaultTarget: raise django.core.exceptions.ValidationError( {"target": "Agent PID has non-default target URL."}) # N.B.: the isTest field hasn't been computed yet. if util2.isTestIdentifier(self.identifier): raise django.core.exceptions.ValidationError( {"identifier": "Agent PID is a test identifier."})
def authorizeCreate(user, prefix): """ Returns True if a request to mint or create an identifier is authorized. 'user' is the requestor and should be an authenticated StoreUser object. 'prefix' may be a complete identifier or just an identifier prefix corresponding to a shoulder; in either case it must be qualified, e.g., "doi:10.5060/". """ if util2.isTestIdentifier(prefix): return True if any(map(lambda s: prefix.startswith(s.prefix), user.shoulders.all())): return True if any(authorizeCreate(u, prefix) for u in user.proxy_for.all()): return True # Note what's missing here: group and realm administrators get no # extra identifier creation privileges. if user.isSuperuser: return True return False
def computeComputedValues(self): import util2 self.isTest = util2.isTestIdentifier(self.identifier)