Skip to content

Commit

Permalink
Merge pull request #257 from Exifly/main
Browse files Browse the repository at this point in the history
Bump to v2.2.0
  • Loading branch information
gdjohn4s authored Sep 12, 2023
2 parents b906445 + 1e3d68b commit 493c73e
Show file tree
Hide file tree
Showing 49 changed files with 1,684 additions and 616 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: [gdjohn4s, FlavioAdamo]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: apivault
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ share/python-wheels/
MANIFEST
*.log

# django static files (they will be generated directly on the server)
./backend/static/*
static/*
static/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
64 changes: 43 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
MIT License

Copyright (c) 2023 ApiVault

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)

Creative Commons Corporation ("Creative Commons") is not a law firm and does not provide legal services. Distributing this license does not create an attorney-client relationship. Creative Commons provides this information on an "as-is" basis. Creative Commons makes no warranties regarding the information provided, and disclaims liability for damages resulting from its use.

License

The authors of the work (hereinafter referred to as "you" or "the authors") grant you the non-exclusive rights to use the described work under the following terms:

Title: Apivault
Authors: Giovanni D'Andrea, Flavio Adamo

1. Definitions

a. "Derivative Works" means any work that is based on or derived from the original work, including the work based on the original work and expressing the original author's views or opinions.
b. "Commercial Use" means use of the work for any purpose that is primarily intended for or directed toward commercial advantage or private monetary compensation.
c. "Licenses Granted" are the additional restrictions that apply to the work under this license.

2. License Grant

Subject to the terms and conditions of this license, the authors grant you a worldwide, non-exclusive, non-sublicensable, revocable, and royalty-free license to:

a. Reproduce, distribute, and publicly communicate the work, including derivative works, under the terms of this license.
b. Attribute the authors as suggested by the authors or requested by them.

3. Restrictions

This license is subject to the following restrictions:

a. NonCommercial Use: You may not use the work for Commercial Use.
b. No Derivative Works: You may not modify, adapt, or build upon the original work to create a Derivative Work.
c. License Application: Any use or distribution of the work or derivative works must be made in compliance with the terms of this license and must attribute the authors as suggested by the authors or requested by them.

4. Other Conditions

a. Waivers: The authors provide the work "as is" and make no warranties regarding the work, express or implied, and disclaim liability for damages resulting from using the work.
b. Limitation of Liability: In no event will the authors be liable to you or any third party for any damages, including any lost profits, lost savings, or other incidental or consequential damages arising out of the use or inability to use the work, even if advised of the possibility of such damages.
c. Termination of License: Any use or distribution of the work in violation of the terms of this license will automatically terminate your rights under this license, without prejudice to any legal rights and remedies the authors may have.

Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with the authors regarding the work or any separate legal agreements between you and the authors.

This license is governed and interpreted under the laws of the state where the authors have their primary residence, without giving effect to any principles of conflicts of law.

The complete and official version of the CC BY-NC-ND 4.0 license can be found at the following address: https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<p align="center">
<a href="https://github.com/Exifly/ApiVault/tree/release" alt="Stable">
<img src="https://img.shields.io/badge/stable-2.0.5-blue?style=for-the-badge" /></a>
<img src="https://img.shields.io/badge/stable-2.1.0-blue?style=for-the-badge" /></a>
<a href="https://github.com/exifly/apivault/graphs/contributors" alt="Contributors">
<img src="https://img.shields.io/github/contributors/exifly/apivault?style=for-the-badge" /></a>
<a href="https://github.com/exifly/apivault/pulse" alt="Activity">
Expand Down Expand Up @@ -194,7 +194,7 @@ If you want to support us with a coffee, that's how to do it! ❤️
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/T6T0LL2YG)

## License
ApiVault is licensed under the terms of **MIT License**. Check out [LICENSE](https://github.com/Exifly/ApiVault/blob/main/LICENSE) for details.
ApiVault is licensed under the terms of **CC BY-NC-ND 4.0**. Check out [LICENSE](https://github.com/Exifly/ApiVault/blob/main/LICENSE) for details.

<br>

Expand Down
17 changes: 17 additions & 0 deletions backend/apivault/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

class ApiFilterMixin:
def get_ordering_fields(self):
ordering = self.request.query_params.get('order', None)
allowed_fields = [field.lstrip('-') for field in getattr(self, 'allowed_order_field', [])]

if ordering and ordering.lstrip('-') in allowed_fields:
return (ordering,)

return None


def apply_ordering(self, queryset):
ordering_fields = self.get_ordering_fields()
if ordering_fields:
return queryset.order_by(*ordering_fields)
return queryset
11 changes: 10 additions & 1 deletion backend/apivault/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
SECRET_KEY = 'django-insecure-pnadu&92%d==xohx_27-z%is=nb7c&s!ph7#1r$i0d#oxttgh5'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = True


ALLOWED_HOSTS = ['*']
Expand All @@ -55,6 +55,7 @@

'rest_framework_simplejwt',
'rest_framework',
'drf_spectacular',
'drf_yasg',

'corsheaders',
Expand Down Expand Up @@ -84,6 +85,14 @@
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}

SPECTACULAR_SETTINGS = {
'TITLE': 'ApiVault',
'DESCRIPTION': 'Your gateway to a world of public APIs',
'VERSION': '2.1.0',
'SERVE_INCLUDE_SCHEMA': False,
}

SIMPLE_JWT = {
Expand Down
24 changes: 3 additions & 21 deletions backend/apivault/urls.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
"""apivault URL Configuration"""
from drf_spectacular.views import SpectacularSwaggerView
from django.conf.urls.static import static
from django.contrib import admin
from django.conf import settings
from django.urls import (
path,
include,
re_path
)
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi


schema_view = get_schema_view(
openapi.Info(
title="Snippets API",
default_version='v1',
description="Test description",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="contact@snippets.local"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=[permissions.AllowAny],
)


urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -34,7 +16,7 @@
path('api/interaction', include('interaction.urls')),

#documentation
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),]
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
3 changes: 2 additions & 1 deletion backend/authentication/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.2 on 2023-06-17 15:31
# Generated by Django 4.2.3 on 2023-07-15 10:03

import django.contrib.auth.models
import django.contrib.auth.validators
Expand Down Expand Up @@ -31,6 +31,7 @@ class Migration(migrations.Migration):
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('type', models.CharField(choices=[('D', 'DEVELOPER'), ('A', 'ADMIN')], default='D', max_length=2)),
('is_verified', models.BooleanField(default=False)),
('picture', models.URLField(blank=True, null=True)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
Expand Down
18 changes: 0 additions & 18 deletions backend/authentication/migrations/0002_defaultuser_picture.py

This file was deleted.

4 changes: 2 additions & 2 deletions backend/authentication/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def register_social_user(email: str, name: str, picture: str):
user = DefaultUser.objects.create_user(
username=generate_username(name),
email=email,
password="pipposito",
password="<PASSWORD>",
is_verified=True,
picture=picture
)

registered_user = authenticate(
username=user.username,
password="pipposito"
password="<PASSWORD>"
)

return {
Expand Down
5 changes: 5 additions & 0 deletions backend/docker/command/start_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import subprocess
import time
import os

print('Starting server...')
time.sleep(25)

SERVER_PORT = 9001
SERVER_HOST = "0.0.0.0"

Expand All @@ -23,4 +27,5 @@
subprocess.call(CMD_MIGRATE_AUTH, shell=True)
subprocess.call(CMD_MIGRATE, shell=True)
subprocess.call(CMD_LOAD_FIXTURES, shell=True)
subprocess.call("python3 manage.py collectstatic --noinput", shell=True)
subprocess.call(CMD_RUNSERVER, shell=True)
9 changes: 7 additions & 2 deletions backend/docker/command/start_server_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
CMD_MAKE_MIGRATIONS: str = f"{PYTHON_COMMAND} manage.py makemigrations"
CMD_MIGRATE_AUTH: str = f"{PYTHON_COMMAND} manage.py migrate auth"
CMD_MIGRATE: str = f"{PYTHON_COMMAND} manage.py migrate"
CMD_STATIC: str = f"{PYTHON_COMMAND} manage.py collectstatic"
CMD_STATIC: str = f"{PYTHON_COMMAND} manage.py collectstatic --noinput"

CMD_LOAD_APIS: str = f"{PYTHON_COMMAND} manage.py loaddata fixtures/apis.json --app vault"
CMD_LOAD_CATEGORIES: str = f"{PYTHON_COMMAND} manage.py loaddata fixtures/categories.json --app vault"

#CMD_LOAD_FIXTURES: str = f"{PYTHON_COMMAND} manage.py loaddata fixtures/vault.json --app vault"
CMD_RUNSERVER: str = f"gunicorn apivault.wsgi -b :{SERVER_PORT}"

os.chdir(SHELL_DIRECTORY)

subprocess.call(CMD_MAKE_MIGRATIONS, shell=True)
subprocess.call(CMD_MIGRATE_AUTH, shell=True)
subprocess.call(CMD_MIGRATE, shell=True)
subprocess.call(CMD_LOAD_CATEGORIES, shell=True)
subprocess.call(CMD_LOAD_APIS, shell=True)

subprocess.call(CMD_STATIC, shell=True)
subprocess.call(CMD_RUNSERVER, shell=True)
9 changes: 8 additions & 1 deletion backend/interaction/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from .models import Like, Feedback
from django.contrib import admin
from .models import Like


class CustomFeedbacksAdmin(admin.ModelAdmin):
list_display = ("id", "email", "message", "user")
search_fields = ("name", "id")


admin.site.register(Like)
admin.site.register(Feedback, CustomFeedbacksAdmin)
11 changes: 11 additions & 0 deletions backend/interaction/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from django.shortcuts import get_object_or_404
from rest_framework import status, permissions
from rest_framework.response import Response
from .serializers import FeedbackSerializer
from rest_framework.views import APIView
from rest_framework import generics
from vault.models import API
from .models import(
Like,
Expand Down Expand Up @@ -33,3 +35,12 @@ def delete(self, request, api_id, format=None):
return Response({'detail': 'You have not liked this API yet.'}, status=status.HTTP_400_BAD_REQUEST)


class FeedbackView(generics.CreateAPIView):
"""
View to handle user feedbacks
"""
permission_classes = [permissions.IsAuthenticated]
serializer_class = FeedbackSerializer

def perform_create(self, serializer):
serializer.save(user=self.request.user)
2 changes: 1 addition & 1 deletion backend/interaction/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.2 on 2023-06-17 15:31
# Generated by Django 4.2.3 on 2023-07-15 10:03

from django.conf import settings
from django.db import migrations, models
Expand Down
26 changes: 26 additions & 0 deletions backend/interaction/migrations/0002_feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.3 on 2023-07-21 11:11

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('interaction', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Feedback',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank=True, max_length=30, null=True)),
('email', models.EmailField(blank=True, max_length=254, null=True)),
('message', models.TextField(max_length=150)),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
12 changes: 9 additions & 3 deletions backend/interaction/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from apivault import settings
from django.db import models
from vault.models import API

class Like(models.Model):
Expand All @@ -16,6 +16,12 @@ def __str__(self):
return f"{self.user} - {self.api}"


class Feedback(models.Model):
name = models.CharField(max_length=30, null=True, blank=True)
email = models.EmailField(null=True, blank=True)
message = models.TextField(max_length=150, null=False, blank=False)
user = models.ForeignKey(settings.AUTH_USER_MODEL, db_index=True, blank=True, null=True, on_delete=models.CASCADE)



def __str__(self):
username = "Anonymous" if self.name is None else self.name
return f"{username} - {self.message}"
10 changes: 10 additions & 0 deletions backend/interaction/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from rest_framework import serializers
from interaction.models import (
Feedback
)

class FeedbackSerializer(serializers.ModelSerializer):
class Meta:
model = Feedback
fields = ["name", "email", "message"]
read_only_fields = ["user"]
3 changes: 2 additions & 1 deletion backend/interaction/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.urls import path
from .api import LikeAPIView
from .api import LikeAPIView, FeedbackView

urlpatterns = [
path('/like/<int:api_id>/', LikeAPIView.as_view(), name='like-api'),
path('/feedback/', FeedbackView.as_view(), name='feedback')
]
Loading

0 comments on commit 493c73e

Please sign in to comment.