Merge pull request #1901 from emanuelschuetze/fix1895

Translate permission strings. (Fixes #1895)
This commit is contained in:
Norman Jäckel 2016-01-27 20:42:07 +01:00
commit 352e32334e
11 changed files with 88 additions and 43 deletions

View File

@ -7,7 +7,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models, transaction from django.db import models, transaction
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy, ugettext_noop from django.utils.translation import ugettext_lazy
from openslides.core.config import config from openslides.core.config import config
from openslides.core.projector import Countdown from openslides.core.projector import Countdown
@ -266,9 +266,9 @@ class Item(RESTModelMixin, models.Model):
class Meta: class Meta:
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_see', ugettext_noop("Can see agenda")), ('can_see', 'Can see agenda'),
('can_manage', ugettext_noop("Can manage agenda")), ('can_manage', 'Can manage agenda'),
('can_see_hidden_items', ugettext_noop("Can see hidden items and time scheduling of agenda"))) ('can_see_hidden_items', 'Can see hidden items and time scheduling of agenda'))
unique_together = ('content_type', 'object_id') unique_together = ('content_type', 'object_id')
def __str__(self): def __str__(self):
@ -392,7 +392,7 @@ class Speaker(RESTModelMixin, models.Model):
class Meta: class Meta:
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_be_speaker', ugettext_noop('Can put oneself on the list of speakers')), ('can_be_speaker', 'Can put oneself on the list of speakers'),
) )
def __str__(self): def __str__(self):

View File

@ -109,10 +109,10 @@ class Assignment(RESTModelMixin, models.Model):
class Meta: class Meta:
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_see', ugettext_noop('Can see elections')), ('can_see', 'Can see elections'),
('can_nominate_other', ugettext_noop('Can nominate another participant')), ('can_nominate_other', 'Can nominate another participant'),
('can_nominate_self', ugettext_noop('Can nominate oneself')), ('can_nominate_self', 'Can nominate oneself'),
('can_manage', ugettext_noop('Can manage elections')), ('can_manage', 'Can manage elections'),
) )
ordering = ('title', ) ordering = ('title', )
verbose_name = ugettext_noop('Election') verbose_name = ugettext_noop('Election')

View File

