Exemple #1
0
def handleDoiUpdate(currentPackage, newPackage):
    oldDoi = getDoiStatus(currentPackage)
    newDoi = getDoiStatus(newPackage)

    # No changes
    if oldDoi.get('status').get('value') == newDoi.get('status').get('value') and oldDoi.get('status').get('error') != True:
        if oldDoi.get('value') == newDoi.get('value'):
            # check this package doesn't have a DOI
            # Perhaps just not let them make it private?
            # if not canUpdate(oldDoi):
            #     return {
            #         'error': True,
            #         'message' : 'You cannot update a package once the DOI as been applied'
            #     }
            # else:
            return {'success': True}

    # the one thing a USER can do is request approval
    if oldDoi.get('status').get('value') in (None, DOI_STATUS['PENDING_REVISION']):
        if newDoi.get('status').get('value') == DOI_STATUS['PENDING_APPROVAL'] and newDoi.get('value') is None:
            # set the requesting user
            status = {
                'value' : DOI_STATUS['PENDING_APPROVAL'],
                'requested_by' : c.user
            }
            setPackageExtra('EcoSIS DOI Status', json.dumps(status), newPackage)

            # alert the admins of the request
            sendAdminNotification(newPackage)

            return {'success': True}

        # user is canceling request
        if newDoi.get('status').get('value') is None:
            setPackageExtra('EcoSIS DOI Status', '{}', newPackage)

            return {'success': True}


    if not isAdmin():
        return {
            'error' : True,
            'message' : 'You do not have access to update DOI values'
        }

    resp = {}
    if newDoi.get('status').get('value') == DOI_STATUS['PENDING_REVISION'] and oldDoi.get('status').get('value') != DOI_STATUS['PENDING_REVISION']:
        resp = sendUserNotification(newPackage, False)
    elif newDoi.get('status').get('value') == DOI_STATUS['ACCEPTED'] and oldDoi.get('status').get('value') != DOI_STATUS['ACCEPTED']:
        resp = sendUserNotification(newPackage, True)

    resp['success'] = True
    return resp
Exemple #2
0
def doiQuery():
    response.headers["Content-Type"] = "application/json"

    if not isAdmin():
        return {
            'error' : True,
            'message' : 'Nope.'
        }

    query = request.params.get('query')
    status = request.params.get('status')
    offset = request.params.get('offset')
    limit = request.params.get('limit')

    resp = package.doiQuery(query=query, status=status, offset=offset, limit=limit)
    return json.dumps(resp)
Exemple #3
0
def info():
    response.headers["Content-Type"] = "application/json"
    if len(c.user) == 0:
        return json.dumps({"loggedIn": False})

    context = {'model': model, 'user': c.user}

    # see line 604 of ckan/logic/action/get about params for this method
    orgs = logic.get_action('organization_list_for_user')(context,{"permission": "create_dataset"})

    user = {
        "loggedIn": True,
        "username": c.user,
        "organizations" : orgs
    }

    if isAdmin():
        user['isAdmin'] = True

    return json.dumps(user)
Exemple #4
0
def clearDoi():
    response.headers["Content-Type"] = "application/json"

    if not isAdmin():
        return {
            'error' : True,
            'message' : 'Nope.'
        }

    id = request.params.get('id')

    context = {'model': model, 'user': c.user}
    pkg = logic.get_action('package_show')(context, {'id': id})

    # check EcoSIS DOI status
    setPackageExtra('EcoSIS DOI Status', '{}', pkg)
    setPackageExtra('EcoSIS DOI', '', pkg)

    pkg = logic.get_action('package_update')(context, pkg)

    return json.dumps({'success': True})