Skip to content

Commit

Permalink
First commit #2616 #2594 #2591
Browse files Browse the repository at this point in the history
  • Loading branch information
pesikj committed Dec 1, 2024
1 parent 181e5e2 commit 1a07d93
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 13 deletions.
2 changes: 0 additions & 2 deletions docker-compose-dev-local-db-all-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ services:

celery_exporter:
image: danihodovic/celery-exporter:0.10.8
networks:
- prod-net
secrets:
- redis_pass
- redis_host
Expand Down
10 changes: 9 additions & 1 deletion webclient/core/repository_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from xml_generator.generator import DocumentGenerator
from xml_generator.models import ModelWithMetadata

from redis import ResponseError

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -1336,7 +1338,13 @@ def _send_transaction_request(self, operation=FedoraTransactionOperation.COMMIT)
auth = HTTPBasicAuth(settings.FEDORA_ADMIN_USER, settings.FEDORA_ADMIN_USER_PASSWORD)
if operation == FedoraTransactionOperation.COMMIT:
response = requests.put(url, auth=auth, verify=False)
self._save_transaction_result_to_redis(FedoraTransactionResult.COMMITED)
try:
self._save_transaction_result_to_redis(FedoraTransactionResult.COMMITED)
except ResponseError as err:
logger.error(
"core_repository_connector.FedoraTransaction._save_transaction_result_to_redis.failed",
extra={"transaction": self.uid, "err": err},
)
elif operation == FedoraTransactionOperation.ROLLBACK:
response = requests.delete(url, auth=auth, verify=False)
self._save_transaction_result_to_redis(FedoraTransactionResult.ABORTED)
Expand Down
9 changes: 9 additions & 0 deletions webclient/core/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
logger = logging.getLogger(__name__)


orcid_pattern = re.compile(r"\d{4}-\d{4}-\d{4}-\d{4}")


def validate_phone_number(number):
"""
Validátor pro ověření telefonního čísla na správny formát.
Expand Down Expand Up @@ -37,3 +40,9 @@ def validate_date_min_1600(value):
raise ValidationError(_("core.validators.validate_date_min_1600.not_valid_upper"))
elif value and value <= min_date:
raise ValidationError(_("core.validators.validate_date_min_1600.not_valid"))


def validate_orcid(orcid):
match = orcid_pattern.search(orcid)
if not match:
raise ValidationError(_("core.validators.validate_orcid.not_valid"))
9 changes: 5 additions & 4 deletions webclient/ez/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ class Meta:

def clean_doi(self):
doi = self.cleaned_data["doi"]
match = re.search(r"10\.\d{4,9}\/[-._;()/:a-zA-Z0-9]+", doi)
if not match:
raise ValidationError(_("ez.forms.externiZdrojForm.doi.error"))
doi = match.group()
if doi:
match = re.search(r"10\.\d{4,9}\/[-._;()/:a-zA-Z0-9]+", doi)
if not match:
raise ValidationError(_("ez.forms.externiZdrojForm.doi.error"))
doi = match.group()
return doi

def __init__(self, *args, required=None, required_next=None, readonly=False, **kwargs):
Expand Down
12 changes: 11 additions & 1 deletion webclient/uzivatel/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class CustomUserAdmin(DjangoObjectActions, UserAdmin):
"last_name",
"telefon",
"osoba",
"orcid",
"groups",
)
},
Expand All @@ -206,12 +207,21 @@ class CustomUserAdmin(DjangoObjectActions, UserAdmin):
"last_name",
"telefon",
"osoba",
"orcid",
"groups",
),
},
),
)
search_fields = ("email", "organizace__nazev_zkraceny", "ident_cely", "first_name", "last_name", "telefon")
search_fields = (
"email",
"organizace__nazev_zkraceny",
"ident_cely",
"first_name",
"last_name",
"telefon",
"orcid",
)
ordering = ("email",)
change_actions = ("metadata",)

Expand Down
29 changes: 27 additions & 2 deletions webclient/uzivatel/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from core.validators import validate_phone_number
from core.validators import validate_orcid, validate_phone_number
from core.widgets import ForeignKeyReadOnlyTextInput
from crispy_forms.bootstrap import AppendedText
from crispy_forms.helper import FormHelper
Expand Down Expand Up @@ -31,6 +31,13 @@ class AuthUserCreationForm(RegistrationForm):
Formulář pro vytvoření uživatele.
"""

orcid = forms.CharField(
validators=[validate_orcid],
help_text=_("uzivatel.forms.AuthUserCreationForm.orcid.tooltip"),
label=_("uzivatel.forms.AuthUserCreationForm.orcid.label"),
widget=forms.TextInput(),
)

