Merge pull request #2082 from emanuelschuetze/fix2081
Use always user.groups_id (Fixes #2081)
This commit is contained in:
commit
5959b19af2
@ -4,8 +4,8 @@ from django.utils.translation import ugettext as _
|
|||||||
from django.utils.translation import ugettext_lazy
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from ..utils.rest_api import (
|
from ..utils.rest_api import (
|
||||||
|
IdPrimaryKeyRelatedField,
|
||||||
ModelSerializer,
|
ModelSerializer,
|
||||||
PrimaryKeyRelatedField,
|
|
||||||
RelatedField,
|
RelatedField,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
)
|
)
|
||||||
@ -40,7 +40,7 @@ class UserFullSerializer(ModelSerializer):
|
|||||||
|
|
||||||
Serializes all relevant fields.
|
Serializes all relevant fields.
|
||||||
"""
|
"""
|
||||||
groups = PrimaryKeyRelatedField(
|
groups = IdPrimaryKeyRelatedField(
|
||||||
many=True,
|
many=True,
|
||||||
queryset=Group.objects.exclude(pk__in=(1, 2)),
|
queryset=Group.objects.exclude(pk__in=(1, 2)),
|
||||||
help_text=ugettext_lazy('The groups this user belongs to. A user will '
|
help_text=ugettext_lazy('The groups this user belongs to. A user will '
|
||||||
|
@ -122,8 +122,8 @@ angular.module('OpenSlidesApp.users', [])
|
|||||||
getPerms: function() {
|
getPerms: function() {
|
||||||
var allPerms = [];
|
var allPerms = [];
|
||||||
var allGroups = [];
|
var allGroups = [];
|
||||||
if (this.groups) {
|
if (this.groups_id) {
|
||||||
allGroups = this.groups.slice(0);
|
allGroups = this.groups_id.slice(0);
|
||||||
}
|
}
|
||||||
// Add registered group
|
// Add registered group
|
||||||
allGroups.push(2);
|
allGroups.push(2);
|
||||||
@ -146,6 +146,14 @@ angular.module('OpenSlidesApp.users', [])
|
|||||||
return "Participant";
|
return "Participant";
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
relations: {
|
||||||
|
hasMany: {
|
||||||
|
'users/group': {
|
||||||
|
localField: 'groups',
|
||||||
|
localKey: 'groups_id',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
@ -319,7 +319,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'groups',
|
key: 'groups_id',
|
||||||
type: 'select-multiple',
|
type: 'select-multiple',
|
||||||
templateOptions: {
|
templateOptions: {
|
||||||
label: gettextCatalog.getString('Groups'),
|
label: gettextCatalog.getString('Groups'),
|
||||||
@ -672,7 +672,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
var user = {
|
var user = {
|
||||||
first_name: first_name,
|
first_name: first_name,
|
||||||
last_name: last_name,
|
last_name: last_name,
|
||||||
groups: []
|
groups_id: []
|
||||||
};
|
};
|
||||||
User.create(user).then(
|
User.create(user).then(
|
||||||
function(success) {
|
function(success) {
|
||||||
@ -741,7 +741,7 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
// groups
|
// groups
|
||||||
if (user.groups) {
|
if (user.groups) {
|
||||||
var csvGroups = user.groups.replace(quotionRe, '$1').split(",");
|
var csvGroups = user.groups.replace(quotionRe, '$1').split(",");
|
||||||
user.groups = [];
|
user.groups_id = [];
|
||||||
user.groupnames = [];
|
user.groupnames = [];
|
||||||
if (csvGroups !== '') {
|
if (csvGroups !== '') {
|
||||||
// All group objects are already loaded via the resolve statement from ui-router.
|
// All group objects are already loaded via the resolve statement from ui-router.
|
||||||
@ -749,14 +749,14 @@ angular.module('OpenSlidesApp.users.site', ['OpenSlidesApp.users'])
|
|||||||
csvGroups.forEach(function(csvGroup) {
|
csvGroups.forEach(function(csvGroup) {
|
||||||
allGroups.forEach(function (allGroup) {
|
allGroups.forEach(function (allGroup) {
|
||||||
if (csvGroup == allGroup.id) {
|
if (csvGroup == allGroup.id) {
|
||||||
user.groups.push(allGroup.id);
|
user.groups_id.push(allGroup.id);
|
||||||
user.groupnames.push(allGroup.name);
|
user.groupnames.push(allGroup.name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
user.groups = [];
|
user.groups_id = [];
|
||||||
}
|
}
|
||||||
// comment
|
// comment
|
||||||
if (user.comment) {
|
if (user.comment) {
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
<label translate>Structure level</label>
|
<label translate>Structure level</label>
|
||||||
{{ user.structure_level }}
|
{{ user.structure_level }}
|
||||||
<label translate>Groups</label>
|
<label translate>Groups</label>
|
||||||
<div ng-repeat="group in user.groups">
|
<div ng-repeat="group in user.groups_id">
|
||||||
{{ (groups | filter: {id: group})[0].name }}
|
{{ (groups | filter: {id: group})[0].name | translate }}
|
||||||
</div>
|
</div>
|
||||||
<label translate>About me</label>
|
<label translate>About me</label>
|
||||||
<div ng-bind-html="user.about_me"></div>
|
<div ng-bind-html="user.about_me"></div>
|
||||||
|
@ -124,7 +124,7 @@
|
|||||||
|
|
||||||
<!-- filter users (for user with 'can_see_extra_data' permission) - consider present filter -->
|
<!-- filter users (for user with 'can_see_extra_data' permission) - consider present filter -->
|
||||||
<div os-perms="users.can_see_extra_data">
|
<div os-perms="users.can_see_extra_data">
|
||||||
<span ng-repeat="user in $parent.usersFiltered = (users | filter: filter.search | filter: {groups: groupFilter} |
|
<span ng-repeat="user in $parent.usersFiltered = (users | filter: filter.search | filter: {groups_id: groupFilter} |
|
||||||
filter: {is_present: filterPresent} | orderBy: sortColumn:reverse)"></span>
|
filter: {is_present: filterPresent} | orderBy: sortColumn:reverse)"></span>
|
||||||
</div>
|
</div>
|
||||||
<!-- filter users (for user without 'can_see_extra_data' permission) -->
|
<!-- filter users (for user without 'can_see_extra_data' permission) -->
|
||||||
@ -190,11 +190,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<td class="optional">{{ user.structure_level }}
|
<td class="optional">{{ user.structure_level }}
|
||||||
<td class="optional">
|
<td class="optional">
|
||||||
<div os-perms="users.can_manage" ng-repeat="group in user.groups">
|
<div ng-repeat="group in user.groups_id">
|
||||||
{{ (groups | filter: {id: group})[0].name | translate }}
|
|
||||||
</div>
|
|
||||||
<!-- TODO: normal users can't use user.groups but users.groups_id -->
|
|
||||||
<div os-perms="!users.can_manage" ng-repeat="group in user.groups_id">
|
|
||||||
{{ (groups | filter: {id: group})[0].name | translate }}
|
{{ (groups | filter: {id: group})[0].name | translate }}
|
||||||
</div>
|
</div>
|
||||||
<td os-perms="users.can_see_extra_data">
|
<td os-perms="users.can_see_extra_data">
|
||||||
|
@ -49,7 +49,7 @@ class UserCreate(TestCase):
|
|||||||
self.client.post(
|
self.client.post(
|
||||||
reverse('user-list'),
|
reverse('user-list'),
|
||||||
{'last_name': 'Test name aedah1iequoof0Ashed4',
|
{'last_name': 'Test name aedah1iequoof0Ashed4',
|
||||||
'groups': group_pks})
|
'groups_id': group_pks})
|
||||||
|
|
||||||
user = User.objects.get(username='Test name aedah1iequoof0Ashed4')
|
user = User.objects.get(username='Test name aedah1iequoof0Ashed4')
|
||||||
self.assertTrue(user.groups.filter(pk=group_pks[0]).exists())
|
self.assertTrue(user.groups.filter(pk=group_pks[0]).exists())
|
||||||
@ -64,10 +64,10 @@ class UserCreate(TestCase):
|
|||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse('user-list'),
|
reverse('user-list'),
|
||||||
{'last_name': 'Test name aedah1iequoof0Ashed4',
|
{'last_name': 'Test name aedah1iequoof0Ashed4',
|
||||||
'groups': group_pks})
|
'groups_id': group_pks})
|
||||||
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
self.assertEqual(response.data, {'groups': ["Invalid pk \"%d\" - object does not exist." % group_pks[0]]})
|
self.assertEqual(response.data, {'groups_id': ["Invalid pk \"%d\" - object does not exist." % group_pks[0]]})
|
||||||
|
|
||||||
|
|
||||||
class UserUpdate(TestCase):
|
class UserUpdate(TestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user