-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
linkin
committed
Nov 17, 2024
1 parent
eba2f1f
commit edb0435
Showing
24 changed files
with
274 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import api from "../api"; | ||
|
||
export default class GroupService { | ||
static async getAllUsersGroups() { | ||
const response = await api.get("/api/groups/"); | ||
return response; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react"; | ||
import cl from "./Modal.module.css"; | ||
|
||
const Modal = ({ children, visible, setVisible }) => { | ||
const rootClasses = [cl.myModal]; | ||
|
||
if (visible) { | ||
rootClasses.push(cl.active); | ||
} | ||
|
||
return ( | ||
<div className={rootClasses.join(" ")} onClick={() => setVisible(false)}> | ||
<div className={cl.myModalContent} onClick={(e) => e.stopPropagation()}> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Modal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.myModal { | ||
position: fixed; | ||
top: 0; | ||
bottom: 0; | ||
right: 0; | ||
left: 0; | ||
display: none; | ||
background: rgba(0, 0, 0, 0.5); | ||
} | ||
|
||
.myModalContent { | ||
padding: 25px; | ||
background: white; | ||
border-radius: 16px; | ||
min-width: 250px; | ||
} | ||
|
||
.myModal.active { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
justhink_server/justhink/core/migrations/0003_alter_user_options_user_friends.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 5.1.1 on 2024-11-16 11:42 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0002_alter_user_username"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="user", | ||
options={ | ||
"verbose_name": "пользователь", | ||
"verbose_name_plural": "пользователи", | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name="user", | ||
name="friends", | ||
field=models.ManyToManyField( | ||
blank=True, to=settings.AUTH_USER_MODEL | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import django.contrib.admin | ||
|
||
import groups.models | ||
|
||
|
||
@django.contrib.admin.register(groups.models.Group) | ||
class AdminGroup(django.contrib.admin.ModelAdmin): | ||
list_display = ( | ||
groups.models.Group.name.field.name, | ||
groups.models.Group.created_at.field.name, | ||
) | ||
|
||
|
||
__all__ = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class GroupsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "groups" | ||
verbose_name = "Группы" |
52 changes: 52 additions & 0 deletions
52
justhink_server/justhink/groups/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 5.1.1 on 2024-11-16 12:16 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Group", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"name", | ||
models.CharField( | ||
blank=True, | ||
help_text="Придумайте название", | ||
max_length=255, | ||
verbose_name="название", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
( | ||
"users", | ||
models.ManyToManyField( | ||
blank=True, | ||
related_name="user_groups", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Группа", | ||
"verbose_name_plural": "Группы", | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import django.db.models | ||
|
||
import core.models | ||
|
||
|
||
class Group(django.db.models.Model): | ||
name = django.db.models.CharField( | ||
verbose_name="название", | ||
help_text="Придумайте название", | ||
max_length=255, | ||
blank=True, | ||
) | ||
users = django.db.models.ManyToManyField( | ||
core.models.User, | ||
blank=True, | ||
related_name="user_groups", | ||
) | ||
created_at = django.db.models.DateTimeField( | ||
auto_now_add=True, | ||
) | ||
|
||
class Meta: | ||
verbose_name = "Группа" | ||
verbose_name_plural = "Группы" | ||
|
||
def __str__(self): | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class IsGroupParticipant(permissions.BasePermission): | ||
def has_object_permission(self, request, view, obj): | ||
return obj.users.filter(id=request.user.id).exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import rest_framework.serializers | ||
|
||
import groups.models | ||
|
||
|
||
class GroupSerializer(rest_framework.serializers.ModelSerializer): | ||
class Meta: | ||
model = groups.models.Group | ||
fields = (groups.models.Group.name.field.name,) | ||
|
||
def create(self, validated_data): | ||
user = self.context["request"].user | ||
group = groups.models.Group.objects.create(**validated_data) | ||
group.users.add(user) | ||
return group | ||
|
||
|
||
__all__ = [GroupSerializer] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import rest_framework.generics | ||
import rest_framework.viewsets | ||
import rest_framework.decorators | ||
import rest_framework.permissions | ||
|
||
import groups.models | ||
import groups.serializers | ||
import groups.permissions | ||
|
||
|
||
class GroupViewSet(rest_framework.viewsets.ModelViewSet): | ||
queryset = groups.models.Group.objects.all() | ||
serializer_class = groups.serializers.GroupSerializer | ||
permission_classes = [ | ||
rest_framework.permissions.IsAuthenticated, | ||
groups.permissions.IsGroupParticipant, | ||
] | ||
|
||
def get_queryset(self): | ||
return groups.models.Group.objects.filter(users=self.request.user) | ||
|
||
|
||
__all__ = [GroupViewSet] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.