diff --git a/openslides/mediafiles/access_permissions.py b/openslides/mediafiles/access_permissions.py index 7a87aa2fc..948b807c3 100644 --- a/openslides/mediafiles/access_permissions.py +++ b/openslides/mediafiles/access_permissions.py @@ -18,3 +18,14 @@ class MediafileAccessPermissions(BaseAccessPermissions): from .serializers import MediafileSerializer return MediafileSerializer + + def get_restricted_data(self, full_data, user): + """ + Returns the restricted serialized data for the instance prepared + for the user. + """ + if (not full_data['private'] or user.has_perm('mediafiles.can_see_private')): + data = full_data + else: + data = None + return data diff --git a/openslides/mediafiles/migrations/0002_mediafile_private.py b/openslides/mediafiles/migrations/0002_mediafile_private.py new file mode 100644 index 000000000..213aa8d4e --- /dev/null +++ b/openslides/mediafiles/migrations/0002_mediafile_private.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-14 12:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mediafiles', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='mediafile', + name='private', + field=models.BooleanField(default=False), + ), + ] diff --git a/openslides/mediafiles/migrations/0003_auto_20160514_1347.py b/openslides/mediafiles/migrations/0003_auto_20160514_1347.py new file mode 100644 index 000000000..82d4a0d9a --- /dev/null +++ b/openslides/mediafiles/migrations/0003_auto_20160514_1347.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.6 on 2016-05-14 13:47 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('mediafiles', '0002_mediafile_private'), + ] + + operations = [ + migrations.AlterModelOptions( + name='mediafile', + options={ + 'default_permissions': (), + 'ordering': ['title'], + 'permissions': ( + ('can_see', 'Can see the list of files'), + ('can_see_private', 'Can see private files'), + ('can_upload', 'Can upload files'), + ('can_manage', 'Can manage files'))}, + ), + ] diff --git a/openslides/mediafiles/models.py b/openslides/mediafiles/models.py index 037c717b3..5a664288e 100644 --- a/openslides/mediafiles/models.py +++ b/openslides/mediafiles/models.py @@ -30,6 +30,9 @@ class Mediafile(RESTModelMixin, models.Model): blank=True) """A user – the uploader of a file.""" + private = models.BooleanField(default=False) + """Whether or not this mediafile should be listed as private""" + timestamp = models.DateTimeField(auto_now_add=True) """A DateTimeField to save the upload date and time.""" @@ -41,6 +44,7 @@ class Mediafile(RESTModelMixin, models.Model): default_permissions = () permissions = ( ('can_see', 'Can see the list of files'), + ('can_see_private', 'Can see private files'), ('can_upload', 'Can upload files'), ('can_manage', 'Can manage files')) diff --git a/openslides/mediafiles/serializers.py b/openslides/mediafiles/serializers.py index 320e66acb..368404485 100644 --- a/openslides/mediafiles/serializers.py +++ b/openslides/mediafiles/serializers.py @@ -58,6 +58,7 @@ class MediafileSerializer(ModelSerializer): 'media_url_prefix', 'uploader', 'filesize', + 'private', 'timestamp',) def get_filesize(self, mediafile): diff --git a/openslides/mediafiles/static/js/mediafiles/site.js b/openslides/mediafiles/static/js/mediafiles/site.js index 4254028ec..f115dacbf 100644 --- a/openslides/mediafiles/static/js/mediafiles/site.js +++ b/openslides/mediafiles/static/js/mediafiles/site.js @@ -331,12 +331,27 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp. return Upload.upload({ url: '/rest/mediafiles/mediafile/', method: 'POST', - data: {mediafile: mediafile.newFile, title: mediafile.title, uploader_id: mediafile.uploader_id} + data: {mediafile: mediafile.newFile, title: mediafile.title, uploader_id: mediafile.uploader_id, private: mediafile.private} }); } }; } +]) + +.filter('privateFilter', [ + '$filter', + 'operator', + function ($filter, operator) { + return function (array) { + if (operator.hasPerms('mediafiles.can_see_private')) { + return array; + } + return Array.prototype.filter.call(array, function (item) { + return !item.private; + }); + }; + } ]); }()); diff --git a/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html b/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html index 2c4e9404a..5dabbdb24 100644 --- a/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html +++ b/openslides/mediafiles/static/templates/mediafiles/mediafile-form.html @@ -21,6 +21,13 @@ + +
+ +
+
diff --git a/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html b/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html index 7ac7a156b..8b45e19c1 100644 --- a/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html +++ b/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html @@ -155,8 +155,8 @@ - @@ -177,6 +177,7 @@ {{ mediafile.title_or_filename }}
{{ mediafile.filetype }}
{{ mediafile.filesize }} +
Private
Edit |