Skip to content

Commit

Permalink
integrates accounts app from DHBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
klifish committed Jan 12, 2023
1 parent c7c4646 commit d1065a8
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 46 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ classifiers = [
]

dependencies = [
"django ==2.2",
"django == 3.0",
"django-extensions",
"psycopg2 ==2.8.6",
"py-solc",
Expand All @@ -43,6 +43,7 @@ dependencies = [
"ethereum ==2.3.1",
"rlp ==1.0.1",
"eth_utils >=1.0.3",
"djangorestframework == 3.14.0"
]


Expand Down
36 changes: 27 additions & 9 deletions src/luce_django/luce/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .forms import UserAdminCreationForm, UserAdminChangeForm
from .models import User


class UserAdmin(BaseUserAdmin):
# The forms to add and change user instances
form = UserAdminChangeForm
Expand All @@ -19,17 +20,35 @@ class UserAdmin(BaseUserAdmin):
list_display = ('email', 'admin')
list_filter = ('admin',)
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name', 'last_name', 'institution')}),
('Web3', {'fields': ('ethereum_public_key',)}),
('Permissions', {'fields': ('admin', 'staff','active')}),
(
None, {
'fields': ('email', 'password')
}
),
(
'Personal info', {
'fields': ('first_name', 'last_name', 'institution')
}
),
(
'Web3', {
'fields': ('ethereum_public_key',)
}
),
(
'Permissions', {
'fields': ('admin', 'staff', 'active')
}
),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'first_name', 'last_name', 'institution', 'password1', 'password2')}
(
None, {
'classes': ('wide',),
'fields': ('email', 'first_name', 'last_name', 'institution', 'password1', 'password2')
}
),
)
search_fields = ('email',)
Expand All @@ -40,6 +59,5 @@ class UserAdmin(BaseUserAdmin):
admin.site.register(User, UserAdmin)



# Remove Group Model from admin. We're not using it.
admin.site.unregister(Group)
admin.site.unregister(Group)
5 changes: 3 additions & 2 deletions src/luce_django/luce/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
class RegisterForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
password2 = forms.CharField(label='Confirm password', widget=forms.PasswordInput)
access_token = forms.CharField(label='Access token', widget=forms.TextInput)

class Meta:
model = User
fields = ('email','first_name', 'last_name', 'institution')
fields = ('email', 'first_name', 'last_name', 'access_token', 'institution')

def clean_email(self):
email = self.cleaned_data.get('email')
Expand Down Expand Up @@ -87,7 +88,7 @@ class UserAdminChangeForm(forms.ModelForm):

class Meta:
model = User
fields = ('email', 'first_name', 'last_name', 'institution', 'password', 'active', 'staff', 'admin')
fields = ('email', 'first_name', 'last_name', 'institution' , 'user_type', 'password', 'active', 'staff' , 'admin')

def clean_password(self):
# Regardless of what the user provides, return the initial value.
Expand Down
18 changes: 18 additions & 0 deletions src/luce_django/luce/accounts/migrations/0008_user_user_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0 on 2023-01-12 14:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0007_user_ethereum_private_key'),
]

operations = [
migrations.AddField(
model_name='user',
name='user_type',
field=models.IntegerField(choices=[(0, 'Data Provider'), (1, 'Data Requester')], default=0),
),
]
123 changes: 123 additions & 0 deletions src/luce_django/luce/accounts/migrations/0009_auto_20230112_1437.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Generated by Django 2.2 on 2023-01-12 14:37

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


class Migration(migrations.Migration):

dependencies = [
('accounts', '0008_user_user_type'),
]

operations = [
migrations.CreateModel(
name='ClinicalPurpose',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('use_for_decision_support', models.BooleanField(default=False)),
('use_for_disease_support', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='ConsentContract',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('contract_address', models.CharField(max_length=255, null=True)),
],
),
migrations.CreateModel(
name='GeneralResearchPurpose',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('use_for_methods_development', models.BooleanField(default=False)),
('use_for_reference_or_control_material', models.BooleanField(default=False)),
('use_for_research_concerning_populations', models.BooleanField(default=False)),
('use_for_research_ancestry', models.BooleanField(default=False)),
('use_for_biomedical_research', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='HMBResearchPurpose',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('use_for_research_concerning_fundamental_biology', models.BooleanField(default=False)),
('use_for_research_concerning_genetics', models.BooleanField(default=False)),
('use_for_research_concerning_drug_development', models.BooleanField(default=False)),
('use_for_research_concerning_any_disease', models.BooleanField(default=False)),
('use_for_research_concerning_age_categories', models.BooleanField(default=False)),
('use_for_research_concerning_gender_categories', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='Restrictions',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('no_restrictions', models.BooleanField()),
('open_to_general_research_and_clinical_care', models.BooleanField()),
('open_to_HMB_research', models.BooleanField()),
('open_to_population_and_ancestry_research', models.BooleanField()),
('open_to_disease_specific', models.BooleanField()),
],
),
migrations.AddField(
model_name='user',
name='age',
field=models.IntegerField(null=True),
),
migrations.AddField(
model_name='user',
name='country',
field=models.CharField(max_length=25, null=True),
),
migrations.AddField(
model_name='user',
name='gender',
field=models.CharField(choices=[(0, 'Male'), (1, 'Female')], max_length=6, null=True),
),
migrations.CreateModel(
name='ResearchPurpose',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('HMB_research_purpose', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.HMBResearchPurpose')),
('clinical_purpose', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.ClinicalPurpose')),
('general_research_purpose', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.GeneralResearchPurpose')),
],
),
migrations.CreateModel(
name='LuceRegistry',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('contract_address', models.CharField(max_length=255, null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='DataContract',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('contract_address', models.CharField(max_length=255, null=True, unique=True)),
('description', models.CharField(max_length=255, null=True)),
('licence', models.IntegerField(default=1)),
('link', models.CharField(max_length=255, null=True)),
('consent_contract', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.ConsentContract')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='consentcontract',
name='research_purpose',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='accounts.ResearchPurpose'),
),
migrations.AddField(
model_name='consentcontract',
name='restrictions',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='accounts.Restrictions'),
),
migrations.AddField(
model_name='consentcontract',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
Loading

0 comments on commit d1065a8

Please sign in to comment.