Beispiel #1
0
def rename_ingestion(request, ing_id):
    """
    Rename ingestion (regarding permissions)
    """
    # FIXME: make a post query, not passing ing_id as parameter!
    name = request.POST.get('value', None)
    if not name:
        # Fails silently
        return HttpResponse(str(ing.name), mimetype = 'text/plain')
    try:
        ing = Ingestion.objects.get(id = ing_id)
    except:
        return HttpResponse(json.encode({'error': "This ingestion has not been found"}), mimetype = 'text/plain')

    perms = get_entity_permissions(request, target = 'ingestion', key = int(ing.id))
    if not perms['currentUser']['write']:
        return HttpResponse(json.encode({'error': "You don't have permission to delete this ingestion"}), mimetype = 'text/plain')

    orig = ing.label
    try:
        ing.label = name
        ing.save()
    except IntegrityError:
        # Name not available
        return HttpResponse(json.encode({'old': orig, 'error': "An ingestion named <b>%s</b> already exists.<br/>Cannot rename ingestion." % name}), mimetype = 'text/plain')

    return HttpResponse(str(name), mimetype = 'text/plain')
Beispiel #2
0
    def getSavedItems(self, request):
        """
        Returns a user's saved items. 
        """
        from terapix.youpi.views import get_entity_permissions
        # Full cart items count to be stored in the cache
        full_count = CartItem.objects.filter(kind__name__exact = self.id).count()
        saved = cache.get(self.id + '_saved_items')
        if saved:
            if cache.get(self.id + '_saved_items_num') == full_count:
                return saved

        # per-user items
        items, filtered = read_proxy(request, CartItem.objects.filter(kind__name__exact = self.id).order_by('-date'))
        res = []
        for it in items:
            data = marshal.loads(base64.decodestring(str(it.data)))
            res.append({'date'              : "%s %s" % (it.date.date(), it.date.time()), 
                        'username'          : str(it.user.username),
                        'idList'            : str(data['idList']), 
                        'resultsOutputDir'  : str(self.getUserResultsOutputDir(request, data['resultsOutputDir'], it.user.username)),
                        'aheadPath'         : str(data['aheadPath']),
                        'name'              : str(it.name),
                        'taskId'            : str(data['taskId']), 
                        'itemId'            : str(it.id), 
                        'perms'             : json.encode(get_entity_permissions(request, 'cartitem', it.id)),
                        'config'            : str(data['config'])})

        cache.set(self.id + '_saved_items_num', full_count)
        cache.set(self.id + '_saved_items', res)
        return res
Beispiel #3
0
    def getSavedItems(self, request):
        """
        Returns a user's saved items for this plugin 
        """
        from terapix.youpi.views import get_entity_permissions

        # Full cart items count to be stored in the cache
        full_count = CartItem.objects.filter(kind__name__exact=self.id).count()
        saved = cache.get(self.id + "_saved_items")
        if saved:
            if cache.get(self.id + "_saved_items_num") == full_count:
                return saved

        items, filtered = read_proxy(request, CartItem.objects.filter(kind__name__exact=self.id).order_by("-date"))
        res = []
        for it in items:
            data = marshal.loads(base64.decodestring(str(it.data)))
            res.append(
                {
                    "date": "%s %s" % (it.date.date(), it.date.time()),
                    "username": str(it.user.username),
                    "descr": str(data["Descr"]),
                    "itemId": str(it.id),
                    "resultsOutputDir": str(self.getUserResultsOutputDir(request)),
                    "perms": json.encode(get_entity_permissions(request, "cartitem", it.id)),
                    "name": str(it.name),
                }
            )

        cache.set(self.id + "_saved_items_num", full_count)
        cache.set(self.id + "_saved_items", res)
        return res
