-
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 branch 'qgis:master' into fix-icons-in-style-list
- Loading branch information
Showing
39 changed files
with
1,380 additions
and
54 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
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,39 @@ | ||
from functools import wraps | ||
from django.http import HttpResponseForbidden | ||
from rest_framework_simplejwt.authentication import JWTAuthentication | ||
from plugins.models import Plugin, PluginOutstandingToken | ||
from rest_framework_simplejwt.exceptions import InvalidToken, TokenError | ||
from rest_framework_simplejwt.token_blacklist.models import BlacklistedToken, OutstandingToken | ||
import datetime | ||
|
||
def has_valid_token(function): | ||
@wraps(function) | ||
def wrap(request, *args, **kwargs): | ||
auth_token = request.META.get("HTTP_AUTHORIZATION") | ||
package_name = kwargs.get('package_name') | ||
if not str(auth_token).startswith('Bearer'): | ||
raise InvalidToken("Invalid token") | ||
|
||
# Validate JWT token | ||
authentication = JWTAuthentication() | ||
try: | ||
validated_token = authentication.get_validated_token(auth_token[7:]) | ||
plugin_id = validated_token.payload.get('plugin_id') | ||
jti = validated_token.payload.get('refresh_jti') | ||
token_id = OutstandingToken.objects.get(jti=jti).pk | ||
is_blacklisted = BlacklistedToken.objects.filter(token_id=token_id).exists() | ||
if not plugin_id or is_blacklisted: | ||
raise InvalidToken("Invalid token") | ||
|
||
plugin = Plugin.objects.get(pk=plugin_id) | ||
if not plugin or plugin.package_name != package_name: | ||
raise InvalidToken("Invalid token") | ||
plugin_token = PluginOutstandingToken.objects.get(token__pk=token_id, plugin=plugin) | ||
plugin_token.last_used_on = datetime.datetime.now() | ||
plugin_token.save() | ||
request.plugin_token = plugin_token | ||
return function(request, *args, **kwargs) | ||
except (InvalidToken, TokenError) as e: | ||
return HttpResponseForbidden(str(e)) | ||
|
||
return wrap |
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
40 changes: 40 additions & 0 deletions
40
qgis-app/plugins/management/commands/organize_old_package.py
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,40 @@ | ||
# myapp/management/commands/organize_packages.py | ||
import os | ||
import shutil | ||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
from plugins.models import PluginVersion | ||
|
||
PLUGINS_STORAGE_PATH = getattr(settings, "PLUGINS_STORAGE_PATH", "packages") | ||
class Command(BaseCommand): | ||
help = 'Organize packages created before 2014 into folders by year' | ||
|
||
def handle(self, *args, **options): | ||
packages_dir = os.path.join(settings.MEDIA_ROOT, PLUGINS_STORAGE_PATH) | ||
|
||
# Some of the packages created on 2014 also need to be organized | ||
versions = PluginVersion.objects.filter(created_on__lt='2014-12-31').exclude(package__icontains='2014/') | ||
self.stdout.write(self.style.NOTICE(f'{versions.count()} packages will be organized.')) | ||
|
||
for version in versions: | ||
year_folder = os.path.join(packages_dir, str(version.created_on.year)) | ||
|
||
# Create the year folder if it doesn't exist | ||
os.makedirs(year_folder, exist_ok=True) | ||
|
||
# Copy the package file to the year folder | ||
old_path = version.package.path | ||
if os.path.exists(old_path): | ||
new_path = os.path.join(year_folder, os.path.basename(old_path)) | ||
if not os.path.exists(new_path): | ||
shutil.copy(old_path, year_folder) | ||
|
||
# Update the model with the new package path | ||
version.package.name = os.path.relpath(new_path, settings.MEDIA_ROOT) | ||
version.save() | ||
else: | ||
self.stdout.write(self.style.WARNING(f'Plugin version id {version.pk} ignored: {new_path} already exists.')) | ||
else: | ||
self.stdout.write(self.style.WARNING(f'Plugin version id {version.pk} ignored: {old_path} is not found.')) | ||
|
||
self.stdout.write(self.style.SUCCESS('Packages organized successfully')) |
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
24 changes: 24 additions & 0 deletions
24
qgis-app/plugins/migrations/0005_pluginoutstandingtoken.py
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,24 @@ | ||
# Generated by Django 2.2.25 on 2023-12-11 23:36 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('token_blacklist', '0007_auto_20171017_2214'), | ||
('plugins', '0004_merge_20231122_0223'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PluginOutstandingToken', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('is_blacklisted', models.BooleanField(default=False)), | ||
('plugin', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='plugins.Plugin')), | ||
('token', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='token_blacklist.OutstandingToken')), | ||
], | ||
), | ||
] |
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,28 @@ | ||
# Generated by Django 2.2.25 on 2023-12-18 02:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('plugins', '0005_pluginoutstandingtoken'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='pluginoutstandingtoken', | ||
name='description', | ||
field=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'), | ||
), | ||
migrations.AddField( | ||
model_name='pluginoutstandingtoken', | ||
name='is_newly_created', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='pluginoutstandingtoken', | ||
name='last_used_on', | ||
field=models.DateTimeField(blank=True, null=True, verbose_name='Last used on'), | ||
), | ||
] |
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,30 @@ | ||
# Generated by Django 2.2.25 on 2024-01-09 04:28 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('plugins', '0006_auto_20231218_0225'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='pluginversion', | ||
name='is_from_token', | ||
field=models.BooleanField(default=False, verbose_name='Is uploaded using token'), | ||
), | ||
migrations.AddField( | ||
model_name='pluginversion', | ||
name='token', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='plugins.PluginOutstandingToken', verbose_name='Token used'), | ||
), | ||
migrations.AlterField( | ||
model_name='pluginversion', | ||
name='created_by', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Created by'), | ||
), | ||
] |
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
Oops, something went wrong.