-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/ProjetSigma/backend into …
…feature/improve_groups Conflicts: sigma/urls.py sigma_core/models/group.py sigma_core/models/user.py sigma_core/tests/factories.py
- Loading branch information
Showing
18 changed files
with
540 additions
and
27 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-01-26 13:41 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0009_auto_20160111_0057'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='School', | ||
fields=[ | ||
('group_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='sigma_core.Group')), | ||
('design', models.CharField(max_length=255)), | ||
], | ||
bases=('sigma_core.group',), | ||
), | ||
] |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-01-27 14:24 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0010_school'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SchoolGroup', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('validated', models.BooleanField(default=False)), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('updated', models.DateTimeField(auto_now=True)), | ||
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='group_schools', to='sigma_core.Group')), | ||
('school', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='school_groups', to='sigma_core.School')), | ||
], | ||
), | ||
] |
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,51 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-01-27 17:48 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0011_schoolgroup'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GroupAcknowledgment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('validated', models.BooleanField(default=False)), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('updated', models.DateTimeField(auto_now=True)), | ||
], | ||
), | ||
migrations.RemoveField( | ||
model_name='schoolgroup', | ||
name='group', | ||
), | ||
migrations.RemoveField( | ||
model_name='schoolgroup', | ||
name='school', | ||
), | ||
migrations.AddField( | ||
model_name='group', | ||
name='resp_school', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='sigma_core.School'), | ||
), | ||
migrations.DeleteModel( | ||
name='SchoolGroup', | ||
), | ||
migrations.AddField( | ||
model_name='groupacknowledgment', | ||
name='asking_group', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='group_recognizers', to='sigma_core.Group'), | ||
), | ||
migrations.AddField( | ||
model_name='groupacknowledgment', | ||
name='validator_group', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='group_acknowledgments', to='sigma_core.Group'), | ||
), | ||
] |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-02-01 10:08 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0012_auto_20160127_1848'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='groupacknowledgment', | ||
name='parent_group', | ||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='subgroups', to='sigma_core.Group'), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='groupacknowledgment', | ||
name='subgroup', | ||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='group_parents', to='sigma_core.Group'), | ||
preserve_default=False, | ||
), | ||
] |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-02-01 10:09 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
def move_foreignkeys(apps, schema_editor): | ||
GroupAcknowledgment = apps.get_model("sigma_core", "GroupAcknowledgment") | ||
for ga in GroupAcknowledgment.objects.all(): | ||
ga.subgroup = ga.asking_group | ||
ga.parent_group = ga.validator_group | ||
ga.save() | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0013_auto_20160201_1108'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(move_foreignkeys), | ||
] |
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 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-02-01 10:09 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0014_auto_20160201_1109'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='groupacknowledgment', | ||
name='asking_group', | ||
), | ||
migrations.RemoveField( | ||
model_name='groupacknowledgment', | ||
name='validator_group', | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from django.db import models | ||
|
||
from dry_rest_permissions.generics import allow_staff_or_superuser | ||
|
||
from sigma_core.models.group import Group | ||
|
||
|
||
class School(Group): | ||
design = models.CharField(max_length=255) | ||
|
||
def save(self, *args, **kwargs): | ||
""" | ||
Schools are special groups: some params cannot be specified by user. | ||
""" | ||
self.visibility = Group.VIS_PUBLIC | ||
self.type = Group.TYPE_SCHOOL | ||
self.default_member_rank = -1 | ||
self.req_rank_invite = Group.ADMINISTRATOR_RANK | ||
self.req_rank_kick = Group.ADMINISTRATOR_RANK | ||
self.req_rank_accept_join_requests = Group.ADMINISTRATOR_RANK | ||
self.req_rank_promote = Group.ADMINISTRATOR_RANK | ||
self.req_rank_demote = Group.ADMINISTRATOR_RANK | ||
self.req_rank_modify_group_infos = Group.ADMINISTRATOR_RANK | ||
self.resp_school = None | ||
|
||
return super(School, self).save(*args, **kwargs) | ||
|
||
# Permissions | ||
@staticmethod | ||
def has_read_permission(request): | ||
""" | ||
Schools list is visible by everybody. | ||
""" | ||
return True | ||
|
||
def has_object_read_permission(self, request): | ||
""" | ||
Schools are only visible by members. | ||
""" | ||
return request.user.is_group_member(self) | ||
|
||
@staticmethod | ||
@allow_staff_or_superuser | ||
def has_create_permission(request): | ||
""" | ||
Schools can be created by Sigma admin only. | ||
""" | ||
return False |
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.