@ -73,8 +73,7 @@ angular.module('OpenSlidesApp.assignments', [])
'AssignmentPoll', 'AssignmentPoll',
'jsDataModel', 'jsDataModel',
'gettext', 'gettext',
'gettextCatalog', function ($http, DS, AssignmentRelatedUser, AssignmentPoll, jsDataModel, gettext) {
function ($http, DS, AssignmentRelatedUser, AssignmentPoll, jsDataModel, gettext, gettextCatalog) {
var name = 'assignments/assignment'; var name = 'assignments/assignment';
var phases; var phases;
return DS.defineResource({ return DS.defineResource({

View File

@ -2,7 +2,6 @@ from django.conf import settings
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import models from django.db import models
from django.utils.translation import ugettext_noop
from jsonfield import JSONField from jsonfield import JSONField
from openslides.mediafiles.models import Mediafile from openslides.mediafiles.models import Mediafile
@ -64,9 +63,9 @@ class Projector(RESTModelMixin, models.Model):
""" """
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_see_projector', ugettext_noop('Can see the projector')), ('can_see_projector', 'Can see the projector'),
('can_manage_projector', ugettext_noop('Can manage the projector')), ('can_manage_projector', 'Can manage the projector'),
('can_see_frontpage', ugettext_noop('Can see the front page'))) ('can_see_frontpage', 'Can see the front page'),)
@property @property
def elements(self): def elements(self):
@ -184,7 +183,7 @@ class Tag(RESTModelMixin, models.Model):
ordering = ('name',) ordering = ('name',)
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_manage_tags', ugettext_noop('Can manage tags')),) ('can_manage_tags', 'Can manage tags'),)
def __str__(self): def __str__(self):
return self.name return self.name
@ -204,7 +203,7 @@ class ConfigStore(models.Model):
class Meta: class Meta:
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_manage_config', ugettext_noop('Can manage configuration')),) ('can_manage_config', 'Can manage configuration'),)
def get_root_rest_url(self): def get_root_rest_url(self):
""" """
@ -230,7 +229,7 @@ class ChatMessage(RESTModelMixin, models.Model):
class Meta: class Meta:
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_use_chat', ugettext_noop('Can use the chat')),) ('can_use_chat', 'Can use the chat'),)
def __str__(self): def __str__(self):
return 'Message {}'.format(self.timestamp) return 'Message {}'.format(self.timestamp)

View File

@ -1,7 +1,6 @@
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_noop
from openslides.utils.search import user_name_helper from openslides.utils.search import user_name_helper
@ -38,9 +37,9 @@ class Mediafile(RESTModelMixin, models.Model):
ordering = ['title'] ordering = ['title']
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_see', ugettext_noop('Can see the list of files')), ('can_see', 'Can see the list of files'),
('can_upload', ugettext_noop('Can upload files')), ('can_upload', 'Can upload files'),
('can_manage', ugettext_noop('Can manage files')),) ('can_manage', 'Can manage files'))
def __str__(self): def __str__(self):
""" """

View File

@ -115,10 +115,10 @@ class Motion(RESTModelMixin, models.Model):
class Meta: class Meta:
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_see', ugettext_noop('Can see motions')), ('can_see', 'Can see motions'),
('can_create', ugettext_noop('Can create motions')), ('can_create', 'Can create motions'),
('can_support', ugettext_noop('Can support motions')), ('can_support', 'Can support motions'),
('can_manage', ugettext_noop('Can manage motions')), ('can_manage', 'Can manage motions'),
) )
ordering = ('identifier', ) ordering = ('identifier', )
verbose_name = ugettext_noop('Motion') verbose_name = ugettext_noop('Motion')

View File

@ -161,10 +161,9 @@ angular.module('OpenSlidesApp.motions', ['OpenSlidesApp.users'])
'MotionPoll', 'MotionPoll',
'jsDataModel', 'jsDataModel',
'gettext', 'gettext',
'gettextCatalog',
'operator', 'operator',
'Config', 'Config',
function(DS, MotionPoll, jsDataModel, gettext, gettextCatalog, 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,

View File

@ -8,7 +8,6 @@ from django.contrib.auth.models import (
PermissionsMixin, PermissionsMixin,
) )
from django.db import models from django.db import models
from django.utils.translation import ugettext_noop
from openslides.utils.search import user_name_helper from openslides.utils.search import user_name_helper
@ -146,9 +145,9 @@ class User(RESTModelMixin, PermissionsMixin, AbstractBaseUser):
class Meta: class Meta:
default_permissions = () default_permissions = ()
permissions = ( permissions = (
('can_see_name', ugettext_noop('Can see names of users')), ('can_see_name', 'Can see names of users'),
('can_see_extra_data', ugettext_noop('Can see extra data of users')), ('can_see_extra_data', 'Can see extra data of users'),
('can_manage', ugettext_noop('Can manage users')), ('can_manage', 'Can manage users'),
) )
ordering = ('last_name', 'first_name', 'username', ) ordering = ('last_name', 'first_name', 'username', )

View File

@ -148,10 +148,22 @@ angular.module('OpenSlidesApp.users', [])
]) ])
.factory('Group', [ .factory('Group', [
'$http',
'DS', 'DS',
function(DS) { function($http, DS) {
var permissions;
return DS.defineResource({ return DS.defineResource({
name: 'users/group', name: 'users/group',
permissions: permissions,
getPermissions: function() {
if (!this.permissions) {
this.permissions = $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' })
.then(function(result) {
return result.data.actions.POST.permissions.choices;
});
}
return this.permissions;
}
}); });
} }
]) ])

