Skip to content

Commit

Permalink
Maybe finish survey requests...?
Browse files Browse the repository at this point in the history
  • Loading branch information
smellsblue committed Sep 18, 2023
1 parent 3b41234 commit 9a757b6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
8 changes: 8 additions & 0 deletions app/models/survey_organization_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ class SurveyOrganizationRequest < ApplicationRecord
belongs_to :organization
has_one :survey_answer

def self.unanswered
where(answered: false, skipped: false)
end

def self.for_organizations(organizations)
where(organization: organizations)
end

def unanswered?
!answered && !skipped
end
Expand Down
24 changes: 16 additions & 8 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ class User < ApplicationRecord

after_commit :send_pending_notifications

def deleted?
!super_admin? && organization_users.empty?
end

def valid_password?(password)
super && !deleted?
end

def self.at_organization(orgs)
joins(:organization_users).where(organization_users: { organization: orgs })
end
Expand All @@ -50,6 +42,22 @@ def self.not_deleted
all.reject(&:deleted?)
end

def unanswered_survey_requests
return [] if super_admin?

SurveyOrganizationRequest.includes(survey_request: :survey)
.unanswered.for_organizations(organizations)
.order(:created_at).to_a
end

def deleted?
!super_admin? && organization_users.empty?
end

def valid_password?(password)
super && !deleted?
end

protected

def email_updated?
Expand Down
10 changes: 9 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
</div>
</div>

<% if !user_signed_in? %>
<% if user_signed_in? %>
<% if params[:controller] != "survey_request_answers" %>
<% current_user.unanswered_survey_requests.each do |org_request| %>
<div class="alert alert-danger" role="alert">
Please take some time to fill out a survey: <%= link_to org_request.survey_request.survey.title, survey_request_answer_path(org_request.survey_request, org_request) %>
</div>
<% end %>
<% end %>
<% else %>
<div class="row top15">
<div class="col-xs-12 top15 bottom15">
<img class="img-responsive center-block" src="<%= path_to_image("header-logo.png") %>" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class AddClosedAtToSurveyRequests < ActiveRecord::Migration[5.2]
def change
add_column :survey_requests, :closed_at, :datetime
add_index :survey_organization_requests, [:organization_id, :answered, :skipped], name: "surv_org_reqs_on_orgid_answered_skipped"
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "skipped", default: false, null: false
t.index ["organization_id", "answered", "skipped"], name: "surv_org_reqs_on_orgid_answered_skipped"
t.index ["organization_id", "answered"], name: "surv_org_reqs_on_orgid_answered"
t.index ["organization_id"], name: "index_survey_organization_requests_on_organization_id"
t.index ["survey_request_id"], name: "index_survey_organization_requests_on_survey_request_id"
Expand Down

0 comments on commit 9a757b6

Please sign in to comment.