-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1170 from alphagov/zendesk-custom-fields
Add functionality to set Zendesk custom fields and form template
- Loading branch information
Showing
22 changed files
with
503 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Zendesk | ||
class CustomField | ||
CUSTOM_FIELDS_DATA = YAML.safe_load_file( | ||
"config/zendesk/custom_fields_data.yml", | ||
permitted_classes: [ | ||
Zendesk::CustomFieldType::DateField, | ||
Zendesk::CustomFieldType::DropDown, | ||
Zendesk::CustomFieldType::Text, | ||
], | ||
).freeze | ||
|
||
class << self | ||
delegate :set, :options_for_name, to: :new | ||
end | ||
|
||
def set(id:, input:) | ||
{ "id" => id, "value" => find_by_id(id).prepare_value(input) } | ||
end | ||
|
||
def options_for_name(name) | ||
find_by_name(name).options.values | ||
end | ||
|
||
private | ||
|
||
def find_by_id(id) | ||
field = CUSTOM_FIELDS_DATA.select { |f| f.id == id }.first | ||
|
||
if field.nil? | ||
raise "Unable to find custom field ID: #{id}. " \ | ||
"Ensure it's defined in config/zendesk/custom_fields_data.yml" | ||
end | ||
|
||
field | ||
end | ||
|
||
def find_by_name(name) | ||
field = CUSTOM_FIELDS_DATA.select { |f| f.name == name }.first | ||
|
||
if field.nil? | ||
raise "Unable to find custom field name: #{name}. " \ | ||
"Ensure it's defined in config/zendesk/custom_fields_data.yml" | ||
end | ||
|
||
field | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Zendesk | ||
module CustomFieldType | ||
class Base | ||
attr_reader :id, :name | ||
|
||
def initialize(args) | ||
@id = args[:id] | ||
@name = args[:name] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Zendesk | ||
module CustomFieldType | ||
class DateField < Base | ||
def prepare_value(input) | ||
date = Date.parse(input) | ||
|
||
date.strftime("%F") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Zendesk | ||
module CustomFieldType | ||
class DropDown < Base | ||
attr_reader :id, :name, :options | ||
|
||
def initialize(args) | ||
@options = args[:options] | ||
|
||
super | ||
end | ||
|
||
def prepare_value(input) | ||
name_tag = find_name_tag(input) | ||
|
||
if name_tag.nil? | ||
raise "Unable to find name tag for '#{input}' to populate custom fields. " \ | ||
"Ensure it's defined in config/zendesk/custom_fields_data.yml" | ||
end | ||
|
||
name_tag | ||
end | ||
|
||
private | ||
|
||
def find_name_tag(input) | ||
options&.key(input) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Zendesk | ||
module CustomFieldType | ||
class Text < Base | ||
def prepare_value(input) | ||
input.to_s | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
- !ruby/object:Zendesk::CustomFieldType::DropDown | ||
name: "[CR] Reason for the request" | ||
id: 7948652819356 | ||
options: | ||
cr_inaccuracy: Factual inaccuracy | ||
cr_user_problem: Content is causing problems for users | ||
cr_new_info: New information (policy, campaign, service) - for example, service start page needed | ||
cr_missing_info: Missing information | ||
cr_policy_process_update: Update - policy or process change | ||
cr_uprating: Uprating - policy or money changes at the new tax year (6 April) | ||
cr_service_review: Service Review | ||
cr_reason_other: Other | ||
- !ruby/object:Zendesk::CustomFieldType::DropDown | ||
name: "[CR] Subject Area" | ||
id: 7949106580380 | ||
options: | ||
cr_benefits: Benefits | ||
cr_births_deaths: Births, death, marriages and care | ||
cr_business_selfemployed: Business and self-employed | ||
cr_childcare_parenting: Childcare and parenting | ||
cr_citizenship: Citizenship and living in the UK | ||
cr_crime_justice: Crime, justice and the law | ||
cr_disabled_people: Disabled people | ||
cr_driving_transport: Driving and transport | ||
cr_education_learning: Education and learning | ||
cr_employing_people: Employing people | ||
cr_environment_countryside: Environment and countryside | ||
cr_health: Health | ||
cr_housing_local_services: Housing and local services | ||
cr_money_tax: Money and tax | ||
cr_passports_travel_living_abroad: Passports, travel and living abroad | ||
cr_visas_immigration: Visas and immigration | ||
cr_working_jobs_pensions: Working, jobs and pensions | ||
cr_subject_other: Other | ||
- !ruby/object:Zendesk::CustomFieldType::DateField | ||
name: "[CR] Deadline" | ||
id: 7949136091548 | ||
- !ruby/object:Zendesk::CustomFieldType::DateField | ||
name: "[CR] Do not publish before" | ||
id: 7949152975772 | ||
- !ruby/object:Zendesk::CustomFieldType::Text | ||
name: "[CR] Deadline (time)" | ||
id: 8250061570844 | ||
- !ruby/object:Zendesk::CustomFieldType::Text | ||
name: "[CR] Do not publish before (time)" | ||
id: 8250075489052 |
Oops, something went wrong.