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

Create table user status type 35 #427

Merged
merged 1 commit into from
Nov 13, 2024
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
6 changes: 6 additions & 0 deletions app/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .models import StackElementType
from .models import UrlType
from .models import User
from .models import UserStatusType


class UserCreationForm(DefaultUserCreationForm):
Expand Down Expand Up @@ -251,3 +252,8 @@ class SocMajorAdmin(admin.ModelAdmin):
@admin.register(UrlType)
class UrlTypeAdmin(admin.ModelAdmin):
list_display = ("name", "description")


@admin.register(UserStatusType)
class UserStatusTypeAdmin(admin.ModelAdmin):
list_display = ("name", "description")
10 changes: 10 additions & 0 deletions app/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from core.models import UrlType
from core.models import User
from core.models import UserPermission
from core.models import UserStatusType


class PracticeAreaSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -377,3 +378,12 @@ class Meta:
model = UrlType
fields = ("uuid", "name", "description")
read_only_fields = ("uuid", "created_at", "updated_at")


class UserStatusTypeSerializer(serializers.ModelSerializer):
"""Used to retrieve user_status_type info"""

class Meta:
model = UserStatusType
fields = ("uuid", "name", "description")
read_only_fields = ("uuid", "created_at", "updated_at")
4 changes: 4 additions & 0 deletions app/core/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .views import UrlTypeViewSet
from .views import UserPermissionViewSet
from .views import UserProfileAPIView
from .views import UserStatusTypeViewSet
from .views import UserViewSet

router = routers.SimpleRouter()
Expand Down Expand Up @@ -48,6 +49,9 @@
router.register(r"check-types", CheckTypeViewSet, basename="check-type")
router.register(r"soc-majors", SocMajorViewSet, basename="soc-major")
router.register(r"url-types", UrlTypeViewSet, basename="url-type")
router.register(
r"user-status-types", UserStatusTypeViewSet, basename="user-status-type"
)
urlpatterns = [
path("me/", UserProfileAPIView.as_view(), name="my_profile"),
]
Expand Down
16 changes: 16 additions & 0 deletions app/core/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from ..models import StackElementType
from ..models import UrlType
from ..models import UserPermission
from ..models import UserStatusType
from .serializers import AffiliateSerializer
from .serializers import AffiliationSerializer
from .serializers import CheckTypeSerializer
Expand All @@ -48,6 +49,7 @@
from .serializers import UrlTypeSerializer
from .serializers import UserPermissionSerializer
from .serializers import UserSerializer
from .serializers import UserStatusTypeSerializer


class UserProfileAPIView(RetrieveModelMixin, GenericAPIView):
Expand Down Expand Up @@ -390,3 +392,17 @@ class UrlTypeViewSet(viewsets.ModelViewSet):
permission_classes = [IsAuthenticated]
queryset = UrlType.objects.all()
serializer_class = UrlTypeSerializer


@extend_schema_view(
list=extend_schema(description="Return a list of all the user status types"),
create=extend_schema(description="Create a new user status type"),
retrieve=extend_schema(description="Return the details of a user status type"),
destroy=extend_schema(description="Delete a user status type"),
update=extend_schema(description="Update a user status type"),
partial_update=extend_schema(description="Patch a user status type"),
)
class UserStatusTypeViewSet(viewsets.ModelViewSet):
permission_classes = [IsAuthenticated]
queryset = UserStatusType.objects.all()
serializer_class = UserStatusTypeSerializer
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,description
1,Inactive,Member who has not checked into their project or Community of Practice for 4 weeks and does not have a timeAwayHold
2,Active,Member that is checking into meetings
3,Time Away Hold,Hold placed by the member or their leader after they have announced a temporary absence
4,Barred,Member who has been removed from the community
52 changes: 52 additions & 0 deletions app/core/migrations/0031_userstatustype_user_user_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated by Django 4.2.11 on 2024-10-31 16:06

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

dependencies = [
("core", "0030_urltype"),
]

