-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #471 from Xpirix/hub_api
Resource Hub api
- Loading branch information
Showing
18 changed files
with
1,648 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
API URL Configuration | ||
# QGIS Resources Hub API Documentation | ||
|
||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
[https://docs.djangoproject.com/en/3.2/topics/http/urls/](https://docs.djangoproject.com/en/3.2/topics/http/urls/) | ||
|
||
## Endpoints | ||
|
||
### Resources | ||
- **URL:** `/resources/` | ||
- **Method:** `GET` | ||
- **View:** `ResourceAPIList.as_view()` | ||
- **Name:** `resource-list` | ||
- **Description:** Retrieves a list of all resources. | ||
|
||
### Resource by UUID | ||
- **URL:** `/resource/<uuid:uuid>/` | ||
- **Method:** `GET` | ||
- **View:** `ResourceAPIDownload.as_view()` | ||
- **Name:** `resource-download` | ||
- **Description:** Downloads a specific resource identified by UUID. | ||
|
||
### Create Resource | ||
- **URL:** `/resource/create` | ||
- **Method:** `POST` | ||
- **View:** `ResourceCreateView.as_view()` | ||
- **Name:** `resource-create` | ||
- **Description:** Creates a new resource. | ||
- **Request example with cURL:** | ||
```sh | ||
curl --location 'http://localhost:62202/api/v1/resource/create' \ | ||
--header 'Authorization: Bearer <my_token>' \ | ||
--form 'file=@"path/to/the/file.zip"' \ | ||
--form 'thumbnail_full=@"path/to/the/thumbnail.png"' \ | ||
--form 'name="My model"' \ | ||
--form 'description="Little description"' \ | ||
--form 'tags="notag"' \ | ||
--form 'resource_type="model"' | ||
``` | ||
|
||
### Resource Detail | ||
- **URL:** `/resource/<str:resource_type>/<uuid:uuid>/` | ||
- **Methods:** `GET`, `PUT`, `DELETE` | ||
- **View:** `ResourceDetailView.as_view()` | ||
- **Name:** `resource-detail` | ||
- **Description:** Handles the detailed display, update, and deletion of a specific resource based on its type and UUID. | ||
- **Example:** | ||
To access the details of a resource with type 'style' and UUID '123e4567-e89b-12d3-a456-426614174000': | ||
```sh | ||
GET /resource/style/123e4567-e89b-12d3-a456-426614174000/ | ||
``` | ||
- **Permissions:** Ensure that the user has the necessary permissions (staff or creator) to view, update, or delete the resource details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.forms import CharField, ModelForm | ||
from api.models import UserOutstandingToken | ||
|
||
|
||
class UserTokenForm(ModelForm): | ||
""" | ||
Form for token description editing | ||
""" | ||
|
||
class Meta: | ||
model = UserOutstandingToken | ||
fields = ( | ||
"description", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.2.16 on 2024-11-18 03:02 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('token_blacklist', '0012_alter_outstandingtoken_user'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserOutstandingToken', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('is_blacklisted', models.BooleanField(default=False)), | ||
('is_newly_created', models.BooleanField(default=False)), | ||
('description', models.CharField(blank=True, help_text="Describe this token so that it's easier to remember where you're using it.", max_length=512, null=True, verbose_name='Description')), | ||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')), | ||
('last_used_at', models.DateTimeField(blank=True, null=True, verbose_name='Last used at')), | ||
('token', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='token_blacklist.outstandingtoken')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
# Create your models here. | ||
from base.models.processing_models import Resource | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
from rest_framework_simplejwt.token_blacklist.models import OutstandingToken | ||
from django.contrib.auth.models import User | ||
|
||
class UserOutstandingToken(models.Model): | ||
""" | ||
Hub outstanding token | ||
""" | ||
user = models.ForeignKey( | ||
User, | ||
on_delete=models.CASCADE | ||
) | ||
token = models.ForeignKey( | ||
OutstandingToken, | ||
on_delete=models.CASCADE | ||
) | ||
is_blacklisted = models.BooleanField(default=False) | ||
is_newly_created = models.BooleanField(default=False) | ||
description = models.CharField( | ||
verbose_name=_("Description"), | ||
help_text=_("Describe this token so that it's easier to remember where you're using it."), | ||
max_length=512, | ||
blank=True, | ||
null=True, | ||
) | ||
created_at = models.DateTimeField( | ||
verbose_name=_("Created at"), | ||
auto_now_add=True, | ||
) | ||
last_used_at = models.DateTimeField( | ||
verbose_name=_("Last used at"), | ||
blank=True, | ||
null=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% extends BASE_TEMPLATE %}{% load i18n %} | ||
{% block app_title %} | ||
<h2 xmlns="http://www.w3.org/1999/html">{{ title }}</h2> | ||
{% endblock %} | ||
|
||
{% block menu %} | ||
{{ block.super }} | ||
<form method="post" action="{% url "user_token_create"%}">{% csrf_token %} | ||
<div> | ||
<h2> | ||
<button type="submit" name="user_token_create" id="user_token_create" | ||
value="{% trans "Generate a New Token" %}" class="btn btn-block btn-primary btn-large" style="padding: 10px"> | ||
<i class="icon-plus icon-white icon-2x" style=" vertical-align: middle;"></i> | ||
{% trans "Generate a New Token" %} | ||
</button> | ||
</h2> | ||
</div> | ||
</form> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% extends 'user_token_base.html' %}{% load i18n %} | ||
{% block content %} | ||
<h3>Delete token of "{{ username }}"</h3> | ||
<form action="" method="post">{% csrf_token %} | ||
<p class="alert alert-danger">{% trans "You asked to delete a token.<br />It will be permanently deleted and this action cannot be undone.<br />Please confirm." %}</p> | ||
<p><input type="submit" class="btn btn-danger" name="delete_confirm" value="{% trans "Ok" %}" /> <a class="btn btn-default" href="javascript:history.back()">{% trans "Cancel" %}</a></p> | ||
</form> | ||
|
||
{% endblock %} |
Oops, something went wrong.