Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add account permissions hint for screen reader users #4902

Merged
merged 4 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Extract component to render account permissions
We were using similar code in four different places; six, if we count
the welcome pages seeds. Reducing duplication in the pages seeds is a
bit tricky because administrators are supposed to edit their content and
might remove the HTML class we use to define styles. However, we can
share the code everywhere else.

Note that there's a bug in the application since we show that level 2
users cannot vote for budget projects but we give them permission to do
so in the abilities model. We're keeping the same behavior after this
refactoring but we might change it in the future.
  • Loading branch information
javierm committed Nov 29, 2022
commit 9b908d72641728457d6357ea50a4c2c191559fac
23 changes: 23 additions & 0 deletions app/assets/stylesheets/account/permissions_list.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.permissions-list {
list-style-type: none;
margin-bottom: 0;
margin-left: 0;

li {
font-size: $small-font-size;
margin-bottom: $line-height / 2;

span {
color: $text-medium;
font-size: rem-calc(12);
}

.icon-check {
color: $check;
}

.icon-x {
color: $delete;
}
}
}
26 changes: 0 additions & 26 deletions app/assets/stylesheets/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -525,32 +525,6 @@ code {
// 05. Management
// --------------

.user-permissions {

ul {
list-style-type: none;
margin-left: 0;
}

li {
font-size: rem-calc(14);
margin-bottom: rem-calc(12);

span {
color: $text-medium;
font-size: rem-calc(12);
}

.icon-check {
color: $check;
}

.icon-x {
color: $delete;
}
}
}

.account-info,
.login-as {
background-color: $highlight;
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@import "stats";
@import "sticky_overrides";
@import "tags";
@import "account/**/*";
@import "admin/**/*";
@import "budgets/**/*";
@import "debates/**/*";
Expand Down
24 changes: 0 additions & 24 deletions app/assets/stylesheets/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1278,30 +1278,6 @@ form {
font-size: rem-calc(12);
}
}

ul {
list-style-type: none;
margin-bottom: 0;
margin-left: 0;
}

li {
font-size: $small-font-size;
margin-bottom: $line-height / 2;

span {
color: $text-medium;
font-size: rem-calc(12);
}

.icon-check {
color: $check;
}

.icon-x {
color: $delete;
}
}
}

.notifications-list {
Expand Down
20 changes: 20 additions & 0 deletions app/components/account/permissions_list_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ul class="permissions-list">
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_debates") %></li>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_proposal") %></li>
<li>
<% if user.level_two_or_three_verified? %>
<span class="icon-check"></span>
<% else %>
<span class="icon-x"></span>
<% end %>
<%= t("verification.user_permission_support_proposal") %>
</li>
<li>
<% if user.level_three_verified? %>
<span class="icon-check"></span>
<% else %>
<span class="icon-x"></span>
<% end %>
<%= t("verification.user_permission_votes") %>
</li>
</ul>
7 changes: 7 additions & 0 deletions app/components/account/permissions_list_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Account::PermissionsListComponent < ApplicationComponent
attr_reader :user

def initialize(user)
@user = user
end
end
2 changes: 1 addition & 1 deletion app/controllers/management/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Management::UsersController < Management::BaseController
def new
@user = User.new(user_params)
@user = User.new(user_params.merge(verified_at: Time.current))
end

def create
Expand Down
21 changes: 1 addition & 20 deletions app/views/account/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,7 @@

<p><%= t("account.show.user_permission_info") %></p>

<ul>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_debates") %></li>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_proposal") %></li>
<li>
<% if current_user.level_two_or_three_verified? %>
<span class="icon-check"></span>
<% else %>
<span class="icon-x"></span>
<% end %>
<%= t("verification.user_permission_support_proposal") %>
</li>
<li>
<% if current_user.level_three_verified? %>
<span class="icon-check"></span>
<% else %>
<span class="icon-x"></span>
<% end %>
<%= t("verification.user_permission_votes") %>
</li>
</ul>
<%= render Account::PermissionsListComponent.new(current_user) %>

<p>
<%= t("account.show.user_permission_verify") %>
Expand Down
15 changes: 1 addition & 14 deletions app/views/management/_user_permissions.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<%# # Parameters:
# message: A string explaining the permissions
# permissions: An array of symbols containing the permissions
# (can be :debates, :proposal, :support_proposal, :votes) %>
<div class="user-permissions">

<p><%= message %></p>

<ul>
<% [:debates, :proposal, :support_proposal, :votes].each do |permission| %>
<li>
<span class="<%= permissions.include?(permission) ? "icon-check" : "icon-x" %>"></span>
<%= t("verification.user_permission_#{permission}") %>
</li>
<% end %>
</ul>

<%= render Account::PermissionsListComponent.new(user) %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<%= render "management/user_permissions",
message: t("management.document_verifications.not_in_census_info"),
permissions: [:debates, :proposal] %>
user: User.new %>

<p>
<%= sanitize(t("management.document_verifications.has_no_account",
Expand Down
2 changes: 1 addition & 1 deletion app/views/management/document_verifications/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<%= render "management/user_permissions",
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :proposal, :support_proposal] %>
user: @document_verification.user %>

<%= form_for @document_verification,
as: :document_verification,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

<%= render "management/user_permissions",
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :proposal, :support_proposal, :votes] %>
user: @document_verification.user %>

<a href="javascript:window.print();" class="button warning"><%= t("management.print_info") %></a>
2 changes: 1 addition & 1 deletion app/views/management/email_verifications/sent.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<%= render "management/user_permissions",
message: t("management.email_verifications.document_found_in_census"),
permissions: [:debates, :proposal, :support_proposal, :votes] %>
user: @email_verification.user %>

<p>
<a href="javascript:window.print();" class="button warning"><%= t("management.print_info") %></a>
Expand Down
2 changes: 1 addition & 1 deletion app/views/management/users/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
<div class="callout">
<%= render "management/user_permissions",
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :proposal, :support_proposal, :votes] %>
user: @user %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/management/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

<%= render "management/user_permissions",
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :proposal, :support_proposal, :votes] %>
user: @user %>

<a href="javascript:window.print();" class="button warning radius"><%= t("management.print_info") %></a>
8 changes: 1 addition & 7 deletions app/views/verification/letter/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,9 @@
<h1><%= t("verification.letter.new.title") %></h1>

<div class="user-permissions">

<p><%= t("verification.letter.new.user_permission_info") %></p>

<ul>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_debates") %></li>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_proposal") %></li>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_support_proposal") %></li>
<li><span class="icon-x"></span>&nbsp;<%= t("verification.user_permission_votes") %></li>
</ul>
<%= render Account::PermissionsListComponent.new(current_user) %>
</div>

<%= link_to t("verification.letter.new.go_to_index"), root_path, class: "button warning" %>
Expand Down
7 changes: 1 addition & 6 deletions app/views/verification/residence/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
<div class="user-permissions small-12">
<p><%= t("verification.user_permission_info") %></p>

<ul>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_debates") %></li>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_proposal") %></li>
<li><span class="icon-check"></span>&nbsp;<%= t("verification.user_permission_support_proposal") %></li>
<li><span class="icon-x"></span>&nbsp;<%= t("verification.user_permission_votes") %></li>
</ul>
<%= render Account::PermissionsListComponent.new(User.new(level_two_verified_at: Time.current)) %>
</div>

<%= form_for @residence, as: "residence", url: residence_path do |f| %>
Expand Down