Merge pull request #1831 from emanuelschuetze/templateFixes2
Several fixes for 2.0b2
This commit is contained in:
commit
dd120bbf91
@ -1,5 +1,6 @@
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import models as dbmodels
|
from django.db import models as dbmodels
|
||||||
|
|
||||||
from ..utils.rest_api import FileField, ModelSerializer, SerializerMethodField
|
from ..utils.rest_api import FileField, ModelSerializer, SerializerMethodField
|
||||||
@ -26,6 +27,7 @@ class MediafileSerializer(ModelSerializer):
|
|||||||
"""
|
"""
|
||||||
Serializer for mediafile.models.Mediafile objects.
|
Serializer for mediafile.models.Mediafile objects.
|
||||||
"""
|
"""
|
||||||
|
media_url_prefix = SerializerMethodField()
|
||||||
filesize = SerializerMethodField()
|
filesize = SerializerMethodField()
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -42,9 +44,13 @@ class MediafileSerializer(ModelSerializer):
|
|||||||
'id',
|
'id',
|
||||||
'title',
|
'title',
|
||||||
'mediafile',
|
'mediafile',
|
||||||
|
'media_url_prefix',
|
||||||
'uploader',
|
'uploader',
|
||||||
'filesize',
|
'filesize',
|
||||||
'timestamp',)
|
'timestamp',)
|
||||||
|
|
||||||
def get_filesize(self, mediafile):
|
def get_filesize(self, mediafile):
|
||||||
return mediafile.get_filesize()
|
return mediafile.get_filesize()
|
||||||
|
|
||||||
|
def get_media_url_prefix(self, mediafile):
|
||||||
|
return settings.MEDIA_URL
|
||||||
|
@ -4,14 +4,21 @@
|
|||||||
|
|
||||||
angular.module('OpenSlidesApp.mediafiles', [])
|
angular.module('OpenSlidesApp.mediafiles', [])
|
||||||
|
|
||||||
.factory('Mediafile', ['DS', function(DS) {
|
.factory('Mediafile', [
|
||||||
|
'DS',
|
||||||
|
'jsDataModel',
|
||||||
|
function(DS, jsDataModel) {
|
||||||
|
var name = 'mediafiles/mediafile';
|
||||||
return DS.defineResource({
|
return DS.defineResource({
|
||||||
name: 'mediafiles/mediafile',
|
name: name,
|
||||||
computed: {
|
computed: {
|
||||||
is_presentable: ['filetype', function (filetype) {
|
is_presentable: ['filetype', function (filetype) {
|
||||||
var PRESENTABLE_FILE_TYPES = ['application/pdf'];
|
var PRESENTABLE_FILE_TYPES = ['application/pdf'];
|
||||||
return _.contains(PRESENTABLE_FILE_TYPES, filetype);
|
return _.contains(PRESENTABLE_FILE_TYPES, filetype);
|
||||||
}],
|
}],
|
||||||
|
mediafileUrl: [function () {
|
||||||
|
return this.media_url_prefix + this.mediafile.name;
|
||||||
|
}],
|
||||||
filename: [function () {
|
filename: [function () {
|
||||||
var filename = this.mediafile.name;
|
var filename = this.mediafile.name;
|
||||||
return /\/(.+?)$/.exec(filename)[1];
|
return /\/(.+?)$/.exec(filename)[1];
|
||||||
@ -19,9 +26,18 @@ angular.module('OpenSlidesApp.mediafiles', [])
|
|||||||
title_or_filename: ['title', 'mediafile', function (title) {
|
title_or_filename: ['title', 'mediafile', function (title) {
|
||||||
return title || this.filename;
|
return title || this.filename;
|
||||||
}]
|
}]
|
||||||
|
},
|
||||||
|
relations: {
|
||||||
|
belongsTo: {
|
||||||
|
'users/user': {
|
||||||
|
localField: 'uploader',
|
||||||
|
localKey: 'uploader_id',
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}])
|
}
|
||||||
|
])
|
||||||
|
|
||||||
.run(['Mediafile', function(Mediafile) {}]);
|
.run(['Mediafile', function(Mediafile) {}]);
|
||||||
|
|
||||||
|
@ -82,22 +82,39 @@ angular.module('OpenSlidesApp.mediafiles.site', ['ngFileUpload', 'OpenSlidesApp.
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
.controller('MediafileCreateCtrl', function($scope, $state, $timeout, Upload) {
|
.controller('MediafileCreateCtrl', [
|
||||||
|
'$scope',
|
||||||
|
'$state',
|
||||||
|
'$timeout',
|
||||||
|
'operator',
|
||||||
|
'Upload',
|
||||||
|
function($scope, $state, $timeout, operator, Upload) {
|
||||||
$scope.mediafile = {};
|
$scope.mediafile = {};
|
||||||
$scope.save = uploadFile($timeout, $scope, $state, Upload);
|
$scope.save = uploadFile($timeout, $scope, $state, operator, Upload);
|
||||||
})
|
}
|
||||||
|
])
|
||||||
|
|
||||||
.controller('MediafileUpdateCtrl', function($scope, $state, $timeout, Upload, Mediafile, mediafile) {
|
.controller('MediafileUpdateCtrl', [
|
||||||
|
'$scope',
|
||||||
|
'$state',
|
||||||
|
'$timeout',
|
||||||
|
'operator',
|
||||||
|
'Upload',
|
||||||
|
'Mediafile',
|
||||||
|
'mediafile',
|
||||||
|
function($scope, $state, $timeout, operator, Upload, Mediafile, mediafile) {
|
||||||
$scope.mediafile = mediafile;
|
$scope.mediafile = mediafile;
|
||||||
$scope.save = uploadFile($timeout, $scope, $state, Upload, mediafile);
|
$scope.save = uploadFile($timeout, $scope, $state, operator, Upload, mediafile);
|
||||||
});
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
function uploadFile($timeout, $scope, $state, Upload, mediafile) {
|
function uploadFile($timeout, $scope, $state, operator, Upload, mediafile) {
|
||||||
|
console.log(operator.user);
|
||||||
return function(file) {
|
return function(file) {
|
||||||
file.upload = Upload.upload({
|
file.upload = Upload.upload({
|
||||||
url: '/rest/mediafiles/mediafile/' + (mediafile ? mediafile.id : ''),
|
url: '/rest/mediafiles/mediafile/' + (mediafile ? mediafile.id : ''),
|
||||||
method: mediafile ? 'PUT' : 'POST',
|
method: mediafile ? 'PUT' : 'POST',
|
||||||
data: {mediafile: file.newFile, title: file.title}
|
data: {mediafile: file.newFile, title: file.title, uploader_id: operator.user.id}
|
||||||
});
|
});
|
||||||
|
|
||||||
file.upload.then(function (response) {
|
file.upload.then(function (response) {
|
||||||
|
@ -53,11 +53,11 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="mediafile in mediafiles | filter: filter.search |
|
<tr ng-repeat="mediafile in mediafiles | filter: filter.search |
|
||||||
orderBy: sortColumn:reverse">
|
orderBy: sortColumn:reverse">
|
||||||
<td><a ng-href="/media/{{ mediafile.mediafile.name }}" target="_self">{{ mediafile.title_or_filename }}</a>
|
<td><a ng-href="{{ mediafile.mediafileUrl }}" target="_blank">{{ mediafile.title_or_filename }}</a>
|
||||||
<td class="optional">{{ mediafile.mediafile.type }}
|
<td class="optional">{{ mediafile.mediafile.type }}
|
||||||
<td>{{ mediafile.filesize }}
|
<td>{{ mediafile.filesize }}
|
||||||
<td>{{ mediafile.timestamp }}
|
<td>{{ mediafile.timestamp }}
|
||||||
<td>{{ mediafile.uploader }}
|
<td>{{ mediafile.uploader.get_full_name() }}
|
||||||
<td os-perms="mediafiles.can_manage core.can_manage_projector" class="nobr">
|
<td os-perms="mediafiles.can_manage core.can_manage_projector" class="nobr">
|
||||||
<!-- projector, TODO: add link to activate slide -->
|
<!-- projector, TODO: add link to activate slide -->
|
||||||
<a href="#TODO" ng-if="mediafile.is_presentable" os-perms-lite="core.can_manage_projector"
|
<a href="#TODO" ng-if="mediafile.is_presentable" os-perms-lite="core.can_manage_projector"
|
||||||
|
@ -164,7 +164,7 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
|
|||||||
'operator',
|
'operator',
|
||||||
'Config',
|
'Config',
|
||||||
function(DS, MotionPoll, jsDataModel, gettext, operator, Config) {
|
function(DS, MotionPoll, jsDataModel, gettext, operator, Config) {
|
||||||
var name = 'motions/motion'
|
var name = 'motions/motion';
|
||||||
return DS.defineResource({
|
return DS.defineResource({
|
||||||
name: name,
|
name: name,
|
||||||
useClass: jsDataModel,
|
useClass: jsDataModel,
|
||||||
|
@ -71,11 +71,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<!-- Category -->
|
<!-- Category -->
|
||||||
<h3 translate>Category</h3>
|
<h3 ng-if="motion.category" translate>Category</h3>
|
||||||
{{ motion.category.name }}</a>
|
{{ motion.category.name }}
|
||||||
|
|
||||||
<!-- Tags -->
|
<!-- Tags -->
|
||||||
<h3 translate>Tags</h3>
|
<h3 ng-if="motion.tags.length > 0" translate>Tags</h3>
|
||||||
<span ng-repeat="tag in motion.tags">
|
<span ng-repeat="tag in motion.tags">
|
||||||
{{ tag.name }}{{$last ? '' : ', '}}
|
{{ tag.name }}{{$last ? '' : ', '}}
|
||||||
</span>
|
</span>
|
||||||
@ -100,11 +100,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<h3 translate>Voting result</h3>
|
<h3 ng-if="motion.polls.length > 0" translate>Voting result</h3>
|
||||||
<ol class="slimlist">
|
<ol class="slimlist">
|
||||||
<li ng-repeat="poll in motion.polls" class="spacer">
|
<li ng-repeat="poll in motion.polls" class="spacer">
|
||||||
<translate>Vote</translate>
|
<translate>Vote</translate>
|
||||||
<button os-perms-lite="motions.can_manage" ng-click="poll.isEditMode=true;"
|
<button os-perms="motions.can_manage" ng-click="$parent.poll.isEditMode=true;"
|
||||||
class="btn btn-default btn-xs">
|
class="btn btn-default btn-xs">
|
||||||
<i class="fa fa-pencil"></i>
|
<i class="fa fa-pencil"></i>
|
||||||
</button>
|
</button>
|
||||||
@ -163,7 +163,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div ng-show="!poll.isEditMode && poll.yes >= -2" class="pollresults">
|
<div ng-show="!poll.isEditMode" class="pollresults">
|
||||||
<!-- yes -->
|
<!-- yes -->
|
||||||
<div class="result_label">
|
<div class="result_label">
|
||||||
<i class="fa fa-thumbs-up"></i>
|
<i class="fa fa-thumbs-up"></i>
|
||||||
@ -240,16 +240,16 @@
|
|||||||
<div class="white-space-pre-line" ng-bind-html="motion.getReason()"></div>
|
<div class="white-space-pre-line" ng-bind-html="motion.getReason()"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- attachments
|
<!-- attachments -->
|
||||||
TODO: make 'motion.attachments' useable and itteratable in template
|
<h3 ng-if="motion.attachments.length > 0" translate>Attachments</h3>
|
||||||
<div ng-if="motion.attachments">
|
<ul>
|
||||||
<h3 translate>Attachments</h3>
|
<li ng-repeat="attachment in motion.attachments">
|
||||||
</div>
|
<a href="{{ attachment.mediafileUrl }}" target="_blank">{{ attachment.title_or_filename }}</a>
|
||||||
-->
|
</ul>
|
||||||
|
|
||||||
<!-- log -->
|
<!-- log -->
|
||||||
<button type="button" class="btn btn-default spacer" ng-click="isCollapsed = !isCollapsed" translate>
|
<button type="button" class="btn btn-default spacer" ng-click="isCollapsed = !isCollapsed" translate>
|
||||||
Show log
|
Show history
|
||||||
</button>
|
</button>
|
||||||
<div uib-collapse="isCollapsed">
|
<div uib-collapse="isCollapsed">
|
||||||
<div class="well well-sm">
|
<div class="well well-sm">
|
||||||
|
@ -546,7 +546,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
function($scope, $state, User, user) {
|
function($scope, $state, User, user) {
|
||||||
$scope.user = user; // autoupdate is not activated
|
$scope.user = user; // autoupdate is not activated
|
||||||
$scope.save = function (user) {
|
$scope.save = function (user) {
|
||||||
User.save(user).then(
|
User.save(user, { method: 'PATCH' }).then(
|
||||||
function(success) {
|
function(success) {
|
||||||
$state.go('users.user.list');
|
$state.go('users.user.list');
|
||||||
},
|
},
|
||||||
|
@ -37,9 +37,9 @@ class UserViewSet(ModelViewSet):
|
|||||||
"""
|
"""
|
||||||
Returns True if the user has required permissions.
|
Returns True if the user has required permissions.
|
||||||
"""
|
"""
|
||||||
if self.action in ('metadata', 'list', 'retrieve', 'partial_update'):
|
if self.action in ('metadata', 'list', 'retrieve', 'update', 'partial_update'):
|
||||||
result = self.request.user.has_perm('users.can_see_name')
|
result = self.request.user.has_perm('users.can_see_name')
|
||||||
elif self.action in ('create', 'update', 'destroy', 'reset_password'):
|
elif self.action in ('create', 'destroy', 'reset_password'):
|
||||||
result = (self.request.user.has_perm('users.can_see_name') and
|
result = (self.request.user.has_perm('users.can_see_name') and
|
||||||
self.request.user.has_perm('users.can_see_extra_data') and
|
self.request.user.has_perm('users.can_see_extra_data') and
|
||||||
self.request.user.has_perm('users.can_manage'))
|
self.request.user.has_perm('users.can_manage'))
|
||||||
@ -121,12 +121,13 @@ class UserViewSet(ModelViewSet):
|
|||||||
'title',
|
'title',
|
||||||
'first_name',
|
'first_name',
|
||||||
'last_name',
|
'last_name',
|
||||||
'structure_level'
|
'structure_level',
|
||||||
'about_me',)
|
'about_me',)
|
||||||
for data in request.data.keys():
|
keys = list(request.data.keys())
|
||||||
if data not in whitelist:
|
for key in keys:
|
||||||
# Non-staff users are allowed to send only some data.
|
if key not in whitelist:
|
||||||
self.permission_denied(request)
|
# Non-staff users are allowed to send only some data. Ignore other data.
|
||||||
|
del request.data[key]
|
||||||
# Validate data and update user.
|
# Validate data and update user.
|
||||||
serializer = self.get_serializer(
|
serializer = self.get_serializer(
|
||||||
user,
|
user,
|
||||||
|
Loading…
Reference in New Issue
Block a user