Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.6 KiB

module UserHelper
def aliased_user_edit(user, current_user)
current_user == user ? edit_account_path : edit_user_path(user)
end
def perspective(user, current_user)
current_user == user ? "Are you" : "Is this person"
end
def can_edit_org?(current_user)
current_user.data_coordinator? || current_user.support?
end
def delete_user_link(user)
govuk_button_link_to "Delete this user", delete_confirmation_user_path(user), warning: true
end
def organisation_change_warning(user, new_organisation)
logs_count = user.assigned_to_lettings_logs.count + user.assigned_to_sales_logs.count
logs_count_text = logs_count == 1 ? "is #{logs_count} log" : "are #{logs_count} logs"
"You’re moving #{user.name} from #{user.organisation.name} to #{new_organisation.name}. There #{logs_count_text} assigned to them."
end
def organisation_change_confirmation_warning(user, new_organisation, log_reassignment)
log_reassignment_text = "There are no logs assigned to them."
logs_count = user.assigned_to_lettings_logs.count + user.assigned_to_sales_logs.count
if logs_count.positive?
case log_reassignment
when "reassign_all"
log_reassignment_text = "The stock owner and managing agent on their logs will change to #{new_organisation.name}."
when "reassign_stock_owner"
log_reassignment_text = "The stock owner on their logs will change to #{new_organisation.name}."
when "reassign_managing_agent"
log_reassignment_text = "The managing agent on their logs will change to #{new_organisation.name}."
when "unassign"
log_reassignment_text = "Their logs will be unassigned."
end
end
"You’re moving #{user.name} from #{user.organisation.name} to #{new_organisation.name}. #{log_reassignment_text}"
end
def remove_attributes_from_error_messages(user)
modified_errors = []
user.errors.each do |error|
cleaned_message = error.type.gsub(error.attribute.to_s.humanize, "").strip
modified_errors << [error.attribute, cleaned_message]
end
user.errors.clear
modified_errors.each do |attribute, message|
user.errors.add(attribute, message)
end
end
def display_pending_email_change_banner?(user)
user.unconfirmed_email.present? && user.email != user.unconfirmed_email
end
def pending_email_change_title_text(current_user, user)
if current_user == user
"You have requested to change your email address to #{user.unconfirmed_email}."
else
"There has been a request to change this user’s email address to #{user.unconfirmed_email}."
end
end
def pending_email_change_banner_text(current_user)
text = "A confirmation link has been sent to the new email address. The current email will continue to work until the change is confirmed."
text += " Deactivating this user will cancel the email change request." if current_user.support? || current_user.data_coordinator?
text
end
CLDC-3740: Replace you didn't answer text with link to question (#2836) * Different versions of details_html * One version of details_html * Replace you didnt answer with link * Fix lint * Update some tests * Update some tests * Add question marks to yes no questions - test * Improve formatting helper * Improve formatting helper * Improve prompt message * Revert "Add question marks to yes no questions - test" This reverts commit 40bee289 * Rename question method * Add check answer prompt method to question model and translation key * Add translation key to soft validations * Lettings custom prompts * Update to handle new helpdesk ticket logic * Update copy * Update copy * Update method names * Add check answer prompt to soft validations * Change copy * Do not put error objects into cookies * Hide change link for inferred or derived values not yet answered * Revert "Hide change link for inferred or derived values not yet answered" This reverts commit ec1fd1c9aa7db852c0250600ce39335335344f65. * Update lettings related check answer prompts * Update some sales related check answer prompts * Update some sales related check answer prompts * Bug fix * More sales prompts * Replace text for bulk upload * Update uprn known test with specific error message already used * Translation file to CSV * Revert "Translation file to CSV" This reverts commit 0565fea7172ba9fe78af806ee19afdac255a60bc. * Add a red link to show questions that still must be answered (after bulk upload) * Lint * Update feature tests * Update component tests * Update helper tests * Update requests tests * Update request test * Refactor improvements * Refactor improvements 0.2 * Lint * Stay consistent with date question message * Rename variable * Add tests * Improvements * Refactor details table helper * Remove action link not just hide * Revert "Remove action link not just hide" This reverts commit 59ecac5cf3a2c8f1453d7f5ad6c6a1a2ef891578. * Users - remove action link * Organisations - remove action link * Merge requests - remove action link * Revert "Refactor details table helper" This reverts commit b74fd830f13ff0179efeff77421a3d7e43e76d83. * Schemes - remove action link * Location - remove action link * Logs - remove action link * Lint * Refactor V2 details table helper * Allow respond_to? to see private methods * Remove .presence duplication of logic * Change "Answer if" to "Tell us if" * Add missing CAP * Update age questions sales and lettings * Update postcode and la questions * Update wording * Updates and improvements * Another update * Fix bug * typo * typo * update relat to buyer/lead prompts * Update test * Additional copy * Additional copy * Update copy "housing-related" to "housing related" --------- Co-authored-by: Kat <54268893+kosiakkatrina@users.noreply.github.com>
2 weeks ago
def user_details_html(user, current_user, attribute)
value = user.send(attribute)
return value.humanize if value.present?
case attribute
when "role"
current_user.data_coordinator? || current_user.support? ? govuk_link_to("Select role", aliased_user_edit(user, current_user), class: "govuk-link govuk-link--no-visited-state") : "No role assigned"
when "phone"
govuk_link_to("Enter telephone number", aliased_user_edit(user, current_user), class: "govuk-link govuk-link--no-visited-state")
else
"No answer provided"
end
end
def user_action_text(user, attribute)
return "Change" if %w[role phone].include?(attribute) && user.send(attribute).present?
""
end
end