class Meta(RegistrationForm):
model = User
fields = (
Expand All @@ -39,6 +46,7 @@ class Meta(RegistrationForm):
"email",
"telefon",
"organizace",
"orcid",
"password1",
"password2",
)
Expand Down Expand Up @@ -79,6 +87,7 @@ def __init__(self, *args, **kwargs):
Field("email"),
Field("telefon"),
Field("organizace"),
Field("orcid"),
AppendedText(
"password1",
mark_safe('<i class="bi bi-eye-slash" id="togglePassword1"></i>'),
Expand Down Expand Up @@ -122,9 +131,16 @@ class AuthUserChangeForm(forms.ModelForm):
Formulář pro editaci uživatele.
"""

orcid = forms.CharField(
validators=[validate_orcid],
help_text=_("uzivatel.forms.AuthUserChangeForm.orcid.tooltip"),
label=_("uzivatel.forms.AuthUserChangeForm.orcid.label"),
widget=forms.TextInput(),
)

class Meta:
model = User
fields = ("telefon",)
fields = ("telefon", "orcid")
labels = {
"telefon": _("uzivatel.forms.userChange.telefon.label"),
}
Expand All @@ -143,6 +159,7 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
Div(
Div("telefon", css_class="col-sm-3"),
Div("orcid", css_class="col-sm-3"),
css_class="row",
)
)
Expand Down Expand Up @@ -376,6 +393,14 @@ class OsobaForm(forms.ModelForm):
Formulář pro vytvoření osoby.
"""

orcid = forms.CharField(
validators=[validate_orcid],
help_text=_("uzivatel.forms.OsobaForm.orcid.tooltip"),
label=_("uzivatel.forms.OsobaForm.orcid.label"),
widget=forms.TextInput(),
required=False,
)

class Meta:
model = Osoba
fields = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ class Migration(migrations.Migration):
name="wikidata",
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name="user",
name="orcid",
field=models.CharField(blank=True, max_length=255, null=True),
),
]
1 change: 1 addition & 0 deletions webclient/uzivatel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class User(ExportModelOperationsMixin("user"), AbstractBaseUser, PermissionsMixi
limit_choices_to={"ident_cely__icontains": "S-E-"},
default=only_notification_groups,
)
orcid = models.CharField(max_length=255, blank=True, null=True)

USERNAME_FIELD = "email"
REQUIRED_FIELDS = []
Expand Down
7 changes: 5 additions & 2 deletions webclient/uzivatel/signals.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
import re

from cacheops import invalidate_model
from core.ident_cely import get_uzivatel_ident
from core.repository_connector import FedoraRepositoryConnector, FedoraTransaction
from core.validators import orcid_pattern
from django.contrib.auth import user_logged_in
from django.contrib.auth.hashers import check_password
from django.core.exceptions import ObjectDoesNotExist, ValidationError
Expand Down Expand Up @@ -35,7 +35,7 @@ def orgnaizace_save_metadata(sender, instance: Organizace, **kwargs):
@receiver(pre_save, sender=Osoba, weak=False)
def osoba_pre_save(sender, instance: Osoba, **kwargs):
if instance.orcid:
match = re.search(r"\d{4}-\d{4}-\d{4}-\d{4}", instance.orcid)
match = orcid_pattern.search(instance.orcid)
instance.orcid = match.group() if match else None
if instance.wikidata and "/" in instance.wikidata:
instance.wikidata = instance.wikidata.split("/")[-1]
Expand Down Expand Up @@ -66,6 +66,9 @@ def create_ident_cely(sender, instance: User, **kwargs):
instance.old = database_user_query.first()
else:
instance.old = None
if instance.orcid:
match = orcid_pattern.search(instance.orcid)
instance.orcid = match.group() if match else None
if instance.pk is None:
instance.model_is_updated = False
logger.debug("uzivatel.signals.create_ident_cely.running_create_ident_cely_receiver")
Expand Down
5 changes: 4 additions & 1 deletion webclient/uzivatel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ def post(self, request, *args, **kwargs):
request_data = dict(request.POST)
logger.debug("uzivatel.views.UserAccountUpdateView.post.start", extra={"request_data": request_data})
form = self.form_class(data=request.POST, instance=self.request.user)
has_changed = request.POST.get("telefon") != self.request.user.telefon
has_changed = (
request.POST.get("telefon") != self.request.user.telefon
or request.POST.get("orcid") != self.request.user.orcid
)
if form.is_valid() and has_changed:
obj = form.save(commit=False)
obj: User
Expand Down
1 change: 1 addition & 0 deletions webclient/xml_generator/definitions/amcr.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<xs:element name="prijmeni" minOccurs="1" maxOccurs="1" type="xs:string"/> <!-- "{last_name}" -->
<xs:element name="email" minOccurs="1" maxOccurs="1" type="xs:string"/> <!-- "{email}" -->
<xs:element name="osoba" minOccurs="0" maxOccurs="1" type="amcr:refType"/> <!-- "{osoba.ident_cely}" | "{osoba.vypis_cely}" -->
<xs:element name="orcid" minOccurs="0" maxOccurs="1" type="xs:string"/> <!-- "{orcid}" -->
<xs:element name="organizace" minOccurs="1" maxOccurs="1" type="amcr:vocabType"/> <!-- "{organizace.ident_cely}" | "{organizace.nazev}" -->
<xs:element name="jazyk" minOccurs="0" maxOccurs="1" type="xs:string"/> <!-- "{jazyk}" -->
<xs:element name="telefon" minOccurs="0" maxOccurs="1" type="xs:string"/> <!-- "{telefon}" -->
Expand Down

0 comments on commit 1a07d93

Please sign in to comment.