View File

@ -96,8 +96,8 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
}) })
.state('users.group.create', { .state('users.group.create', {
resolve: { resolve: {
permissions: function($http) { permissions: function(Group) {
return $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' }); return Group.getPermissions();
} }
} }
}) })
@ -113,8 +113,8 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'@users.group': {} '@users.group': {}
}, },
resolve: { resolve: {
permissions: function($http) { permissions: function(Group) {
return $http({ 'method': 'OPTIONS', 'url': '/rest/users/group/' }); return Group.getPermissions();
} }
} }
}) })
@ -762,7 +762,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'permissions', 'permissions',
function($scope, $state, Group, permissions) { function($scope, $state, Group, permissions) {
// get all permissions // get all permissions
$scope.permissions = permissions.data.actions.POST.permissions.choices; $scope.permissions = permissions;
$scope.group = {}; $scope.group = {};
$scope.save = function (group) { $scope.save = function (group) {
Group.create(group).then( Group.create(group).then(
@ -782,7 +782,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'group', 'group',
function($scope, $state, Group, permissions, group) { function($scope, $state, Group, permissions, group) {
// get all permissions // get all permissions
$scope.permissions = permissions.data.actions.POST.permissions.choices; $scope.permissions = permissions;
$scope.group = group; // autoupdate is not activated $scope.group = group; // autoupdate is not activated
$scope.save = function (group) { $scope.save = function (group) {
Group.save(group).then( Group.save(group).then(
@ -827,8 +827,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
'$http', '$http',
'$stateParams', '$stateParams',
'operator', 'operator',
'gettextCatalog', function ($rootScope, $scope, $http, $stateParams, operator ) {
function ($rootScope, $scope, $http, $stateParams, operator, gettextCatalog) {
$scope.alerts = []; $scope.alerts = [];
// get login info-text from server // get login info-text from server
@ -872,8 +871,47 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
$scope.closeThisDialog(); $scope.closeThisDialog();
}; };
} }
])
// Mark all permission strings for translation in JavaScript.
// (see models.py of each Django app)
.config([
'gettext',
function (gettext) {
// agenda
gettext('Can see agenda')
gettext('Can manage agenda')
gettext('Can see hidden items and time scheduling of agenda')
gettext('Can put oneself on the list of speakers')
// assignments
gettext('Can see elections')
gettext('Can nominate another participant')
gettext('Can nominate oneself')
gettext('Can manage elections')
// core
gettext('Can see the projector')
gettext('Can manage the projector')
gettext('Can see the dashboard')
gettext('Can manage tags')
gettext('Can manage configuration')
gettext('Can use the chat')
// mediafiles
gettext('Can see the list of files')
gettext('Can upload files')
gettext('Can manage files')
// motions
gettext('Can see motions')
gettext('Can create motions')
gettext('Can support motions')
gettext('Can manage motions')
// users
gettext('Can see names of users')
gettext('Can see extra data of users')
gettext('Can manage users')
}
]); ]);
// this is code from angular.js. Find a way to call this function from this file // this is code from angular.js. Find a way to call this function from this file
function getBlockNodes(nodes) { function getBlockNodes(nodes) {
// TODO(perf): just check if all items in `nodes` are siblings and if they are return the original // TODO(perf): just check if all items in `nodes` are siblings and if they are return the original

View File

@ -19,8 +19,8 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="selectPermissions" translate>Permissions</label> <label for="selectPermissions" translate>Permissions</label>
<select multiple size="15" ng-options="permission.value as permission.display_name for permission in permissions" <select multiple size="15" ng-model="group.permissions" class="form-control" id="selectPermissions" required>
ng-model="group.permissions" class="form-control" name="selectPermissions" required> <option value="{{ permission.value }}" ng-repeat="permission in permissions">{{ permission.display_name | translate }}</option>
</select> </select>
</div> </div>