Skip to content
Snippets Groups Projects
Commit c686c49f authored by Teal Bauer's avatar Teal Bauer
Browse files

Add role-based visibility controls for UI elements

- Create new CSS visibility classes based on user roles and permissions
- Update ApplicationHelper to add data attributes to body based on user roles and permissions
- Replace legacy hide-unless-shiftcoordinator with more specific can-manage-assignments-only
- Support both positive (has-role-X-only) and negative (except-has-role-X) visibility rules
- Maintain backward compatibility with existing shiftcoordinator checks
parent 218c8fcd
No related branches found
No related tags found
1 merge request!29Add role-based visibility controls for UI elements
Pipeline #38348 passed
...@@ -59,9 +59,75 @@ ...@@ -59,9 +59,75 @@
border-right: 1px dashed gray; border-right: 1px dashed gray;
} }
/* Role-based visibility classes */
[class*="-only"] {
display: none;
}
/* Permission-based visibility classes */
.can-manage-assignments-only {
display: none;
}
body[data-can-manage-assignments] .can-manage-assignments-only {
display: block;
}
/* Role-based visibility classes */
.has-role-shift_coordinator-only {
display: none;
}
body[data-has-role-shift_coordinator] .has-role-shift_coordinator-only {
display: block;
}
.has-role-admin-only {
display: none;
}
body[data-has-role-admin] .has-role-admin-only {
display: block;
}
.has-role-events_admin-only {
display: none;
}
body[data-has-role-events_admin] .has-role-events_admin-only {
display: block;
}
/* Exception classes */
.except-has-role-admin {
display: block;
}
body[data-has-role-admin] .except-has-role-admin {
display: none;
}
.except-has-role-shift_coordinator {
display: block;
}
body[data-has-role-shift_coordinator] .except-has-role-shift_coordinator {
display: none;
}
.except-has-role-events_admin {
display: block;
}
body[data-has-role-events_admin] .except-has-role-events_admin {
display: none;
}
.except-can-manage-assignments {
display: block;
}
body[data-can-manage-assignments] .except-can-manage-assignments {
display: none;
}
/* Legacy class for backward compatibility */
.hide-unless-shiftcoordinator { .hide-unless-shiftcoordinator {
display: none; display: none;
} }
body[data-is-shiftcoordinator] .hide-unless-shiftcoordinator { body[data-has-role-shift_coordinator] .hide-unless-shiftcoordinator,
body[data-can-manage-assignments] .hide-unless-shiftcoordinator {
display: block; display: block;
} }
module ApplicationHelper module ApplicationHelper
def body_data_attributes def body_data_attributes
attributes = {} attributes = {}
attributes[:loggedin_uid] = current_user.id if user_signed_in? if user_signed_in?
attributes[:is_shiftcoordinator] = 1 if current_user&.shiftcoordinator? attributes[:loggedin_uid] = current_user.id
attributes[:languages_from] = current_user.languages_from unless current_user&.languages_from.blank?
# Legacy attribute for backward compatibility
attributes[:is_shiftcoordinator] = 1 if current_user.shiftcoordinator?
# Add role-based data attributes
current_user.roles.each do |role|
attributes[:"has_role_#{role.name}"] = 1
end
# Add permission-based data attributes
current_user.roles.each do |role|
role.permissions.each do |permission|
attributes[:"can_#{permission.name}"] = 1
end
end
attributes[:languages_from] = current_user.languages_from unless current_user.languages_from.blank?
end
attributes[:darkmode] = current_user&.darkmode || "auto" attributes[:darkmode] = current_user&.darkmode || "auto"
{ data: attributes } { data: attributes }
end end
......
<% unassigned_users = @users - session.assignments.collect(&:user) %> <% unassigned_users = @users - session.assignments.collect(&:user) %>
<% if unassigned_users.length > 0 %> <% if unassigned_users.length > 0 %>
<div class="text-sm hide-unless-shiftcoordinator"> <div class="text-sm can-manage-assignments-only">
<%= form_with url: conference_session_assignments_path(session.conference, session), method: :post, data: { turbo_frame: dom_id(session) } do |f| %> <%= form_with url: conference_session_assignments_path(session.conference, session), method: :post, data: { turbo_frame: dom_id(session) } do |f| %>
<%= f.select :user_id, options_from_collection_for_select(unassigned_users, :id, :name), { disabled: '', prompt: '-' }, { class: "text-sm" } %> <%= f.select :user_id, options_from_collection_for_select(unassigned_users, :id, :name), { disabled: '', prompt: '-' }, { class: "text-sm" } %>
<%= f.submit "Assign", class: 'primary text-sm' %> <%= f.submit "Assign", class: 'primary text-sm' %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment