Include room permissions with the Vuex seed data.
Closes #2381 (closed)
Explanation
We use context to decide whether the user is an admin:
context.isTroupeAdmin = function() {
var permissions = troupe.get('permissions');
if (!permissions) return false;
return !!permissions.admin;
};
When switching between rooms, we call router-chat.js .changeRoom()
with the Vuex room as an argument. .changeRoom()
sets this room on the context.
This room is missing permissions
field because we didn't include it in serialization.
After the chatCollection
is rendered, the realtime-troupe-listener
synchronizes a troupe snapshot with the context. This new troupe had the permissions
field.
This is why it broke the "delete" option. We used to check whether the user is an admin when the user opened the context menu (long after the realtime sync happened and the permissions
were available) but now we check the admin rights when we initialize the chatItemView
.
Testing strategy
- go to a room where you are admin, and refresh
- in the left menu select another room where you are an admin
- validate that you can delete a message by selecting "Delete" in the chat item context menu.