operations = [
migrations.CreateModel(
name="UserStatusType",
fields=[
(
"uuid",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
unique=True,
),
),
(
"created_at",
models.DateTimeField(auto_now_add=True, verbose_name="Created at"),
),
(
"updated_at",
models.DateTimeField(auto_now=True, verbose_name="Updated at"),
),
("name", models.CharField(max_length=255)),
("description", models.TextField(blank=True)),
],
options={
"abstract": False,
},
),
migrations.AddField(
model_name="user",
name="user_status",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="core.userstatustype",
),
),
]
2 changes: 1 addition & 1 deletion app/core/migrations/max_migration.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0030_urltype
0031_userstatustype_user_user_status
12 changes: 11 additions & 1 deletion app/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class User(PermissionsMixin, AbstractBaseUser, AbstractBaseModel):
gmail = models.EmailField(blank=True)
preferred_email = models.EmailField(blank=True)

# user_status = models.ForeignKey(user_status_type, on_delete=models.PROTECT)
user_status = models.ForeignKey(
"UserStatusType", null=True, on_delete=models.PROTECT
)
# current_practice_area = models.ManyToManyField("PracticeArea")
# target_practice_area = models.ManyToManyField("PracticeArea")

Expand Down Expand Up @@ -451,3 +453,11 @@ class UrlType(AbstractBaseModel):

def __str__(self):
return self.name


class UserStatusType(AbstractBaseModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this model is going to be implemented, we should uncomment the one-to-many relationship here, according to the tool tip under here.

name = models.CharField(max_length=255)
description = models.TextField(blank=True)

def __str__(self):
return f"{self.name}"
8 changes: 8 additions & 0 deletions app/core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ..models import UrlType
from ..models import User
from ..models import UserPermission
from ..models import UserStatusType


@pytest.fixture
Expand Down Expand Up @@ -299,3 +300,10 @@ def url_type():
name="This is a test url type name",
description="This is a test url type description",
)


@pytest.fixture
def user_status_type():
return UserStatusType.objects.create(
name="Test User Status Type", description="Test User Status Type description"
)
11 changes: 11 additions & 0 deletions app/core/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
USER_PERMISSIONS_URL = reverse("user-permission-list")
PROJECTS_URL = reverse("project-list")
ME_URL = reverse("my_profile")
USER_STATUS_TYPES_URL = reverse("user-status-type-list")
USERS_URL = reverse("user-list")
EVENTS_URL = reverse("event-list")
PRACTICE_AREA_URL = reverse("practice-area-list")
Expand Down Expand Up @@ -419,3 +420,13 @@ def test_create_url_type(auth_client):
assert res.status_code == status.HTTP_201_CREATED
assert res.data["name"] == payload["name"]
assert res.data["description"] == payload["description"]


def test_create_user_status_type(auth_client):
payload = {
"name": "Test User Status Type",
"description": "Test User Status Type description",
}
res = auth_client.post(USER_STATUS_TYPES_URL, payload)
assert res.status_code == status.HTTP_201_CREATED
assert res.data["name"] == payload["name"]
4 changes: 4 additions & 0 deletions app/core/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,7 @@ def test_project_sdg_relationship(project):

def test_url_type(url_type):
assert str(url_type) == "This is a test url type name"


def test_user_status_type(user_status_type):
assert str(user_status_type) == "Test User Status Type"
32 changes: 32 additions & 0 deletions app/data/migrations/0008_userstatustype_seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.db import migrations

from core.models import UserStatusType


def forward(__code__, __reverse_code__):
items = [
(
1,
"Inactive",
"Member who has not checked into their project or Community of Practice for 4 weeks and does not have a timeAwayHold",
),
(2, "Active", "Member that is checking into meetings"),
(
3,
"Time Away Hold",
"Hold placed by the member or their leader after they have announced a temporary absence",
),
(4, "Barred", "Member who has been removed from the community"),
]
for uuid, name, description in items:
UserStatusType.objects.create(uuid=uuid, name=name, description=description)


def reverse(__code__, __reverse_code__):
UserStatusType.objects.all().delete()


class Migration(migrations.Migration):
dependencies = [("data", "0007_urltype_seed")]

operations = [migrations.RunPython(forward, reverse)]
2 changes: 1 addition & 1 deletion app/data/migrations/max_migration.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0007_urltype_seed
0008_userstatustype_seed