Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Add Prefix Registry table and data
Browse files Browse the repository at this point in the history
Changes to be committed:
	new file:   core/migrations/0002_prefixes.py
	modified:   core/models.py
	new file:   core_prefixes.sql
  • Loading branch information
HadleyKing committed Mar 29, 2022
1 parent 311cf8c commit 78097f2
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 33 deletions.
23 changes: 23 additions & 0 deletions core/migrations/0002_prefixes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.1.7 on 2022-03-17 16:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Prefixes',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=100)),
('prefix', models.CharField(max_length=5)),
('registration_date', models.DateTimeField()),
('registration_certificate', models.CharField(max_length=1000)),
],
),
]
78 changes: 45 additions & 33 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Customer user model.
# Source: https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#extending-the-existing-user-model
# Source: https://docs.djangoproject.com/en/3.1/topics/db/models/#many-to-one-relationships
#!/usr/bin/env python3
"""Customer user model.
Source: https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#extending-the-existing-user-model
Source: https://docs.djangoproject.com/en/3.1/topics/db/models/#many-to-one-relationships
"""

from django.db import models
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.dispatch import receiver
from django.urls import reverse
from django_rest_passwordreset.signals import reset_password_token_created
from django.core.mail import send_mail
from rest_framework import status
from rest_framework.response import Response

