diff --git a/.gitea/workflows/ci-pipeline.yaml b/.gitea/workflows/ci-pipeline.yaml index f7d4633..02ba211 100644 --- a/.gitea/workflows/ci-pipeline.yaml +++ b/.gitea/workflows/ci-pipeline.yaml @@ -50,7 +50,7 @@ jobs: - name: Get DIDKit wheel id: didkit run: | - wget https://gitea.pangea.org/trustchain-oc1-orchestral/ssikit_trustchain/raw/branch/master/didkit-0.3.2-cp311-cp311-manylinux_2_34_x86_64.whl + wget -O didkit-0.3.2-cp311-cp311-manylinux_2_34_x86_64.whl https://gitea.pangea.org/api/v1/repos/trustchain-oc1-orchestral/ssikit_trustchain/raw/didkit-0.3.2-cp311-cp311-manylinux_2_34_x86_64.whl?token=${{ secrets.FILE_GETTER_TOKEN }} echo "Successfully downloaded DIDkit" - name: Install dependencies @@ -69,3 +69,21 @@ jobs: source venv/bin/activate python manage.py test + + deploy: + needs: test + runs-on: self-hosted + steps: + - uses: actions/checkout@v4 + + - name: Trigger Remote Script + run: | + response=$(curl -s -o /dev/null -w "%{http_code}" -X POST http://45.150.187.54:5000/trigger-script -H "Authorization: SecretToken") + if [ "$response" -ne 200 ]; then + echo "Script execution failed with HTTP status $response" + exit 1 + else + echo "Script execution successful" + exit 0 + fi + if: success() && github.ref == 'refs/heads/main' diff --git a/examples/excel_templates/course-credential.xlsx b/examples/excel_templates/course-credential.xlsx new file mode 100644 index 0000000..05cc159 Binary files /dev/null and b/examples/excel_templates/course-credential.xlsx differ diff --git a/examples/excel_templates/device-purchase.xlsx b/examples/excel_templates/device-purchase.xlsx new file mode 100644 index 0000000..0a0a924 Binary files /dev/null and b/examples/excel_templates/device-purchase.xlsx differ diff --git a/examples/excel_templates/e-operator-claim.xlsx b/examples/excel_templates/e-operator-claim.xlsx new file mode 100644 index 0000000..f8f886e Binary files /dev/null and b/examples/excel_templates/e-operator-claim.xlsx differ diff --git a/examples/excel_templates/federation-membership.xlsx b/examples/excel_templates/federation-membership.xlsx new file mode 100644 index 0000000..3d20590 Binary files /dev/null and b/examples/excel_templates/federation-membership.xlsx differ diff --git a/examples/excel_templates/financial-vulnerability.xlsx b/examples/excel_templates/financial-vulnerability.xlsx new file mode 100644 index 0000000..012929f Binary files /dev/null and b/examples/excel_templates/financial-vulnerability.xlsx differ diff --git a/examples/excel_templates/membership-card.xlsx b/examples/excel_templates/membership-card.xlsx new file mode 100644 index 0000000..c075579 Binary files /dev/null and b/examples/excel_templates/membership-card.xlsx differ diff --git a/examples/financial-vulnerability.xlsx b/examples/financial-vulnerability.xlsx new file mode 100644 index 0000000..eb016f3 Binary files /dev/null and b/examples/financial-vulnerability.xlsx differ diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index 5476507..59d0eb3 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -23,7 +23,7 @@ from idhub.models import ( from idhub_auth.models import User -class TermsConditionsForm(forms.Form): +class TermsConditionsForm2(forms.Form): accept = forms.BooleanField( label=_("Accept terms and conditions of the service"), required=False @@ -50,6 +50,65 @@ class TermsConditionsForm(forms.Form): return +class TermsConditionsForm(forms.Form): + accept_privacy = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), + required=False + ) + accept_legal = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), + required=False + ) + accept_cookies = forms.BooleanField( + widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}), + required=False + ) + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop('user', None) + super().__init__(*args, **kwargs) + + def get_label(self, url, read): + label = _('I read and accepted the') + label += f' {read}' + return label + + def privacy_label(self): + url = "https://laweb.pangea.org/politica-de-privacitat/" + read = _("Privacy policy") + return self.get_label(url, read) + + def legal_label(self): + url = "https://laweb.pangea.org/avis-legal/" + read = _("Legal policy") + return self.get_label(url, read) + + def cookies_label(self): + url = "https://laweb.pangea.org/politica-de-cookies-2/" + read = _("Cookies policy") + return self.get_label(url, read) + + def clean(self): + data = self.cleaned_data + privacy = data.get("accept_privacy") + legal = data.get("accept_legal") + cookies = data.get("accept_cookies") + if privacy and legal and cookies: + self.user.accept_gdpr = True + else: + self.user.accept_gdpr = False + return data + + def save(self, commit=True): + + if commit: + self.user.save() + return self.user + + return + + class ImportForm(forms.Form): did = forms.ChoiceField(label=_("Did"), choices=[]) eidas1 = forms.ChoiceField( @@ -189,7 +248,7 @@ class ImportForm(forms.Form): cred = VerificableCredential( verified=False, user=user, - csv_data=json.dumps(row), + csv_data=json.dumps(row, default=str), issuer_did=self._did, schema=self._schema, eidas1_did=self._eidas1 diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 3773cab..25ac28d 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -25,7 +25,7 @@ from django.contrib import messages from utils import credtools from idhub_auth.models import User from idhub_auth.forms import ProfileForm -from idhub.mixins import AdminView +from idhub.mixins import AdminView, Http403 from idhub.email.views import NotifyActivateUserByEmail from idhub.admin.forms import ( ImportForm, @@ -60,9 +60,9 @@ from idhub.models import ( class TermsAndConditionsView(AdminView, FormView): template_name = "idhub/admin/terms_conditions.html" - title = _("GDPR") + title = _('Data protection') section = "" - subtitle = _('Accept Terms and Conditions') + subtitle = _('Terms and Conditions') icon = 'bi bi-file-earmark-medical' form_class = TermsConditionsForm success_url = reverse_lazy('idhub:admin_dashboard') @@ -70,7 +70,12 @@ class TermsAndConditionsView(AdminView, FormView): def get_form_kwargs(self): kwargs = super().get_form_kwargs() kwargs['user'] = self.request.user - kwargs['initial'] = {"accept": self.request.user.accept_gdpr} + if self.request.user.accept_gdpr: + kwargs['initial'] = { + "accept_privacy": True, + "accept_legal": True, + "accept_cookies": True + } return kwargs def form_valid(self, form): @@ -82,7 +87,9 @@ class DobleFactorAuthView(AdminView, View): url = reverse_lazy('idhub:admin_dashboard') def get(self, request, *args, **kwargs): - self.check_valid_user() + if not self.request.user.is_admin: + raise Http403() + if not self.request.session.get("2fauth"): return redirect(self.url) @@ -700,12 +707,13 @@ class DidsView(Credentials, SingleTableView): def get_context_data(self, **kwargs): queryset = kwargs.pop('object_list', None) + dids = DID.objects.filter(user=self.request.user) if queryset is None: - self.object_list = self.model.objects.all() + self.object_list = dids.all() context = super().get_context_data(**kwargs) context.update({ - 'dids': DID.objects.filter(user=self.request.user), + 'dids': dids }) return context @@ -905,19 +913,20 @@ class SchemasImportAddView(SchemasMix): def get(self, request, *args, **kwargs): self.check_valid_user() - file_name = kwargs['file_schema'] + self.file_name = kwargs['file_schema'] schemas_files = os.listdir(settings.SCHEMAS_DIR) - if file_name not in schemas_files: + if self.file_name not in schemas_files: + file_name = self.file_name messages.error(self.request, f"The schema {file_name} not exist!") return redirect('idhub:admin_schemas_import') - schema = self.create_schema(file_name) + schema = self.create_schema() if schema: messages.success(self.request, _("The schema was added sucessfully")) return redirect('idhub:admin_schemas') - def create_schema(self, file_name): - data = self.open_file(file_name) + def create_schema(self): + data = self.open_file() try: ldata = json.loads(data) assert credtools.validate_schema(ldata) @@ -933,7 +942,7 @@ class SchemasImportAddView(SchemasMix): _description = json.dumps(ldata.get('description', '')) schema = Schemas.objects.create( - file_schema=file_name, + file_schema=self.file_name, data=data, type=title, _name=_name, @@ -944,9 +953,9 @@ class SchemasImportAddView(SchemasMix): schema.save() return schema - def open_file(self, file_name): + def open_file(self): data = '' - filename = Path(settings.SCHEMAS_DIR).joinpath(file_name) + filename = Path(settings.SCHEMAS_DIR).joinpath(self.file_name) with filename.open() as schema_file: data = schema_file.read() @@ -955,7 +964,7 @@ class SchemasImportAddView(SchemasMix): def get_template_description(self): context = {} template_name = 'credentials/{}'.format( - self.schema.file_schema + self.file_name ) tmpl = get_template(template_name) return tmpl.render(context) @@ -970,7 +979,7 @@ class SchemasImportAddView(SchemasMix): class ImportView(ImportExport, SingleTableView): template_name = "idhub/admin/import.html" table_class = DataTable - subtitle = _('Import data') + subtitle = _('Imported data') icon = '' model = File_datas diff --git a/idhub/email/views.py b/idhub/email/views.py index f14e2a5..caa9370 100644 --- a/idhub/email/views.py +++ b/idhub/email/views.py @@ -57,12 +57,13 @@ class NotifyActivateUserByEmail: html_email = loader.render_to_string(self.html_email_template_name, context) email_message.attach_alternative(html_email, 'text/html') try: - if settings.DEVELOPMENT: - logger.warning(to_email) - logger.warning(body) + if settings.ENABLE_EMAIL: + email_message.send() return - email_message.send() + logger.warning(to_email) + logger.warning(body) + except Exception as err: logger.error(err) return diff --git a/idhub/management/commands/initial_datas.py b/idhub/management/commands/initial_datas.py index 69c1ef5..00224d9 100644 --- a/idhub/management/commands/initial_datas.py +++ b/idhub/management/commands/initial_datas.py @@ -23,11 +23,12 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): ADMIN_EMAIL = config('ADMIN_EMAIL', 'admin@example.org') ADMIN_PASSWORD = config('ADMIN_PASSWORD', '1234') - USER_EMAIL = config('USER_EMAIL', 'user1@example.org') - USER_PASSWORD = config('USER_PASSWORD', '1234') self.create_admin_users(ADMIN_EMAIL, ADMIN_PASSWORD) - self.create_users(USER_EMAIL, USER_PASSWORD) + if settings.CREATE_TEST_USERS: + for u in range(1, 6): + user = 'user{}@example.org'.format(u) + self.create_users(user, '1234') BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent ORGANIZATION = os.path.join(BASE_DIR, settings.ORG_FILE) diff --git a/idhub/models.py b/idhub/models.py index fea0156..c1feadd 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -674,7 +674,6 @@ class VerificableCredential(models.Model): 'organisation': settings.ORGANIZATION or '', } context.update(d) - context['firstName'] = "" return context def render(self, domain): diff --git a/idhub/templates/auth/2fadmin.html b/idhub/templates/auth/2fadmin.html index 4dc2ae6..e96d1b7 100644 --- a/idhub/templates/auth/2fadmin.html +++ b/idhub/templates/auth/2fadmin.html @@ -5,14 +5,14 @@
-{% blocktrans %}You're receiving this email because you try to access in {{ site_name }}.{% endblocktrans %} +{% blocktrans %}You're receiving this email because you tried to access {{ site_name }}.{% endblocktrans %}
diff --git a/idhub/templates/auth/2fadmin_email.txt b/idhub/templates/auth/2fadmin_email.txt index a9ef3e5..6328f66 100644 --- a/idhub/templates/auth/2fadmin_email.txt +++ b/idhub/templates/auth/2fadmin_email.txt @@ -1,5 +1,5 @@ {% load i18n %}{% autoescape off %} -{% blocktrans %}You're receiving this email because you try to access in {{ site_name }}.{% endblocktrans %} +{% blocktrans %}You're receiving this email because you tried to access {{ site_name }}.{% endblocktrans %} {% trans "Please go to the following page" %} {% block reset_link %} diff --git a/idhub/templates/auth/login.html b/idhub/templates/auth/login.html index 18abfd8..1a1775c 100644 --- a/idhub/templates/auth/login.html +++ b/idhub/templates/auth/login.html @@ -46,7 +46,7 @@ class="btn btn-primary form-control" id="submit-id-submit"> -
{% endif %} -