Middle
Tell us how your access rights matrix was organized and how the display of elements depending on the user's role was implemented in the code.
sobes.tech AI
Answer from AI
In our project, the rights matrix was implemented as an object where the keys were user roles, and the values were sets of permitted actions or accessible interface components. For example, for each role, we defined which buttons, pages, or functions are available.
In code, it looked something like this:
const permissions = {
admin: ['viewDashboard', 'editUsers', 'deletePosts'],
editor: ['viewDashboard', 'editPosts'],
viewer: ['viewDashboard']
};
function canAccess(role, action) {
return permissions[role]?.includes(action);
}
// In a React component
function Dashboard({ userRole }) {
return (
<div>
{canAccess(userRole, 'viewDashboard') && <DashboardContent />}
{canAccess(userRole, 'editUsers') && <EditUsersButton />}
</div>
);
}
This approach allowed centralized management of rights and easy extension when adding new roles or functions. The display of interface elements depended on rights verification through the canAccess function, which provided flexibility and security on the client side.