add groups to collections, edits and lists, towards #3063
This commit is contained in:
parent
15c5ad9d54
commit
85c5fafe0d
8 changed files with 143 additions and 19 deletions
21
pandora/edit/migrations/0004_edit_groups.py
Normal file
21
pandora/edit/migrations/0004_edit_groups.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.2 on 2017-12-31 12:33
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0008_auto_20171231_1233'),
|
||||
('edit', '0003_auto_20170415_1029'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='edit',
|
||||
name='groups',
|
||||
field=models.ManyToManyField(blank=True, related_name='edits', to='auth.Group'),
|
||||
),
|
||||
]
|
||||
|
|
@ -15,7 +15,7 @@ from oxdjango.fields import DictField, TupleField
|
|||
from django.conf import settings
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Max
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
from annotation.models import Annotation
|
||||
|
|
@ -24,6 +24,7 @@ from item.utils import get_by_id
|
|||
import clip.models
|
||||
|
||||
from archive import extract
|
||||
from user.utils import update_groups
|
||||
|
||||
from . import managers
|
||||
|
||||
|
|
@ -41,6 +42,7 @@ class Edit(models.Model):
|
|||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
user = models.ForeignKey(User, related_name='edits')
|
||||
groups = models.ManyToManyField(Group, blank=True, related_name='edits')
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
status = models.CharField(max_length=20, default='private')
|
||||
|
|
@ -134,12 +136,16 @@ class Edit(models.Model):
|
|||
if not user or user.is_anonymous():
|
||||
return False
|
||||
if self.user == user or \
|
||||
self.groups.filter(id__in=user.groups.all()).count() > 0 or \
|
||||
user.is_staff or \
|
||||
user.profile.capability('canEditFeaturedEdits'):
|
||||
return True
|
||||
return False
|
||||
|
||||
def edit(self, data, user):
|
||||
if 'groups' in data:
|
||||
groups = data.pop('groups')
|
||||
update_groups(self, groups)
|
||||
for key in data:
|
||||
if key == 'status':
|
||||
value = data[key]
|
||||
|
|
@ -344,6 +350,8 @@ class Edit(models.Model):
|
|||
'description',
|
||||
'duration',
|
||||
'editable',
|
||||
'editable',
|
||||
'groups',
|
||||
'id',
|
||||
'items',
|
||||
'name',
|
||||
|
|
@ -387,6 +395,8 @@ class Edit(models.Model):
|
|||
response[key] = self.editable(user)
|
||||
elif key == 'user':
|
||||
response[key] = self.user.username
|
||||
elif key == 'groups':
|
||||
response[key] = [g.name for g in self.groups.all()]
|
||||
elif key == 'subscribers':
|
||||
response[key] = self.subscribed_users.all().count()
|
||||
elif key == 'subscribed':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue