• Members 17 posts
    Oct. 27, 2018, 11:55 a.m.

    Hi, @rafalp :
    Can I ask question?

    from django.contrib.auth import get_user_model
    UserModel = get_user_model()
    u = UserModel.objects.all().first()
    > u.acl
    > AttributeError:'User' object has no attribute 'acl'
    

    but within user serializers,this user have acl attribute .

    # ...\misago\users\serializers\user.py
    class UserSerializer(serializers.ModelSerializer, MutableFields):
        ......
        acl = serializers.SerializerMethodField()
    
        def get_acl(self, obj):
            return obj.acl
    # here the `obj` is user istance,am i right?
    

    So my question is why u.acl get error,but obj.acl just fine.
    Thank You!

  • Oct. 27, 2018, 4 p.m.
    check_box

    Marked as best answer by Oct. 28, 2018, 4:05 a.m..

    Hello!

    The .acl attribute is set by misago.acl.add_acl utility, and means that item is acl aware: it knows what request.user can do with it. UserSerializer exposes this ACL to client so client logic knows what user moderation options should be displayed in the UI.

    If you want to learn user permissions, you can read them from user.acl_cache.