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

Sparc user profile #1949

Merged
merged 11 commits into from
Aug 6, 2019
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
//= require service_calendar

//= require dashboard/protocols
//= require profile_form



Expand Down
53 changes: 53 additions & 0 deletions app/assets/javascripts/profile_form.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright © 2011-2019 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

$(document).ready ->
$(document).on('keydown', '#identity_orcid', (event) ->
key = event.keyCode || event.charCode
val = $(this).val()
isDelete = [8, 46].includes(key)

# Key must be numerical OR key must be X and last character of ID
if !((key >= 96 && key <= 105) || (key >= 48 && key <= 57)) && !(key == 88 && val.length == 18) && !isDelete
event.stopImmediatePropagation()
return false
else if isDelete && [6, 11, 16].includes(val.length)
$(this).val(val.substr(0, val.length - 1))
if !isDelete && [4, 9, 14].includes(val.length)
$(this).val(val + "-")
else if !isDelete && [5, 10, 15].includes(val.length) && val[val.length-1] != "-"
$(this).val(val.substr(0, val.length - 1) + "-" + val.substr(val.length - 1, val.length))
else if key == 88 && val.length == 18
event.stopImmediatePropagation()
$(this).val(val.substr(0, val.length) + String.fromCharCode(key).toUpperCase())
).on('keyup', '#identity_orcid', (event) ->
key = event.keyCode || event.charCode
val = $(this).val()
isDelete = [8, 46].includes(key)

if !isDelete && [4, 9, 14].includes(val.length)
$(this).val(val + "-")
)

$(document).on 'changed.bs.select', '#identity_credentials', ->
if $(this).val() == 'other'
$('#credentialsOtherContainer').removeClass('d-none')
else
$('#credentialsOtherContainer').addClass('d-none')
33 changes: 33 additions & 0 deletions app/controllers/identities/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,44 @@ def create
end
end

def edit
session[:return_to] ||= request.referer
end

def update
@identity = current_user
@professional_organization_id = params[:project_role][:identity_attributes][:professional_organization_id]
attrs = fix_professional_organization_id
if @identity.update_attributes(attrs)
redirect_to session.delete(:return_to)
flash[:success] = t(:devise)[:profile][:updated]
else
render 'edit'
end
end

private

def sign_up_params
attrs = devise_parameter_sanitizer.sanitize(:sign_up)
attrs[:phone] = sanitize_phone(attrs[:phone])
attrs
end

def identity_params
params.require(:identity).permit(:orcid,
:credentials,
:credentials_other,
:email,
:era_commons_name,
:professional_organization_id,
:phone,
:subspecialty)
end

def fix_professional_organization_id
attrs = identity_params
attrs = attrs.merge(professional_organization_id: @professional_organization_id)
attrs
end
end
6 changes: 3 additions & 3 deletions app/models/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ class Identity < ApplicationRecord

cattr_accessor :current_user

validates_presence_of :first_name, :last_name, :email, :phone
validates_presence_of :first_name, :last_name, :email

