Browse Source

Allow project to accept blank guideline

pull/1230/head
Hironsan 3 years ago
parent
commit
1726885070
2 changed files with 57 additions and 39 deletions
  1. 18
      app/api/migrations/0008_auto_20210302_1013.py
  2. 78
      app/api/models.py

18
app/api/migrations/0008_auto_20210302_1013.py

@ -0,0 +1,18 @@
# Generated by Django 3.1.6 on 2021-03-02 10:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0007_auto_20210301_0302'),
]
operations = [
migrations.AlterField(
model_name='project',
name='guideline',
field=models.TextField(blank=True, default=''),
),
]

78
app/api/models.py

@ -28,7 +28,7 @@ PROJECT_CHOICES = (
class Project(PolymorphicModel):
name = models.CharField(max_length=100)
description = models.TextField(default='')
guideline = models.TextField(default='')
guideline = models.TextField(default='', blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
users = models.ManyToManyField(User, related_name='projects')
@ -312,44 +312,44 @@ class RoleMapping(models.Model):
unique_together = ("user", "project")
@receiver(post_save, sender=RoleMapping)
def add_linked_project(sender, instance, created, **kwargs):
if not created:
return
userInstance = instance.user
projectInstance = instance.project
if userInstance and projectInstance:
user = User.objects.get(pk=userInstance.pk)
project = Project.objects.get(pk=projectInstance.pk)
user.projects.add(project)
user.save()
@receiver(post_save)
def add_superusers_to_project(sender, instance, created, **kwargs):
if not created:
return
if sender not in Project.__subclasses__():
return
superusers = User.objects.filter(is_superuser=True)
admin_role = Role.objects.filter(name=settings.ROLE_PROJECT_ADMIN).first()
if superusers and admin_role:
RoleMapping.objects.bulk_create(
[RoleMapping(role_id=admin_role.id, user_id=superuser.id, project_id=instance.id)
for superuser in superusers]
)
@receiver(post_save, sender=User)
def add_new_superuser_to_projects(sender, instance, created, **kwargs):
if created and instance.is_superuser:
admin_role = Role.objects.filter(name=settings.ROLE_PROJECT_ADMIN).first()
projects = Project.objects.all()
if admin_role and projects:
RoleMapping.objects.bulk_create(
[RoleMapping(role_id=admin_role.id, user_id=instance.id, project_id=project.id)
for project in projects]
)
# @receiver(post_save, sender=RoleMapping)
# def add_linked_project(sender, instance, created, **kwargs):
# if not created:
# return
# userInstance = instance.user
# projectInstance = instance.project
# if userInstance and projectInstance:
# user = User.objects.get(pk=userInstance.pk)
# project = Project.objects.get(pk=projectInstance.pk)
# user.projects.add(project)
# user.save()
#
#
# @receiver(post_save)
# def add_superusers_to_project(sender, instance, created, **kwargs):
# if not created:
# return
# if sender not in Project.__subclasses__():
# return
# superusers = User.objects.filter(is_superuser=True)
# admin_role = Role.objects.filter(name=settings.ROLE_PROJECT_ADMIN).first()
# if superusers and admin_role:
# RoleMapping.objects.bulk_create(
# [RoleMapping(role_id=admin_role.id, user_id=superuser.id, project_id=instance.id)
# for superuser in superusers]
# )
#
#
# @receiver(post_save, sender=User)
# def add_new_superuser_to_projects(sender, instance, created, **kwargs):
# if created and instance.is_superuser:
# admin_role = Role.objects.filter(name=settings.ROLE_PROJECT_ADMIN).first()
# projects = Project.objects.all()
# if admin_role and projects:
# RoleMapping.objects.bulk_create(
# [RoleMapping(role_id=admin_role.id, user_id=instance.id, project_id=project.id)
# for project in projects]
# )
@receiver(pre_delete, sender=RoleMapping)

Loading…
Cancel
Save