Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 98157690-client-sid…
Browse files Browse the repository at this point in the history
…e-validation
  • Loading branch information
afeld committed Oct 27, 2015
2 parents 3b8b95a + 998c641 commit d872a35
Show file tree
Hide file tree
Showing 65 changed files with 979 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .about.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ licenses:
# text: Anchor text for the link
links:
- url: https://c2.18f.gov/
- text: C2 website
text: C2 website

# Email addresses of points-of-contact
contact:
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Style/RedundantSelf:
Style/SignalException:
Enabled: false
Style/StringLiterals:
Enabled: false
EnforcedStyle: double_quotes
Style/TrailingComma:
Enabled: false
Style/AndOr:
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/flash_errors.js.coffee
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$ ->
$('div.alert:first').attr('tabindex','-1').focus()
$('div.alert:first').attr('tabindex', '-1').focus()
2 changes: 1 addition & 1 deletion app/assets/javascripts/required_for_submit.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RequiredForSubmit
@checkDisable()

checkDisable: ->
@$submit.prop 'disabled', (@$controller.val() == '')
@$submit.prop 'disabled', !@$controller.val()

$ ->
$scope = $(document.body)
Expand Down
5 changes: 3 additions & 2 deletions app/assets/javascripts/selectizer.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class Selectizer
@$el.is('input')

form_label: ->
$('label[for="'+@$el.attr('id')+'"]').text()
id = @$el.attr('id')
$("label[for=\"#{id}\"]").text()

add_label: ->
@selectizeObj().$control_input.attr('aria-label',@form_label())
@selectizeObj().$control_input.attr('aria-label', @form_label())

initialChoices: ->
initial = @$el.data('initial') || []
Expand Down
17 changes: 3 additions & 14 deletions app/assets/stylesheets/common/form-control.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
.form-control {
/*Placeholder text color*/
&::-webkit-input-placeholder { /* WebKit browsers */
color: #777677;
}
&:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #777677;
opacity: 1;
}
&::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #777677;
opacity: 1;
}
&:-ms-input-placeholder { /* Internet Explorer 10+ */
color: #777677;
&::placeholder {
color: #777677;
opacity: 1;
}
}

Expand Down
30 changes: 9 additions & 21 deletions app/controllers/ncr/work_orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,39 @@ class WorkOrdersController < UseCaseController
MAX_UPLOADS_ON_NEW = 10

def new
@approver_email = self.suggested_approver_email
@model_instance.approving_official_email = self.suggested_approver_email
super
end

def create
@approver_email = params[:approver_email]
super
end

def edit
if self.proposal.approved?
flash[:warning] = "You are about to modify a fully approved request. Changes will be logged and sent to approvers but this request will not require re-approval."
end
first_approver = self.proposal.approvers.first
@approver_email = first_approver.try(:email_address)

super
end

def update
@approver_email = params[:approver_email]
@model_instance.modifier = current_user

super

if @model_changing && !@model_instance.emergency # skip approvals if emergency
@model_instance.setup_approvals_and_observers(@approver_email)
if @model_changing
@model_instance.setup_approvals_and_observers
@model_instance.email_approvers
end
end

protected

def attribute_changes?
super || @model_instance.approver_changed?(@approver_email)
super || @model_instance.approver_changed?
end

protected

def model_class
Ncr::WorkOrder
end
Expand All @@ -56,22 +52,14 @@ def permitted_params
if @model_instance
fields.delete(:emergency) # emergency field cannot be edited
end
params.require(:ncr_work_order).permit(:project_title, *fields)
end

def errors
results = super
if @approver_email.blank? && !@model_instance.approver_email_frozen?
results += ["Approver email is required"]
end
results
params.require(:ncr_work_order).permit(:project_title, :approving_official_email, *fields)
end

# @pre: @approver_email is set
# @pre: @model_instance.approving_official_email is set
def add_approvals
super
if self.errors.empty?
@model_instance.setup_approvals_and_observers(@approver_email)
@model_instance.setup_approvals_and_observers
end
end
end
Expand Down
21 changes: 14 additions & 7 deletions app/controllers/use_case_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ class UseCaseController < ApplicationController
before_filter ->{authorize self.model_class}, only: [:new, :create]
before_filter ->{authorize self.proposal}, only: [:edit, :update]
rescue_from Pundit::NotAuthorizedError, with: :auth_errors
before_filter :build_model_instance, only: [:new, :create]
before_filter :find_model_instance, only: [:edit, :update]


def new
@model_instance = self.model_class.new
render 'form'
end

def create
@model_instance = self.model_class.new(self.permitted_params)

# TODO unify with how the factories create model instances
@model_instance.build_proposal(flow: 'linear', requester: current_user)

if self.errors.empty?
@model_instance.save
proposal = @model_instance.proposal
Expand Down Expand Up @@ -66,6 +60,19 @@ def attribute_changes?
!@model_instance.changed_attributes.blank?
end

