Skip to content

Commit

Permalink
Merge with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
robindymer committed Dec 6, 2023
2 parents f636f17 + 5fbd11a commit 4335bd1
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 127 deletions.
8 changes: 4 additions & 4 deletions .env-template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Make a copy of this file and rename it to .env if you are using docker. This file is only meant for development
# MELOS_URL=
# MELOS_ORG_ID=
# MELOS_ADMIN=
# UNICORE_URL=
# UNICORE_ORG_ID=
# UNICORE_ADMIN=

# GOOGLE_API_KEY=

Expand All @@ -14,4 +14,4 @@
# DJANGO_DB_USER=
# DJANGO_DB_PASS=
# DJANGO_DB_HOST=
# DJANGO_DB_PORT=
# DJANGO_DB_PORT=
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Extended createsuperuser so it gets a melos id
- Extended createsuperuser so it gets a unicore id
- Teams, roles and positions are now ordered alphabetically after their name
- Updated django-compressor to 2.4
- Updated django-libsass to 0.8
Expand Down Expand Up @@ -326,10 +326,10 @@ Exception to applications where a board member can see and modify applications f
| Applications | Full access | Board/Presidium (all teams) | Presidium (all teams) | Group Leader/Engaged | Engaged | |
| Contact Cards | Full access | Board/Presidium (all teams) | Presidium | Group Leader/Engaged | Engaged | |

- Melos is now used to fetch user-information such as name, ssn and member status.
- Registering an account requires the SSN to exist in Melos.
- Unicore is now used to fetch user-information such as name, ssn and member status.
- Registering an account requires the SSN to exist in Unicore.
- A user may now log in using both username or ssn.
- Firstname, Lastname, SSN, Registration Year and Study Program is no longer stored in Moores database and is instead fetched from Melos.
- Firstname, Lastname, SSN, Registration Year and Study Program is no longer stored in Moores database and is instead fetched from Unicore.
- Replaced Marvin to Bocken
- Upgrade dependencies

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To get started with Project Moore, follow these instructions to set up a
- libpq-dev
4. Clone the repository.
5. Copy the file `.env-template` and name the copy `.env`
6. Fill in the necessary variables in `.env`. `MELOS_URL` and `MELOS_ADMIN` are required. You might have to fill in some database credidentils. Check `src/moore/settings/base.py` for which default values are used if you don't specify and credidentials.
6. Fill in the necessary variables in `.env`. `UNICORE_URL` and `UNICORE_ADMIN` are required. You might have to fill in some database credidentils. Check `src/moore/settings/base.py` for which default values are used if you don't specify and credidentials.
7. Run `source ./source_me.sh` to create a virtual environment.
8. Run `pip install --upgrade pip` to make sure that pip is running the latest version
9. Run `pip install -r dev-requirements.txt`
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ django-jsonschema-form==1.0.3
python-decouple==3.7

# Search and select widget
django-select2==8.1.1
django-select2==8.1.1
2 changes: 1 addition & 1 deletion src/branding/locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ msgstr "Branding"

#: branding/models.py:15
msgid "footer"
msgstr ""
msgstr "sidfot"

#: branding/models.py:33
msgid "social media accounts"
Expand Down
2 changes: 1 addition & 1 deletion src/branding/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@register_setting(icon='fa-window-minimize')
class FooterSettings(BaseSetting):
class Meta:
verbose_name = _('footer_en') # quickfix
verbose_name = _('footer') # quickfix