Expand All @@ -16,7 +18,8 @@ def password_reset_token_created(sender, instance, reset_password_token, *args,
"""
Create the token for a password reset.
"""
email_plaintext_message = "{}?token={}".format(reverse('password_reset:reset-password-request'), reset_password_token.key)
email_plaintext_message = "{}?token={}".format(reverse(
'password_reset:reset-password-request'), reset_password_token.key)

try:
send_mail(
Expand All @@ -27,52 +30,61 @@ def password_reset_token_created(sender, instance, reset_password_token, *args,
recipient_list=[reset_password_token.user.email],
fail_silently=False,
)
except Exception as e:

except Exception as error:
print('activation_link', reset_password_token)
# print('ERROR: ', e)
# print('ERROR: ', error)
# TODO: Should handle when the send_mail function fails?
# return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data={"message": "Not able to send authentication email: {}".format(e)})
return Response(status=status.HTTP_201_CREATED, data={"message": "Account has been requested. Activation email was not sent. Check with your database administrator for activation of your api account"})
# return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data={
# "message": "Not able to send authentication email: {}".format(error)})
return Response(status=status.HTTP_201_CREATED,
data={"message": "Reset token has been requested but email was not sent."\
f" Check with your database administrator for your token. {error}"})

class Profile(models.Model):
"""
Modle for storing additional user information
Public Profile
User Affiliation
User ORCID
"""
username = models.OneToOneField(User, on_delete=models.CASCADE)
# Public Profile
public = models.BooleanField(blank = True, default=False)
# User Affiliation
affiliation = models.CharField(blank = True, max_length = 1000)
# User ORCID
orcid = models.CharField(blank = True, max_length = 1000)

# API Information is kept separate so that we can use it
# elsewhere easily.


# API Information
class ApiInfo(models.Model):
"""API Information
API Information is kept separate so that we can use it
elsewhere easily.
Set the local user.
Servers for which the user has keys.
The username on the server.
max_length = 15 because hostnames are xxx.xxx.xxx.xxx
Need to use a human-readable hostname
Need to know where to make calls.
"Arbitrarily" long token
Permissions and other information.
"""

# Set the local user.
local_username = models.ForeignKey(User, on_delete = models.CASCADE, related_name = 'custom_user')

# Servers for which the user has keys.

# The username on the server.
local_username = models.ForeignKey(
User,
on_delete = models.CASCADE,
related_name = 'custom_user'
)
username = models.CharField(blank = True, max_length = 1000)

# max_length = 15 because hostnames are xxx.xxx.xxx.xxx
hostname = models.CharField(blank = True, max_length = 15)

# Need to use a human-readable name
human_readable_hostname = models.CharField(blank = True, max_length = 1000)

# Need to know where to make calls.
public_hostname = models.CharField(blank = True, max_length = 1000)

# "Arbitrarily" long token
token = models.CharField(blank = True, max_length = 1000)

# Permissions and other information.
other_info = models.JSONField()

class Prefixes(models.Model):
"""Prefix Table: core_prefixes
"""
username = models.CharField(max_length = 100)
prefix = models.CharField(max_length = 5, primary_key=True, unique=True)
registration_date = models.DateTimeField()
registration_certificate = models.CharField(max_length = 1000)
62 changes: 62 additions & 0 deletions core_prefixes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "core_prefixes" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "username" varchar(100) NOT NULL, "prefix" varchar(5) NOT NULL, "registration_date" datetime NOT NULL, "registration_certificate" varchar(1000) NOT NULL);
INSERT INTO core_prefixes VALUES(1,'[email protected]','AWS','2020-12-14 19:36:01','93d836ebcfcc41f6817b36810082eb78');
INSERT INTO core_prefixes VALUES(2,'[email protected]','CIT','2020-12-14 19:36:01','1c8ff7f5f4864022886166b083e684f9');
INSERT INTO core_prefixes VALUES(3,'[email protected]','CAP','2020-12-14 19:36:01','4f191aec8ae0472591fb4b341e99f200');
INSERT INTO core_prefixes VALUES(4,'[email protected]','BCO','2020-12-14 19:36:01','56a369599f4d42bda047963ada468ed6');
INSERT INTO core_prefixes VALUES(5,'[email protected]','CC','2020-12-14 19:36:01','29c9fa47665a4242b2cf9a9366de9966');
INSERT INTO core_prefixes VALUES(6,'[email protected]','CDC','2020-12-14 19:36:01','130d8486529548ae9d77767d79132111');
INSERT INTO core_prefixes VALUES(7,'[email protected]','CLIA','2020-12-14 19:36:01','f488b45594054e1fafc213e6926aec97');
INSERT INTO core_prefixes VALUES(8,'[email protected]','COVID','2020-12-14 19:36:01','37ccddd1eb2b40acb7da7f77182ec10a');
INSERT INTO core_prefixes VALUES(9,'[email protected]','EPA','2020-12-14 19:36:01','6895b247fec84cbfbe30b9fbc4ccbe36');
INSERT INTO core_prefixes VALUES(10,'[email protected]','CSR','2020-12-14 19:36:01','81758be3d0ed4118adf8a11e702a35fd');
INSERT INTO core_prefixes VALUES(11,'[email protected]','FIC','2020-12-14 19:36:01','44509af8d44f4eea9662ebf3416489b3');
INSERT INTO core_prefixes VALUES(12,'[email protected]','FDA','2020-12-14 19:36:01','f22a9133501140ff9cc54ee4db2de5ac');
INSERT INTO core_prefixes VALUES(13,'[email protected]','GLY','2020-12-14 19:36:01','ab0b6da5899b4344a155911f0997a89f');
INSERT INTO core_prefixes VALUES(14,'[email protected]','GWU','2020-12-14 19:36:01','2b1ec43870924df5b0e351d44491add8');
INSERT INTO core_prefixes VALUES(15,'[email protected]','HIVE','2020-12-14 19:36:01','e9c3677d9c854cdf8328830e277416cf');
INSERT INTO core_prefixes VALUES(16,'[email protected]','HIVE1','2020-12-14 19:36:01','d6c3f6949b494fb9acccba831c6e30b8');
INSERT INTO core_prefixes VALUES(17,'[email protected]','NCCIH','2020-12-14 19:36:01','cdef03441753435c9636ed1f4b4c24d1');
INSERT INTO core_prefixes VALUES(18,'[email protected]','NCATS','2020-12-14 19:36:01','424a19e262564b4790580e5d2edb08d4');
INSERT INTO core_prefixes VALUES(19,'[email protected]','NCI','2020-12-14 19:36:01','628cb44cc23a4b0693992247a3cc6807');
INSERT INTO core_prefixes VALUES(20,'[email protected]','NHGRI','2020-12-14 19:36:01','71aa3ca0bd7a4fa38199806357380495');
INSERT INTO core_prefixes VALUES(21,'[email protected]','NHLBI','2020-12-14 19:36:01','faf999d8c839494bb6fde999757ee6bb');
INSERT INTO core_prefixes VALUES(22,'[email protected]','NEI','2020-12-14 19:36:01','6cde428fa5a74b17b4382fe98ea8ade4');
INSERT INTO core_prefixes VALUES(23,'[email protected]','NIA','2020-12-14 19:36:01','d88513ed17734d03a1a2dfd34d984f32');
INSERT INTO core_prefixes VALUES(24,'[email protected]','NIAAA','2020-12-14 19:36:01','911bfb0081f9475a9e0b1dc48cd86d54');
INSERT INTO core_prefixes VALUES(25,'[email protected]','NIAID','2020-12-14 19:36:01','8faaf0c866a147c0845412effb000bcb');
INSERT INTO core_prefixes VALUES(26,'[email protected]','NIBIB','2020-12-14 19:36:01','8f4d54fb2a414d65a1b1ff4efa57391f');
INSERT INTO core_prefixes VALUES(27,'[email protected]','NICHD','2020-12-14 19:36:01','f9806946229d4fce9a5b1ea019fd384c');
INSERT INTO core_prefixes VALUES(28,'[email protected]','NIDA','2020-12-14 19:36:01','40e44d503ec742e681d157a4721d6c83');
INSERT INTO core_prefixes VALUES(29,'[email protected]','NIDCD','2020-12-14 19:36:01','d086e7ac53d9443daf62545cd4924fe1');
INSERT INTO core_prefixes VALUES(30,'[email protected]','NIDCR','2020-12-14 19:36:01','8795c71e99d64a04863403b22cba4a0a');
INSERT INTO core_prefixes VALUES(31,'[email protected]','NIDDK','2020-12-14 19:36:01','ba3003869ace45a4a8d5fe3593cf7dfb');
INSERT INTO core_prefixes VALUES(32,'[email protected]','NIEHS','2020-12-14 19:36:01','e59e1dedc46d451e8dd36f794d60c628');
INSERT INTO core_prefixes VALUES(33,'[email protected]','NIH','2020-12-14 19:36:01','766e895b9bcd4a82b1c52a24b101c01b');
INSERT INTO core_prefixes VALUES(34,'[email protected]','NIMH','2020-12-14 19:36:01','5cc668fe57ff4120bcf480c09588092f');
INSERT INTO core_prefixes VALUES(35,'[email protected]','NIMHD','2020-12-14 19:36:01','d33b9d04dd69411aa0d316abd12a9bee');
INSERT INTO core_prefixes VALUES(36,'[email protected]','NINDS','2020-12-14 19:36:01','1be9871bad5f4a49bd56bd64546a9cf7');
INSERT INTO core_prefixes VALUES(37,'[email protected]','NINR','2020-12-14 19:36:01','cbe5ef4f558a4b83bc3fc63c7e818005');
INSERT INTO core_prefixes VALUES(38,'[email protected]','NLM','2020-12-14 19:36:01','a86248425ace467dbd02778700033e1c');
INSERT INTO core_prefixes VALUES(39,'[email protected]','NIAMS','2020-12-14 19:36:01','66b4efe748324214a74105d9d09024a1');
INSERT INTO core_prefixes VALUES(40,'[email protected]','NIGMS','2020-12-14 19:36:01','844dfd1a15b34b6680149a6b67a85d94');
INSERT INTO core_prefixes VALUES(41,'[email protected]','OHSU','2020-12-14 19:36:01','c63d0cc6717f4911bb0adf95a742d553');
INSERT INTO core_prefixes VALUES(42,'[email protected]','OMX','2020-12-14 19:36:01','2dccb03fc03047ac9c9a88200d178cd5');
INSERT INTO core_prefixes VALUES(43,'[email protected]','TEST','2020-12-14 19:36:01','dafc3b6e6cc94edc9d4a4637204a5506');
INSERT INTO core_prefixes VALUES(44,'[email protected]','TEST1','2020-12-14 19:36:01','4bc5333e11694af7bfbd1ae40e1b48d5');
INSERT INTO core_prefixes VALUES(45,'[email protected]','TEST2','2020-12-14 19:36:01','1dabc8be099b4a3da300b5513bd132ed');
INSERT INTO core_prefixes VALUES(46,'teasod@aasd','TEST3','2020-12-14 19:36:01','8661c8ab76d94e039216908ab524ba0f');
INSERT INTO core_prefixes VALUES(47,'[email protected]','TEST4','2020-12-14 19:36:01','0d55c2e9292d4c7b93dd89e29b72c20a');
INSERT INTO core_prefixes VALUES(48,'[email protected]','OD','2020-12-14 19:36:01','10fd0fd9b3db4d919c778b7d87d79ae0');
INSERT INTO core_prefixes VALUES(49,'[email protected]','TEST6','2020-12-14 19:36:01','f7c56e3ea091479eb90f622fcc415c38');
INSERT INTO core_prefixes VALUES(50,'[email protected]','TEST7','2020-12-14 19:36:01','b361889be7da4fbcae3b53c576501bf7');
INSERT INTO core_prefixes VALUES(51,'[email protected]','TEST8','2020-12-14 19:36:01','a437292d01514aff936d403bd1a9d01d');
INSERT INTO core_prefixes VALUES(52,'[email protected]','TEST9','2020-12-14 19:36:01','a26d969a81f14aaf8a4d7646a3392203');
INSERT INTO core_prefixes VALUES(53,'[email protected]','TST1','2020-12-14 19:36:01','aba46c52b94743aebba4d7e84fce77f3');
INSERT INTO core_prefixes VALUES(54,'[email protected]','TST2','2020-12-14 19:36:01','dcfbb38e4db14d869b08110446344f0f');
INSERT INTO core_prefixes VALUES(55,'[email protected]','YO','2020-12-14 19:36:01','df2ef4dc10f240daa1e702a0fd2c1c87');
INSERT INTO core_prefixes VALUES(56,'[email protected]','TEST5','2020-12-14 19:36:01','69e7b4ba02564f9a9493ec953f78b218');
INSERT INTO core_prefixes VALUES(57,'er','WE','2021-05-19 17:54:37','545ff2781689449ea3864eea493e644e');
INSERT INTO core_prefixes VALUES(58,'erwerf','WEWER','2021-05-19 17:54:45','b3bb50aaf438479ebe42fa884c07cb0a');
COMMIT;

0 comments on commit 78097f2

Please sign in to comment.