Beispiel #4
0
    def getSavedItems(self, request):
        """
        Returns a user's saved items for this plugin 
        """
        from terapix.youpi.views import get_entity_permissions
        # Full cart items count to be stored in the cache
        full_count = CartItem.objects.filter(kind__name__exact = self.id).count()
        saved = cache.get(self.id + '_saved_items')
        if saved:
            if cache.get(self.id + '_saved_items_num') == full_count:
                return saved

        # per-user items
        items, filtered = read_proxy(request, CartItem.objects.filter(kind__name__exact = self.id).order_by('-date'))
        res = []
        for it in items:
            data = marshal.loads(base64.decodestring(str(it.data)))
            # Set default values for items without this information
            if not data.has_key('headPath'):
                data['headPath'] = 'AUTO'
            if not data.has_key('useAutoScampHeads'):
                data['useAutoScampHeads'] = 1
            if not data.has_key('useAutoQFITSWeights'):
                data['useAutoQFITSWeights'] = 1
            res.append({'date'              : "%s %s" % (it.date.date(), it.date.time()), 
                        'username'          : str(it.user.username),
                        'idList'            : str(data['idList']), 
                        'taskId'            : str(data['taskId']), 
                        'itemId'            : str(it.id), 
                        'weightPath'        : str(data['weightPath']), 
                        'headPath'          : str(data['headPath']), 
                        'resultsOutputDir'  : str(self.getUserResultsOutputDir(request, data['resultsOutputDir'], it.user.username)),
                        'useAutoQFITSWeights'   : str(data['useAutoQFITSWeights']),
                        'useAutoScampHeads'     : str(data['useAutoScampHeads']),
                        'name'              : str(it.name),
                        'headDataPaths'     : string.join([str(p) for p in data['headDataPaths']], ','),
                        'perms'             : json.encode(get_entity_permissions(request, 'cartitem', it.id)),
                        'config'            : str(data['config'])})

        cache.set(self.id + '_saved_items_num', full_count)
        cache.set(self.id + '_saved_items', res)
        return res
Beispiel #5
0
def delete_ingestion(request, ing_id):
    """
    Delete ingestion (regarding permissions)
    """
    # FIXME: make a post query, not passing ing_id as parameter!
    try:
        ing = Ingestion.objects.get(id = ing_id)
    except:
        return HttpResponse(json.encode({'error': "This ingestion has not been found"}), mimetype = 'text/plain')

    perms = get_entity_permissions(request, target = 'ingestion', key = int(ing.id))
    if not perms['currentUser']['write']:
        return HttpResponse(json.encode({'error': "You don't have permission to delete this ingestion"}), mimetype = 'text/plain')

    imgs = Image.objects.filter(ingestion = ing)
    rels = Rel_it.objects.filter(image__in = imgs)
    if rels:
        # Processed images, do not delete this ingestion
        return HttpResponse(json.encode({'error': "Some of those ingested images have been processed.<br/>This ingestion can't be deleted."}), mimetype = 'text/plain')
    else:
        # Images have never been processed, the ingestion can safely be deleted
        ing.delete()    
    return HttpResponse(json.encode({'success': True}), mimetype = 'text/plain')
Beispiel #6
0
        # in order to get a valid JSON object.
        # Each header[j] is a list of (display value, type[, value2]).
        # type allows client-side code to known how to display the value.
        #
        data.append({   
            header[0]: [str(pretty.date(ing.start_ingestion_date)) + ' (' + str(ing.start_ingestion_date) + ')', 'str'],
            header[1]: [str(ing.end_ingestion_date-ing.start_ingestion_date), 'str'],
            header[2]: [str(ing.label), 'str'],
            header[3]: [str(ing.user.username), 'str'],
            header[4]: [ing.check_fitsverify, 'check'],
            header[5]: [ing.is_validated, 'check'],
            header[6]: [ing.check_multiple_ingestion, 'check'],
            header[7]: [ing.exit_code, 'exit'],
            header[8]: ['View log', 'link', str(settings.AUP + "/history/ingestion/report/%d/" % ing.id)],
            # Give user permissions for this ingestion
            'perms': json.encode(get_entity_permissions(request, target = 'ingestion', key = int(ing.id))),
            'id': int(ing.id),
            'imgcount': int(Image.objects.filter(ingestion = ing).count()),
        })

    # Be aware that JS code WILL search for data and header keys
    out = {'data': data, 'header': header}

    # Return a JSON object
    return HttpResponse(str(out), mimetype = 'text/plain')

@login_required
@profile
def show_ingestion_report(request, ingestionId):
    try: ing = Ingestion.objects.filter(id = ingestionId)[0]
    except:
Beispiel #7
0
@login_required
@profile
def get_permissions(request):
	"""
	Returns permissions for a given entity. See get_entry_permissions().
	"""
	post = request.POST
	try:
		# Target entity
		target = post['Target']
		# Unique key to identify an element in table
		key = post['Key']
	except Exception, e:
		raise PluginError, "POST argument error. Unable to process data."
	return HttpResponse(json.encode(get_entity_permissions(request, target, key)), mimetype = 'text/plain')

@login_required
@profile
def set_permissions(request):
	"""
	Sets permissions for a given entity.
	The return value is a JSON object like:
	Perms is a string like: 1,1,1,0,0,0 specifying read/write bits for user/group/others respectively
	"""

	post = request.POST
	try:
		# Target entity
		target = post['Target']
		# Unique key to identify an element in table