footer_en = StreamField(
[('column', blocks.StructBlock([
Expand Down
4 changes: 2 additions & 2 deletions src/events/models/participant.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from wagtail.admin.edit_handlers import MultiFieldPanel, FieldPanel
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient


class Participant(models.Model):
Expand Down Expand Up @@ -40,7 +40,7 @@ def __str__(self):
def calculate_order_cost(self):
cost = 0
price_list = self.ticket.event.price_list
is_member = self.person_nr and MelosClient.is_member(self.person_nr)
is_member = self.person_nr and UnicoreClient.is_member(self.person_nr)

if is_member:
cost += self.ticket.event.price_per_participant
Expand Down
4 changes: 2 additions & 2 deletions src/events/views/ticket_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from events.models import Event, Ticket, Participant
from events.forms import ParticipantForm
from django.contrib.auth.decorators import login_required
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient


@login_required
Expand Down Expand Up @@ -76,7 +76,7 @@ def my_ticket(request, event_pk):

# Set this as the first user has to be the owner.
formset[0].fields['person_nr'].disabled = True
owner_is_member = MelosClient.is_member(ticket.owner.person_nr)
owner_is_member = UnicoreClient.is_member(ticket.owner.person_nr)
base_price = event.base_price if owner_is_member \
else event.base_price_nonmember
cost = base_price + \
Expand Down
12 changes: 6 additions & 6 deletions src/involvement/forms/appointment_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.utils.translation import gettext_lazy as _
from involvement.models import Application
from utils.forms import AdvancedModelMultipleChoiceField
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient
from involvement import cron


Expand Down Expand Up @@ -40,17 +40,17 @@ def clean_overturn(self):
pnrs = string.split(',')
users = []
for pnr in pnrs:
melos_id = MelosClient.get_melos_id(pnr)
unicore_id = UnicoreClient.get_unicore_id(pnr)

if not get_user_model().objects.filter(
melos_id=melos_id
).exists() or melos_id is False:
unicore_id=unicore_id
).exists() or unicore_id is False:
raise forms.ValidationError(
_('No user with the person number %(pnr)s exists.'),
params={'pnr': pnr},
)
elif self.position.applications.filter(
applicant__melos_id=melos_id,
applicant__unicore_id=unicore_id,
).exclude(
status='draft'
).exists():
Expand All @@ -62,7 +62,7 @@ def clean_overturn(self):
)
else:
users.append(get_user_model().objects.filter(
melos_id=melos_id
unicore_id=unicore_id
).first())
return users

Expand Down
2 changes: 1 addition & 1 deletion src/involvement/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create_test_user():
user_data['password'] = 'password'
user_data[user_model.EMAIL_FIELD] = "[email protected]"
user_data['phone_number'] = "0733221121"
user_data['melos_id'] = 8631280
user_data['unicore_id'] = 8631280

user_model.objects.create_superuser(**user_data)

Expand Down
2 changes: 1 addition & 1 deletion src/involvement/views/view_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def view_position(request, context, page, position=None):

# Load application form if user is logged in
if request.user.is_authenticated:
if request.user.melos_id:
if request.user.unicore_id:
context['membership_status'] = request.user.get_status
context['email'] = request.user.get_email
context['phone'] = request.user.get_phone_formatted
Expand Down
2 changes: 1 addition & 1 deletion src/members/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# There is now good way for bulk updates and
# without bulk update we will need to make at least 2 requests against melos to
# without bulk update we'll need to make at least 2 requests against unicore to
# update one single member. To reduce the amounts of requests,
# we will only update status for active members e.g the ones that has
# status="member" as this value is updated when you log in to your account.
Expand Down
27 changes: 15 additions & 12 deletions src/members/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.utils.http import urlsafe_base64_encode

from members.models import StudyProgram, Member, Section
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient
from members.fields import PhoneNumberField, PersonNumberField

User = get_user_model()
Expand Down Expand Up @@ -66,11 +66,11 @@ def clean_username(self):
def clean_person_number(self):
person_number = self.cleaned_data['person_number']
if self.instance.pk is None:
melos_id = MelosClient.get_melos_id(person_number)
if not melos_id or Member.find_by_melos_id(melos_id):
unicore_id = UnicoreClient.get_unicore_id(person_number)
if not unicore_id or Member.find_by_unicore_id(unicore_id):
raise forms.ValidationError(_("Incorrect SSN"))

self.instance.melos_id = melos_id
self.instance.unicore_id = unicore_id

return person_number

Expand Down Expand Up @@ -98,13 +98,16 @@ class Meta:
field_classes = {'username': auth.UsernameField}

def save(self):
melos_id = MelosClient.get_melos_id(self.cleaned_data['person_number'])
unicore_id = UnicoreClient.get_unicore_id(
self.cleaned_data['person_number']
)

return Member.objects.create_user(
self.cleaned_data['username'],
self.cleaned_data['password1'],
self.cleaned_data['email'],
self.cleaned_data['phone_number'],
melos_id,
unicore_id,
section=self.cleaned_data['section']
)

Expand All @@ -116,8 +119,8 @@ class CustomPasswordResetForm(forms.Form):
help_text=_('Person number using the YYYYMMDD-XXXX format.'),
)

def get_email(self, melos_id):
member = Member.find_by_melos_id(melos_id)
def get_email(self, unicore_id):
member = Member.find_by_unicore_id(unicore_id)
if member:
return member.get_email
return ''
Expand Down Expand Up @@ -447,11 +450,11 @@ def __init__(self, *args, **kwargs):

def clean_person_number(self):
person_number = self.cleaned_data['person_number']
melos_id = MelosClient.get_melos_id(person_number)
if not melos_id or Member.find_by_melos_id(melos_id):
unicore_id = UnicoreClient.get_unicore_id(person_number)
if not unicore_id or Member.find_by_unicore_id(unicore_id):
raise forms.ValidationError(_("Incorrect SSN"))

self.instance.melos_id = melos_id
self.instance.unicore_id = unicore_id
return person_number

def save(self):
Expand All @@ -460,7 +463,7 @@ def save(self):
"password": self.cleaned_data["password1"],
"email": self.cleaned_data["email"],
"phone_number": self.cleaned_data["phone_number"],
"melos_id": self.instance.melos_id,
"unicore_id": self.instance.unicore_id,
'study': self.cleaned_data['study'],
"section": self.cleaned_data["section"],
"registration_year": self.cleaned_data["registration_year"]
Expand Down
16 changes: 8 additions & 8 deletions src/members/management/commands/createsuperuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ class Command(createsuperuser.Command):
def get_input_data(self, field, message, default=None):
"""
Extends get_input_data from the build in createsuperuser
so that we can get a melos id for the superuser to be
so that we can get a unicore id for the superuser to be
created.
"""
if field.name == "melos_id":
melos_id = None
while melos_id is None:
if field.name == "unicore_id":
unicore_id = None
while unicore_id is None:
ssn = input("Personnummer: ")
found_user, found_melos_id = Member.find_by_ssn(ssn)
found_user, found_unicore_id = Member.find_by_ssn(ssn)
if found_user is None:
melos_id = found_melos_id
unicore_id = found_unicore_id
else:
self.stderr.write(
"An account with that personnummer already exists"
)
melos_id = None
unicore_id = None

return melos_id
return unicore_id
else:
return super().get_input_data(field, message, default)
2 changes: 1 addition & 1 deletion src/members/migrations/0007_member_melos_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ class Migration(migrations.Migration):
name='status',
field=models.CharField(blank=True, null=True, default='', max_length=130),
),
]
]
4 changes: 2 additions & 2 deletions src/members/migrations/0008_auto_20191203_1447.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Migration(migrations.Migration):
migrations.AlterModelManagers(
name='member',
managers=[
('objects', members.models.member.MelosUserManager()),
('objects', members.models.member.UnicoreUserManager()),
],
),
migrations.AlterField(
Expand Down Expand Up @@ -48,4 +48,4 @@ class Migration(migrations.Migration):
name='status',
field=models.CharField(choices=[('unknown', 'Unknown'), ('nonmember', 'Nonmember'), ('member', 'Member'), ('alumnus', 'Alumnus')], default='unknown', max_length=20, verbose_name='Membership status'),
),
]
]
2 changes: 1 addition & 1 deletion src/members/migrations/0009_auto_20191206_1435.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class Migration(migrations.Migration):
name='melos_id',
field=models.IntegerField(blank=True, editable=False, null=True, unique=True),
),
]
]
6 changes: 3 additions & 3 deletions src/members/migrations/0013_auto_20201217_1503.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.db import migrations
from django.db.models import Q
from utils.melos_client import MelosClient
from utils.unicore_client import UnicoreClient

# This is a copy of the function used to get the melos
# data for a member. The reason it is copied is that django migrations
Expand All @@ -11,7 +11,7 @@
# makes sure that this migration file will work in the future, regardless
# of the changes to the Member model
def fetch_and_save_melos_info(melos_id):
melos_data = MelosClient.get_user_data(melos_id)
melos_data = UnicoreClient.get_user_data(melos_id)
if melos_data is not None:
name = "{} {}".format(
melos_data['first_name'].strip(),
Expand Down Expand Up @@ -56,4 +56,4 @@ class Migration(migrations.Migration):
get_user_info,
reverse_code=migrations.RunPython.noop
)
]
]
18 changes: 18 additions & 0 deletions src/members/migrations/0015_rename_melos_id_member_unicore_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.17 on 2023-11-08 18:27

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('members', '0014_auto_20201217_1522'),
]

operations = [
migrations.RenameField(
model_name='member',
old_name='melos_id',
new_name='unicore_id',
),
]
Loading

0 comments on commit 4335bd1

Please sign in to comment.