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