validates_format_of :email, with: Devise::email_regexp, allow_blank: true, if: :email_changed?
validates_format_of :phone, with: /[0-9]{10}(#[0-9]+)?/
validates_format_of :phone, with: /[0-9]{10}(#[0-9]+)?/, allow_blank: true

validates :ldap_uid, uniqueness: {case_sensitive: false}, presence: true
validates :orcid, format: { with: /\A([0-9]{4}-){3}[0-9]{3}[0-9X]\z/ }, allow_blank: true

validates_presence_of :reason, if: :new_record?
# validates_presence_of :reason, if: :new_record?

###############################################################################
############################## DEVISE OVERRIDES ###############################
Expand Down
4 changes: 2 additions & 2 deletions app/views/devise/registrations/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
= icon('far', 'envelope')
= f.email_field :email, class: 'form-control'
.form-group.col-12.col-xl-6
= f.label :phone, class: 'required'
= f.label :phone
.input-group
.input-group-prepend
%span.input-group-text
Expand All @@ -48,7 +48,7 @@
= f.label :company
= f.text_field :company, class: 'form-control'
.form-group
= f.label :reason, class: 'required'
= f.label :reason
= f.text_area :reason, class: 'form-control', rows: 5
.form-group
= f.label :ldap_uid, class: 'required'
Expand Down
58 changes: 58 additions & 0 deletions app/views/devise/registrations/_profile_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f|
= render "devise/shared/error_messages", resource: resource
kayla-glick marked this conversation as resolved.
Show resolved Hide resolved
.form-group.row
= f.label :full_name, t(:devise)[:profile][:full_name], class: 'col-lg-4 col-form-label'
.col-lg-8
= identity.full_name

.form-group.row
= f.label :email, t(:devise)[:profile][:email], class: 'col-lg-4 col-form-label required'
.input-group.col-lg-8
.input-group-prepend
%span.input-group-text
= icon('far', 'envelope')
= f.text_field :email, class: 'form-control'

.form-group.row
= f.label :phone, t(:devise)[:profile][:phone], class: 'col-lg-4 col-form-label'
.col-lg-8
.input-group
.input-group-prepend
%span.input-group-text
= icon('fas', 'phone')
= f.telephone_field :phone, class: 'form-control', placeholder: t('constants.phone.placeholder')
%span.form-text.text-muted
= t('constants.phone.note')

.form-group.row
= f.label :orcid, class: 'col-lg-4 col-form-label'
.col-lg-8
= f.text_field :orcid, class: 'form-control', placeholder: t(:devise)[:profile][:placeholders][:orcid], maxlength: 19
%smal.form-text
= link_to t(:devise)[:profile][:links][:orcid], t(:devise)[:profile][:links][:orcid], target: :blank

.form-group.row
= f.label :era_commons_name, t(:devise)[:profile][:era_commons_name], class: 'col-lg-4 col-form-label'
.col-lg-8
= f.text_field :era_commons_name, class: 'form-control'

.form-group.row
= f.label :subspecialty, t(:devise)[:profile][:subspecialty], class: 'col-lg-4 col-form-label'
.col-lg-8
= f.select :subspecialty, options_for_select(PermissibleValue.get_inverted_hash('subspecialty'), identity.subspecialty), { include_blank: t(:devise)[:profile][:subspecialty_prompt] }, class: 'form-control selectpicker'

.form-group.row
= f.label :credentials, t(:devise)[:profile][:credentials], class: 'col-lg-4 col-form-label'
.col-lg-8
= f.select :credentials, options_for_select(PermissibleValue.get_inverted_hash('user_credential'), identity.credentials), { include_blank: t(:devise)[:profile][:credentials_prompt] }, class: 'form-control selectpicker'

.form-group.row#credentialsOtherContainer{ class: f.object.credentials == 'other' ? '' : 'd-none' }
.col-lg-4
= f.label :credentials_other, t('constants.prompts.please_specify')
.col-lg-8
= f.text_field :credentials_other, class: 'form-control'

= render("dashboard/associated_users/professional_organizations", professional_organization: identity.professional_organization)

.actions
= f.submit t(:devise)[:profile][:update], class: 'btn btn-lg btn-block btn-outline-primary'
3 changes: 3 additions & 0 deletions app/views/devise/registrations/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%h2.text-center.mb-4
= t('devise.profile.header')
= render 'profile_form', identity: current_user
5 changes: 5 additions & 0 deletions app/views/devise/shared/_error_messages.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- if resource.errors.any?
kayla-glick marked this conversation as resolved.
Show resolved Hide resolved
.alert.alert-danger
%ul
- resource.errors.full_messages.each do |message|
%li= message
2 changes: 1 addition & 1 deletion app/views/layouts/_profile.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
- if current_user.unread_notification_count > 0
%span.badge.badge-pill.badge-danger.ml-1#messagesBadge
= current_user.unread_notification_count
= link_to 'javascript:void(0)', class: 'dropdown-item text-secondary' do
= link_to edit_identity_registration_path, class: 'dropdown-item text-secondary' do
= icon('far', 'edit mr-2')
= t('layout.navigation.profile.edit')
= link_to destroy_identity_session_path(srid: @service_request.try(:id)), method: :delete, class: 'dropdown-item text-danger' do
Expand Down
21 changes: 21 additions & 0 deletions config/locales/devise.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,24 @@ en:
subject: "SPARCRequest Reset Password Instructions"
unlock_instructions:
subject: "SPARCRequest Unlock Instructions"
###########
# Profile #
###########
profile:
header: "User Profile"
update: "Save Changes"
full_name: "Full Name"
kayla-glick marked this conversation as resolved.
Show resolved Hide resolved
email: "Email"
orcid: "ORCID"
placeholders:
orcid: "XXXX-XXXX-XXXX-XXXX"
links:
orcid: "https://orcid.org/"
era_commons_name: "ERA Commons Name"
phone: "Phone"
credentials: "Credentials"
credentials_prompt: "Select One"
credentials_other: "Credentials Other"
updated: "Profile Updated!!"
subspecialty: "Subspecialty"
subspecialty_prompt: "Select a Subspecialty:"
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
if Setting.get_value("use_shibboleth_only")
devise_for :identities,
controllers: {
omniauth_callbacks: 'identities/omniauth_callbacks'
omniauth_callbacks: 'identities/omniauth_callbacks',
registrations: 'identities/registrations'
}, path_names: { sign_in: 'auth/shibboleth', sign_up: 'auth/shibboleth' }

elsif Setting.get_value("use_cas_only")
devise_for :identities,
controllers: {
omniauth_callbacks: 'identities/omniauth_callbacks'
omniauth_callbacks: 'identities/omniauth_callbacks',
registrations: 'identities/registrations'
}, path_names: { sign_in: 'auth/cas', sign_up: 'auth/cas' }
else
devise_for :identities,
Expand Down