-
Notifications
You must be signed in to change notification settings - Fork 24
feat: Adds Legal Agreements object for dynamic agreements #429
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
Changes from 4 commits
7e9cf5d
e62bc73
c5e97bf
6733064
e9667dc
9f6687c
04203db
2882c29
cb13563
3341245
22249c5
1a50f1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
class Manage::AgreementsController < Manage::ApplicationController | ||
before_action :require_director | ||
before_action :set_agreement, only: [:show, :edit, :update, :destroy] | ||
|
||
respond_to :html, :json | ||
|
||
# GET /agreements | ||
def index | ||
@agreements = Agreement.all | ||
end | ||
|
||
# GET /agreements/new | ||
def new | ||
@agreement = Agreement.new | ||
end | ||
|
||
# GET /agreements/1/edit | ||
def edit | ||
end | ||
|
||
# POST /agreements | ||
def create | ||
if !agreement_params['agreement_url'].start_with?('http://', 'https://') | ||
flash[:alert] = "Agreement URL must start with http:// or https://" | ||
redirect_to new_manage_agreement_path | ||
else | ||
@agreement = Agreement.new(agreement_params) | ||
@agreement.save | ||
flash[:notice] = "#{@agreement.name} was successfully created." | ||
redirect_to manage_agreements_path | ||
end | ||
end | ||
|
||
# PATCH/PUT /agreements/1 | ||
def update | ||
if !agreement_params['agreement_url'].nil? and agreement_params['agreement_url'].start_with?('http://', 'https://') | ||
flash[:alert] = "Agreement URL must start with http:// or https://" | ||
render :edit | ||
else | ||
@agreement.update_attributes(agreement_params) | ||
flash[:notice] = nil | ||
redirect_to manage_agreements_path | ||
end | ||
end | ||
|
||
# DELETE /agreements/1 | ||
def destroy | ||
@agreement.destroy | ||
flash[:notice] = 'Agreement was successfully destroyed.' | ||
respond_with(:manage, @agreement, location: manage_agreements_path) | ||
end | ||
|
||
private | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_agreement | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@agreement = Agreement.find(params[:id]) | ||
end | ||
|
||
# Only allow a trusted parameter "white list" through. | ||
def agreement_params | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
params.require(:agreement).permit( | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:name, :agreement_url | ||
) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ def datatable | |
end | ||
|
||
def show | ||
@agreements = Agreement.all | ||
respond_with(:manage, @questionnaire) | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Agreement < ApplicationRecord | ||
include ActionView::Helpers::UrlHelper | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
validates_presence_of :name | ||
validates_presence_of :agreement_url | ||
|
||
strip_attributes | ||
|
||
has_and_belongs_to_many :questionnaires | ||
|
||
def formatted_agreement | ||
"I read and accept the #{link_to name, agreement_url, target: "_blank"} agreement.".html_safe | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,19 @@ class Questionnaire < ApplicationRecord | |
belongs_to :user | ||
belongs_to :school | ||
belongs_to :bus_list, optional: true | ||
has_and_belongs_to_many :agreements | ||
|
||
validates_uniqueness_of :user_id | ||
|
||
validates_presence_of :phone, :date_of_birth, :school_id, :experience, :shirt_size, :interest | ||
validates_presence_of :gender, :major, :level_of_study, :graduation_year, :race_ethnicity | ||
validates_presence_of :agreement_accepted, message: "Please read & accept" | ||
validates_presence_of :code_of_conduct_accepted, message: "Please read & accept" | ||
validates_presence_of :data_sharing_accepted, message: "Please read & accept" | ||
|
||
DIETARY_SPECIAL_NEEDS_MAX_LENGTH = 500 | ||
validates_length_of :dietary_restrictions, maximum: DIETARY_SPECIAL_NEEDS_MAX_LENGTH | ||
validates_length_of :special_needs, maximum: DIETARY_SPECIAL_NEEDS_MAX_LENGTH | ||
|
||
validate :agreements_present | ||
|
||
# if HackathonManager.field_enabled?(:why_attend) | ||
# validates_presence_of :why_attend | ||
# end | ||
|
@@ -215,6 +215,26 @@ def verbal_status | |
end | ||
end | ||
|
||
def agreements_present | ||
if (Agreement.all - self.agreements).any? | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
errors.add(:agreements, "must be accepted.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this no longer works haha #437 |
||
end | ||
end | ||
|
||
def all_agreements_accepted? | ||
(Agreement.all - self.agreements).empty? | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
def unaccepted_agreements | ||
Agreement.all - self.agreements | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
def as_json(options = {}) | ||
result = super | ||
result['all_agreements_accepted'] = all_agreements_accepted? | ||
result | ||
end | ||
|
||
private | ||
|
||
def clean_for_non_rsvp | ||
|
@@ -277,4 +297,5 @@ def queue_triggered_email_rsvp_reminder | |
end | ||
UserMailer.rsvp_reminder_email(user_id).deliver_later(wait_until: deliver_date) if deliver_date.present? | ||
end | ||
|
||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#disclaimer.alert | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Classes should be listed before IDs (.alert should precede #disclaimer)
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
%h1.section-title | ||
%span.emphasized.fa.fa-exclamation-circle | ||
Missing | ||
%span.emphasized Agreements | ||
%p | ||
You have unaccepted agreements. You will not be allowed at #{HackathonConfig['name']} until all agreements have been accepted. Please | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
%strong | ||
#{link_to "edit your application", edit_questionnaires_path} | ||
cbaudouinjr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
and review all agreements before attending. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.form-container | ||
= bs_horizontal_simple_form_for(@agreement, url: url_for(action: @agreement.new_record? ? "create" : "update", controller: "agreements")) do |f| | ||
= f.error_notification | ||
|
||
.form-inputs | ||
= f.input :name | ||
= f.input :agreement_url, hint: "Should be a full https:// URL to a web page or .pdf file", label: t(:agreement_url, scope: 'pages.manage.agreements') | ||
|
||
.form-actions | ||
= f.button :submit, class: 'btn-primary' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= render "layouts/manage/page_title", title: t(:edit, scope: 'pages.manage.agreements') | ||
|
||
= render 'form' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
= render "layouts/manage/page_title", title: t(:title, scope: 'pages.manage.agreements') do | ||
= link_to "New Agreement", new_manage_agreement_path, class: "btn btn-sm btn-outline-secondary" | ||
|
||
%p.text-muted | ||
= t(:notice, scope: 'pages.manage.agreements', hackathon_name: HackathonConfig['name']) | ||
.mb-4 | ||
%table.table.table-striped.table-hover | ||
%thead | ||
%tr | ||
%th | ||
%th | ||
%th | ||
= t(:name, scope: 'pages.manage.agreements') | ||
%th | ||
= t(:agreement_url, scope: 'pages.manage.agreements') | ||
|
||
%tbody | ||
- @agreements.each do |agreement| | ||
%tr | ||
%td | ||
= link_to '<i class="fa fa-pencil"></i>'.html_safe, edit_manage_agreement_path(agreement) | ||
%td | ||
= link_to '<i class="fa fa-trash"></i>'.html_safe, manage_agreement_path(agreement), method: :delete, data: { confirm: "Are you sure? The agreement will be permanently deleted. This action is irreversible." } | ||
%td | ||
%strong | ||
= agreement.name | ||
%td | ||
= agreement.agreement_url |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= render "layouts/manage/page_title", title: t(:new, scope: 'pages.manage.agreements') | ||
|
||
= render 'form' |
Uh oh!
There was an error while loading. Please reload this page.