def siloview(self, silo): if not ag.granary.issilo(silo): abort(404) ident = request.environ.get('repoze.who.identity') c.ident = ident c.silo_name = silo c.editor = False if ag.metadata_embargoed: if not ident: abort(401, "Not Authorised") silos = ag.authz(ident) if silo not in silos: abort(403, "Forbidden") c.editor = True elif ident: silos = ag.authz(ident) if silo in silos: c.editor = True rdfsilo = ag.granary.get_rdf_silo(silo) state_info = ag.granary.describe_silo(silo) if 'title' in state_info and state_info['title']: c.title = state_info['title'] c.embargos = {} c.items = [] for item in rdfsilo.list_items(): c.embargos[item] = None try: c.embargos[item] = is_embargoed(rdfsilo, item) except: pass c.items.append(item) #c.embargos[item] = () # conneg return accept_list = None if 'HTTP_ACCEPT' in request.environ: try: accept_list = conneg_parse(request.environ['HTTP_ACCEPT']) except: accept_list= [MT("text", "html")] if not accept_list: accept_list= [MT("text", "html")] mimetype = accept_list.pop(0) while(mimetype): if str(mimetype).lower() in ["text/html", "text/xhtml"]: return render('/siloview.html') elif str(mimetype).lower() in ["text/plain", "application/json"]: response.content_type = 'application/json; charset="UTF-8"' response.status_int = 200 response.status = "200 OK" return simplejson.dumps(c.embargos) try: mimetype = accept_list.pop(0) except IndexError: mimetype = None #Whoops nothing satisfies - return text/html return render('/siloview.html')
def siloview(self, silo): """ Returns the state information of a silo. Only authorized users with role 'admin' or 'manager' can view this information The state information for a silo contains the following: Name of the silo (machine name, used in uris) - ans["silo"] Base URI for the silo - ans["uri_base"] Users who can access the silo (silo owners) - ans["owners"] Silo description - ans["description"] Title of the silo (human readable) - ans["title"] Disk allocation for the silo (in kB) - ans["disk_allocation"] List of datasets in the silo (ans["datasets"]) with embargo information for each of the datasets (ans["datasets"]["dataset_name"]["embargo_info"]) """ # Only authorized users can view state information. # Should this be restricted to admins and managers only, or shoud users too be able to see this information? # Going with restricting this information to admins and managers if not ag.granary.issilo(silo): abort(404) ident = request.environ.get('repoze.who.identity') if not ident: abort(401, "Not Authorised") silos = ag.authz(ident) if silo not in silos: abort(403, "Forbidden") silos_admin = ag.authz(ident, permission='administrator') silos_manager = ag.authz(ident, permission='manager') #if not ident.get('role') in ["admin", "manager"]: if not (silo in silos_admin or silo in silos_manager): abort(403, "Forbidden. You should be an administrator or manager to view this information") options = request.GET start = 0 if 'start' in options and options['start']: try: start = int(options['start']) except: start = 0 rows = 1000 if 'rows' in options and options['rows']: try: rows = int(options['rows']) except: rows = 1000 rdfsilo = ag.granary.get_rdf_silo(silo) state_info = ag.granary.describe_silo(silo) state_info['silo'] = silo state_info['uri_base'] = '' if rdfsilo.state and rdfsilo.state['uri_base']: state_info['uri_base'] = rdfsilo.state['uri_base'] state_info['number of data packages'] = get_datasets_count(silo) state_info['params'] = {'start':start, 'rows':rows} items = {} #for item in rdfsilo.list_items(): for item in get_datasets(silo, start=start, rows=rows): items[item] = {} try: items[item]['embargo_info'] = is_embargoed(rdfsilo, item) except: pass state_info['datasets'] = items # conneg return # Always return application/json response.content_type = 'application/json; charset="UTF-8"' response.status_int = 200 response.status = "200 OK" return simplejson.dumps(state_info)