Skip to content

Commit

Permalink
Fix problems with account updating and user groups / Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Oct 17, 2024
1 parent bb907af commit 7a3b688
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module VerifyUserGroupExtensions

included do
def call
return broadcast(:invalid) unless @user_group.confirmed?
return broadcast(:email_confirmation) unless @user_group.confirmed?
return broadcast(:invalid) unless @user_group.valid?

verify_user_group
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Decidim
module Privacy
module Admin
module UserGroupsControllerExtensions
extend ActiveSupport::Concern

included do
def verify
@user_group = collection.find(params[:id])
enforce_permission_to :verify, :user_group, user_group: @user_group

Decidim::Admin::VerifyUserGroup.call(@user_group, current_user) do
on(:ok) do
flash[:notice] = I18n.t("user_group.verify.success", scope: "decidim.admin")
redirect_back(fallback_location: decidim_admin.user_groups_path)
end

on(:invalid) do
flash[:alert] = I18n.t("user_group.verify.invalid", scope: "decidim.admin")
redirect_back(fallback_location: decidim_admin.user_groups_path)
end

on(:email_confirmation) do
flash[:alert] = I18n.t("user_group.verify.confirmation_pending", scope: "decidim.admin")
redirect_back(fallback_location: decidim_admin.user_groups_path)
end
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def create

CreateUserGroup.call(@form) do
on(:ok) do
flash[:notice] = t("groups.create.success", scope: "decidim")
flash[:notice] = t("groups.create.email_confirmation", scope: "decidim.privacy")

redirect_to profile_path(current_user.nickname)
end
Expand Down
3 changes: 1 addition & 2 deletions app/views/decidim/account/_old_password_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<%
old_password_options = {
autocomplete: "current-password",
required: true
autocomplete: "current-password"
}
old_password_options[:help_text] = t("devise.passwords.edit.old_password_help") if local_assigns.has_key?(:show_help_text) && show_help_text
%>
Expand Down
10 changes: 7 additions & 3 deletions app/views/decidim/account/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
<% end %>

<%= form_required_explanation %>

<%= f.text_field :name, autocomplete: "name" %>
<%= f.text_field :nickname, autocomplete: "nickname" %>
<%= f.email_field :email, disabled: current_user.unconfirmed_email.present?, autocomplete: "email", data: { original: current_user.email } %>
<%= f.email_field :email, readonly: current_user.unconfirmed_email.present?, autocomplete: "email", data: { original: current_user.email } %>
<%= f.url_field :personal_url, autocomplete: "url" %>
<%= f.text_area :about, rows: 5 %>

Expand All @@ -38,9 +37,14 @@
) %>
<p class="help-text"><%= t(".available_locales_helper") %></p>

<% if @account.errors[:password].any? || @account.errors[:password_confirmation].any? || @account.errors[:old_password].any?%>
<% if @account.errors[:password].any? || @account.errors[:password_confirmation].any? %>
<%= render partial: "password_fields", locals: { form: f, user: current_user } %>
<%= render partial: "old_password_field", locals: { form: f, show_help_text: true, unhide: false } %>
<% elsif @account.errors[:old_password].any? && @account.password.present? && @account.password_confirmation.present? %>
<%= render partial: "password_fields", locals: { form: f, user: current_user } %>
<%= render partial: "old_password_field", locals: { form: f, show_help_text: true, unhide: false } %>
<% elsif @account.errors[:old_password].any? %>
<%= render partial: "old_password_field", locals: { form: f, show_help_text: true, unhide: false } %>
<% else %>
<% if current_organization.sign_in_enabled? %>
<p>
Expand Down
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ en:
profile: My public profile
message: "Your profile is set as public on this platform and other people can see details about you, such as your name, nickname, profile picture and your public activity on this platform. You can change the visibility of your profile through the privacy settings page. Your profile is available at:"
decidim:
admin:
user_group:
verify:
confirmation_pending: The group's email address has to be confirmed in order to verify the group.
components:
privacy:
name: Privacy settings
Expand Down Expand Up @@ -111,6 +115,11 @@ en:
do_not_agree: No, I do not want to make my profile public
publish_account:
unauthorized: Only participants with public profiles are allowed to perform this action.
groups:
create:
email_confirmation: Group successfully created! Please check the group's email address for a verification message to verify the group's email address.
verify:
email_confirmation: The group's email address has to be confirmed in order to verify the group.
profile:
private: Private participant
private_info_html: <i>This participant has decided to make their profile private. New messages to this conversation have been therefore disabled.</i>
Expand Down
3 changes: 3 additions & 0 deletions lib/decidim/privacy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class Engine < ::Rails::Engine
)

# controllers
Decidim::Admin::UserGroupsController.include(
Decidim::Privacy::Admin::UserGroupsControllerExtensions
)
Decidim::ApplicationController.include(
Decidim::Privacy::ApplicationControllerExtensions
)
Expand Down
8 changes: 6 additions & 2 deletions spec/system/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,18 @@
it "renders the old password with error" do
within "form.edit_user" do
find("*[type=submit]").click
end

within "form.new_user" do
fill_in :user_old_password, with: "wrong password"
find("*[type=submit]").click
end
within ".flash.alert" do
expect(page).to have_content "There was a problem updating your account."
end
find("#old_password_field").click
within "#old_password_field" do
expect(page).to have_content "is invalid"
expect(page).to have_css('[role="alert"]', text: "is invalid")
end
end
end
Expand All @@ -149,7 +153,7 @@

it "tells user to confirm new email" do
expect(page).to have_content("Email change verification")
expect(page).to have_selector("#user_email[disabled='disabled']")
expect(page).to have_selector("#user_email[readonly='readonly']")
expect(page).to have_content("You'll receive an email to confirm your new email address.")
end

Expand Down
24 changes: 24 additions & 0 deletions spec/system/admin/user_group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "spec_helper"
describe "Admin filters user_groups", type: :system do
let(:organization) { create(:organization) }
let!(:user) { create(:user, :admin, :confirmed, organization: organization) }
let!(:pending_ug) { create(:user_group, organization: organization, users: [user]) }

before do
switch_to_host(organization.host)
login_as user, scope: :user
visit decidim_admin.user_groups_path
end

context "when user group is not confirmed" do
it "gives a flash alert that the user group needs to be confirmed before verification" do
within "td.table-list__actions" do
click_link "Verify"
end

expect(page).to have_content("The group's email address has to be confirmed in order to verify the group.")
end
end
end
12 changes: 12 additions & 0 deletions spec/system/user_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,16 @@
end
end
end

context "when creating a user group" do
it "gives a flash alert to check email for confirmation" do
visit decidim.profile_path(public_member.nickname)
click_link "Create group"
fill_in(:group_name, with: "Example group")
fill_in(:group_nickname, with: "eg")
fill_in(:group_email, with: "[email protected]")
click_button "Create group"
expect(page).to have_content("Group successfully created! Please check the group's email address for a verification message to verify the group's email address")
end
end
end

0 comments on commit 7a3b688

Please sign in to comment.