def filtered_params
if params[:action] == 'new'
{}
else
permitted_params
end
end

def build_model_instance
@model_instance = self.model_class.new(filtered_params)
@model_instance.build_proposal(flow: 'linear', requester: current_user)
end

def find_model_instance
@model_instance ||= self.model_class.find(params[:id])
end
Expand Down
8 changes: 8 additions & 0 deletions app/decorators/ncr/work_order_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def final_approver_email_address
approver_email_address(final_approver)
end

def status_aware_approver_email_address
if proposal.approved?
final_approver_email_address
else
current_approver_email_address
end
end

private

def approver_email_address(approver)
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/ncr/work_orders_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Ncr
module WorkOrdersHelper
def approver_options
# @todo should this list be limited by client/something else?
# @todo is there a better order? maybe by current_user's use?
User.order(:email_address).pluck(:email_address)
User.where(client_slug: 'ncr').order(:email_address).pluck(:email_address)
end

def building_options
Expand Down
8 changes: 4 additions & 4 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ def email_with_name(email, name)
end

def reply_to_email
ENV['NOTIFICATION_REPLY_TO'] || 'noreplyto@some.gov'
email_with_name(ENV['NOTIFICATION_REPLY_TO'] || 'noreplyto@some.gov', 'C2')
end

def sender_email
ENV['NOTIFICATION_FROM_EMAIL'] || 'noreply@some.gov'
email_with_name(ENV['NOTIFICATION_FROM_EMAIL'] || 'noreply@some.gov', 'C2')
end

def resend_to_email
ENV['NOTIFICATION_FALLBACK_EMAIL'] || 'communicart.sender@gsa.gov'
email_with_name(ENV['NOTIFICATION_FALLBACK_EMAIL'] || 'communicart.sender@gsa.gov', 'C2')
end

def default_sender_email
email_with_name(sender_email, "Communicart")
sender_email
end

def user_email_with_name(user)
Expand Down
1 change: 1 addition & 0 deletions app/mailers/feedback_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def feedback(sending_user, form_values)
subject: '[C2] Feedback submission',
from: from,
cc: from,
reply_to: from,
body: self.body_for(form_values)
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/report_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def budget_status
end

def annual_ncr_report(year, to_email)
attachments["NCR_Work_Order_Report_FY#{year}.csv"] = Ncr::Reporter.build_ncr_annual_report_string(year)
attachments["NCR_Work_Order_Report_FY#{year}.csv"] = Ncr::Reporter.new.build_ncr_annual_report_string(year)

mail(
to: to_email,
Expand Down
20 changes: 14 additions & 6 deletions app/models/ncr/work_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ def self.purchase_amount_column_name
include ProposalDelegate
include PurchaseCardMixin

attr_accessor :approving_official_email
# This is a hack to be able to attribute changes to the correct user. This attribute needs to be set explicitly, then the update comment will use them as the "commenter". Defaults to the requester.
attr_accessor :modifier

after_initialize :set_defaults
before_validation :normalize_values
before_update :record_changes

validates :approving_official_email, presence: true
validates_email_format_of :approving_official_email
validates :amount, presence: true
validates :cl_number, format: {
with: /\ACL\d{7}\z/,
Expand Down Expand Up @@ -57,6 +60,10 @@ def self.purchase_amount_column_name
}

def set_defaults
# not sure why the latter condition is necessary...was getting some weird errors from the tests without it. -AF 10/5/2015
if !self.approving_official_email && self.approvers.any?
self.approving_official_email = self.approvers.first.try(:email_address)
end
self.direct_pay ||= false
self.not_to_exceed ||= false
self.emergency ||= false
Expand Down Expand Up @@ -90,23 +97,23 @@ def approver_email_frozen?
approval && !approval.actionable?
end

def approver_changed?(approval_email)
self.approving_official && self.approving_official.email_address != approval_email
def approver_changed?
self.approving_official && self.approving_official.email_address != approving_official_email
end

# Check the approvers, accounting for frozen approving official
def approvers_emails(selected_approving_official_email)
def approvers_emails
emails = self.system_approver_emails
if self.approver_email_frozen?
emails.unshift(self.approving_official.email_address)
else
emails.unshift(selected_approving_official_email)
emails.unshift(self.approving_official_email)
end
emails
end

def setup_approvals_and_observers(selected_approving_official_email)
emails = self.approvers_emails(selected_approving_official_email)
def setup_approvals_and_observers
emails = self.approvers_emails
if self.emergency
emails.each{|e| self.add_observer(e)}
# skip state machine
Expand Down Expand Up @@ -302,6 +309,7 @@ def self.update_comment_format(key, value, bullet, former=nil)
def force_approvers(emails)
individuals = emails.map do |email|
user = User.for_email(email)
user.update!(client_slug: 'ncr')
# Reuse existing approvals, if present
self.proposal.existing_approval_for(user) || Approvals::Individual.new(user: user)
end
Expand Down
Loading

0 comments on commit d872a35

Please sign in to comment.