Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 privacy preserving architecture #2

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: '3'
services:

ganache_db:
image: trufflesuite/ganache-cli
image: trufflesuite/ganache:v7.7.3
restart: unless-stopped
command: --mnemonic luce --db /ganache_db --networkId 72 --host 0.0.0.0 --accounts 10 --defaultBalanceEther 1000000 --account "0x5714ad5f65fb27cb0d0ab914db9252dfe24cf33038a181555a7efc3dcf863ab3,1000000000000000000000000" --account "0xad740a17686169082f3148dcec143e4730fc69a636d710cb8e4e23ef966feadd,1000000000000000000000000" --account "0xdd11160def74259a8cfcb0282702ab65c1388cf4e0265f567fe0a3707957d810,1000000000000000000000000"
command: --database.dbPath /ganache_db --chain.networkId 72 -h 0.0.0.0 -e 1000000
ports:
- 8545:8545
environment:
Expand Down
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