Commit 91bc7384 authored by alexandre's avatar alexandre

Assigning permissions works

parent 7d04329c
......@@ -4,7 +4,7 @@ from rest_framework import serializers
from rest_framework_recursive.fields import RecursiveField
from taggit_serializer.serializers import (TagListSerializerField,
TaggitSerializer)
from guardian.shortcuts import assign_perm, get_users_with_perms
from guardian.shortcuts import assign_perm, get_users_with_perms, get_user_perms, remove_perm
from django.contrib.auth.models import User
......@@ -57,7 +57,6 @@ class ScoreSerializer(TaggitSerializer, serializers.HyperlinkedModelSerializer):
return instance
def update(self, instance, validated_data):
import ipdb; ipdb.set_trace()
instance = super(ScoreSerializer, self).update(instance, validated_data)
permissions = validated_data["permissions"]
for i in permissions:
......@@ -65,6 +64,9 @@ class ScoreSerializer(TaggitSerializer, serializers.HyperlinkedModelSerializer):
perms = i.get("permissions")
user = User.objects.get(username=username)
for perm in get_user_perms(user, instance):
remove_perm(perm, user, instance)
for perm in perms:
assign_perm(perm, user, instance)
return instance
......
......@@ -10,9 +10,9 @@ window.W = window.W || {};
region: 'body',
onStart: function(options) {
var userModel = new W.UserModel();
this.showView(new W.BaseView({model: userModel}));
userModel.fetch();
var userAuthModel = new W.UserAuthModel();
this.showView(new W.BaseView({model: userAuthModel}));
userAuthModel.fetch();
var router = new W.ScoreRouter({application: this});
......
......@@ -6,10 +6,10 @@ window.W = window.W || {};
(function(undefined) {
'use strict';
W.PluginCollection = Backbone.Collection.extend({
W.UserCollection = Backbone.Collection.extend({
url: '/api/users/',
model: W.Plugin
model: W.UserModel
});
W.ScoreCollection = Backbone.PageableCollection.extend({
......
......@@ -7,7 +7,7 @@ window.W = window.W || {};
'use strict';
W.Plugin = Backbone.Model.extend({
W.UserModel = Backbone.Model.extend({
urlRoot: '/api/users/',
label: function () {
......@@ -23,7 +23,7 @@ window.W = window.W || {};
});
W.UserModel = Backbone.Model.extend({
W.UserAuthModel = Backbone.Model.extend({
urlRoot: '/rest-auth/user/',
defaults: {
......
......@@ -1207,11 +1207,11 @@ window.W = window.W || {};
onRender: function () {
document.title = this.model.get('title');
var plugins = new W.PluginCollection();
plugins.fetch({success: function() {
var users = new W.UserCollection();
users.fetch({success: function() {
new AutoCompleteView({
input: $("#plugin"), // your input field
model: plugins, // your collection
model: users, // your collection
queryParameter: 'search',
onSelect: function (model) {
console.log();
......
<%- username %><br>
<input type="checkbox" value="view_score" name="view_score"
<% if (_.indexOf(permissions, "view_score")) { %> checked <% } %>
<% if (_.indexOf(permissions, "view_score") != -1) { %> checked <% } %>
/>
<label>Peut voir</label>
<input type="checkbox" value="change_score" name="change_score"
<% if (_.indexOf(permissions, "change_score")) { %> checked <% } %>
<% if (_.indexOf(permissions, "change_score") != -1) { %> checked <% } %>
/>
<label>Peut éditer</label>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment