예제 #1
0
def get_users(request):
    try:
        api_root_name = request.GET['api_root_name']
        api_root = ApiRoot.objects.get(name=api_root_name)
        return JsonResponse({'users': api_root.stip_meta['users'] if 'users' in api_root.stip_meta else []})
    except Exception as e:
        return error(request, str(e))
예제 #2
0
def create_modify(request):
    RESERVED_API_ROOT_NAMES = ['taxii', 'taxii2']
    try:
        data = json.loads(request.POST['data'])
        api_root_name = data['api_root_name']
        title = data['title']
        description = data['description']
        max_content_length = int(data['max_content_length'])
        action = data['action']
        collections = data['collections']
        users = data['users']
        if action == 'create':
            versions = DEFAULT_VERSIONS
        else:
            versions = None
        if api_root_name in RESERVED_API_ROOT_NAMES:
            raise Exception('%s is reserved.' % (api_root_name))
        api_root = ApiRoot.update_or_create(api_root_name, title, description, versions, max_content_length)
        api_root.set_collections(collections)
        api_root.set_users(users)
        if action == 'create':
            Discovery.append_api_root(api_root)
        return redirect('api_roots')
    except Exception as e:
        return error(request, str(e))
예제 #3
0
def collections(request):
    try:
        collections = Collection.objects
        communities = Communities.objects
        return render(request, 'collections.html', {
            'collections': collections,
            'communities': communities
        })
    except Exception as e:
        return error(request, str(e))
예제 #4
0
def get_collections(request):
    try:
        api_root_name = request.GET['api_root_name']
        api_root = ApiRoot.objects.get(name=api_root_name)
        collections = []
        for collection in api_root.collections:
            collections.append(collection.col_id)
        return JsonResponse({'collections': collections})
    except Exception as e:
        return error(request, str(e))
예제 #5
0
def top(request):
    try:
        discovery = Discovery.objects.limit(1)[0]
        return render(
            request,
            'discovery.html',
            {
                'discovery': discovery
            })
    except Exception as e:
        return error(request, str(e))
예제 #6
0
def modify(request):
    try:
        data = json.loads(request.POST['data'])
        title = data['title']
        description = data['description']
        contact = data['contact']
        default = data['default']
        Discovery.update_or_create(title, description, contact, default)
        return redirect('discovery')
    except Exception as e:
        return error(request, str(e))
예제 #7
0
def delete(request):
    try:
        data = json.loads(request.POST['data'])
        api_root_name = data['api_root_name']
        api_root = ApiRoot.objects.get(name=api_root_name)
        discovery = Discovery.objects.get()
        if api_root in discovery.api_roots:
            discovery.api_roots.remove(api_root)
            discovery.save()
        api_root.delete()
        return redirect('api_roots')
    except Exception as e:
        return error(request, str(e))
예제 #8
0
def api_roots(request):
    try:
        api_roots = ApiRoot.objects
        collections = Collection.objects
        users = STIPUser.objects.filter(is_active=True)
        return render(
            request,
            'api_roots.html',
            {
                'api_roots': api_roots,
                'collections': collections,
                'users': users,
            })
    except Exception as e:
        return error(request, str(e))
예제 #9
0
def delete(request):
    try:
        data = json.loads(request.POST['data'])
        col_id = data['col_id']
        col = Collection.objects.get(col_id=col_id)
        for api_root in ApiRoot.objects:
            if col in api_root.collections:
                api_root.collections.remove(col)
                api_root.save()
        col.delete()
        return redirect('collections')
    except me.DoesNotExist:
        print(col_id + ' does not exist.')
        return redirect('collections')
    except Exception as e:
        return error(request, str(e))
예제 #10
0
def get_access_authority(request):
    try:
        col_id = request.POST['col_id']
        col = Collection.objects.get(col_id=col_id)
        d = {}
        if 'can_read_communities' in col.stip_meta:
            d['can_read_communities'] = []
            for community in col.stip_meta['can_read_communities']:
                d['can_read_communities'].append(community.name)
        else:
            d['can_read_communities'] = None
        if 'can_write_community' in col.stip_meta:
            d['can_write_community'] = col.stip_meta[
                'can_write_community'].name
        else:
            d['can_write_community'] = None
        return JsonResponse(d)
    except Exception as e:
        return error(request, str(e))
예제 #11
0
def create_modify(request):
    try:
        data = json.loads(request.POST['data'])
        col_id = data['id']
        title = data['title']
        description = data['description']
        alias = data['alias']
        can_read = data['can_read']
        can_write = data['can_write']
        action = data['action']
        can_read_communities = None
        can_write_community = None

        if can_read:
            can_read_communities = []
            for name in data['can_read_communities']:
                can_read_communities.append(Communities.objects.get(name=name))

        if can_write:
            can_write_community = Communities.objects.get(
                name=data['can_write_community'])

        if action == 'create':
            media_types = DEFAULT_MEDIA_TYPES
        else:
            media_types = None

        Collection.update_or_create(
            col_id,
            title,
            description,
            alias,
            can_read,
            can_write,
            media_types,
            can_read_communities=can_read_communities,
            can_write_community=can_write_community,
        )
        return redirect('collections')
    except Exception as e:
        return error(request, str(e))
예제 #12
0
def generate_uuid(request):
    try:
        return JsonResponse({'uuid': str(uuid.uuid4())})
    except Exception as e:
        return error(request, str(e))