仅当服务器使用Django-CMS重新启动时,用户页面权限才会更新 [英] User page permissions updating only when server restarts with Django-CMS

查看:67
本文介绍了仅当服务器使用Django-CMS重新启动时,用户页面权限才会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我遇到一个问题,我有一个页面使用rest框架,该页面通过更改组或更改其他次要信息(例如名称和密码)来编辑用户(我正在使用默认的django用户应用)权限.但是,当我编辑一个用户组时,由于某种原因,仅当我编辑它们时,用户权限仅在重新启动django服务器时才更改,从而允许用户查看他不应该看到的django cms pag.服务器重新启动后,所有权限都可以正常工作.

Basically, I am having an issue where, I have a page using rest framework that edits user (I am using the default django user app) permissions by changing the groups or changes other minor infos like name and password. However, when I edit a group of a user, and only when I edit them, for some reason, the user permissions only changes when I restart the django server, allowing the user to view django cms pags that he should not see. After the server restarts all permissions works just fine.

我已经试图像这样强制刷新权限:

I already tried to force the permissions to be refreshed like this:

for app in settings.INSTALLED_APPS:
    create_permissions(apps.get_app_config(app.split(".")[-1]))

但是没有用.

实际上我根本不知道问题的根源是什么,以至于我不确定我可以在此处放置什么代码,因此我不确定是否会发布其余的用户序列化器:

I actually have no clue whatsoever what the cause of the issue is, so much that I am not sure what code I could put here, so in doubt I will post the rest user serializer:

# -*- coding: utf-8 -*-
from rest_framework import serializers
from django.contrib.auth.models import User


class UserSerializer(serializers.ModelSerializer):
    def __init__(self, *args, **kwargs):
        super(UserSerializer, self).__init__(*args, **kwargs)
        self.fields['username'].label = u"Usuário"
        self.fields['password'].label = u"Senha"
        self.fields['first_name'].label = u"Nome Completo"

    group_name = serializers.SerializerMethodField()

    def get_group_name(self, obj):
        return ", ".join(list(obj.groups.values_list('name',flat=True)))

    def create(self, validated_data):
        user = super(UserSerializer, self).create(validated_data)
        user.set_password(validated_data['password'])
        user.save()
        return user

    def update(self, instance, validated_data):
        user = super(UserSerializer, self).update(instance, validated_data)
        if "password" in validated_data:
            user.set_password(validated_data['password'])
        user.save()

        return user


    class Meta:
        model = User
        fields = [
            "id",
            "first_name",
            "username",
            "password",
            "group_name",
            "groups",
            "is_active",
        ]

推荐答案

因此,问题在于菜单缓存,而django CMS在缓存方面似乎不太好.因此,我只是禁用了所有缓存,应该使用以下代码的第一行将其禁用,但实际上仅禁用了在settings.py中添加CMS_CACHE_DURATIONS:

So, the problem was a menu caching, and django CMS seems to be not so good with cache. So I simply disabled all cache, which, should've been disabled with the first line of the following code, but it only actually disabled adding a CMS_CACHE_DURATIONS in settings.py:

CMS_PAGE_CACHE = CMS_PLACEHOLDER_CACHE = CMS_PLUGIN_CACHE = False
CMS_CACHE_DURATIONS={
    'menus': 0,
    'content': 0,
    'permissions': 0,
}

这篇关于仅当服务器使用Django-CMS重新启动时,用户页面权限才会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