Commit 524d8313 authored by felix.herrmann's avatar felix.herrmann
Browse files

feat(access): add model for dataset access requests

parent d019e81f
# Generated by Django 2.2.12 on 2020-06-01 11:42
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('dddatasets', '0014_auto_20200520_1457'),
]
operations = [
migrations.CreateModel(
name='DataSetAccessRequest',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('dataset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dddatasets.DataSet')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
......@@ -330,6 +330,19 @@ class DataSetExternalLink(models.Model):
return self.site_title
class DataSetAccessRequest(models.Model):
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
dataset = models.ForeignKey("DataSet", on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
ar_string = "Access request to {} for {} pending since {}".format(
self.dataset, self.user, self.created_at.strftime("%d.%m.%Y, %H:%M:%S")
)
return _(ar_string)
class DataSet(models.Model):
OPEN_ACCESS = "OA"
METADATA_ONLY = "MO"
......@@ -475,6 +488,12 @@ class DataSet(models.Model):
class Meta:
permissions = (("ra_view_dataset", "View data set in restricted access mode"),)
def get_all_access_requests(self):
return DataSetAccessRequest.objects.filter(dataset=self)
def get_access_request(self, user):
return DataSetAccessRequest.objects.filter(dataset=self, user=user).first()
def clear_user_permissions(self, user):
for perm in get_perms(user, self):
remove_perm(perm, user, self)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment