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

Add UI for admin to create org and config messengers #2020

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
78c7316
Test drive creation of organizations by admin
mattwr18 Sep 9, 2024
d710f09
Test drive adding email from address
mattwr18 Sep 9, 2024
b818bd4
Test drive configuring telegram when creating an org
mattwr18 Sep 9, 2024
588beae
Test drive configuring Threema at org creation
mattwr18 Sep 9, 2024
4ff2168
Lint, improve dashboard field types
mattwr18 Sep 9, 2024
9b7887b
Test drive Twilio WhatsApp configuration
mattwr18 Sep 9, 2024
2c0604f
Improve descriptions of specs
mattwr18 Sep 9, 2024
b551f68
Add steps to add and register signal phone number
mattwr18 Sep 10, 2024
9167777
Fix specs to work with both docker and local
mattwr18 Sep 11, 2024
433c8b3
Remove Twilio for new orgs, update field types
mattwr18 Oct 15, 2024
e203ca0
Allow org to be created without Telegram as a channel
mattwr18 Oct 15, 2024
ad2e0d0
Set telegram webhook url on org creation
mattwr18 Oct 15, 2024
041cdd5
Move adding signal phone number to admin portal
mattwr18 Oct 16, 2024
0b9817a
Update admin root to organizations#index
mattwr18 Oct 16, 2024
740e3a9
Add link to register signal
mattwr18 Oct 16, 2024
e450e8b
Refactor signal registration process
mattwr18 Oct 16, 2024
9ea881b
Schedule a job to set the username
mattwr18 Oct 16, 2024
6a774a3
Lint
mattwr18 Oct 16, 2024
482dbaa
Fix failing tests
mattwr18 Oct 17, 2024
a9a9701
Fine tune signal setup
mattwr18 Oct 18, 2024
508cd06
Add job to set profile info for Signal
mattwr18 Oct 22, 2024
5e72aee
Remove undesired change
mattwr18 Nov 5, 2024
b4b7089
Avoid validating signal_server_phone_number
mattwr18 Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ GEM

PLATFORMS
ruby
x86_64-linux
x86_64-linux-musl

DEPENDENCIES
active_model_otp
Expand Down
7 changes: 7 additions & 0 deletions app/components/signal_captcha_form/signal_captcha_form.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.SignalCaptchaForm-useVoiceSection {
margin-top: var(--spacing-unit-s);
}

.SignalCaptchaForm .SubmitButton {
margin-top: var(--spacing-unit);
}
30 changes: 30 additions & 0 deletions app/components/signal_captcha_form/signal_captcha_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= c 'main', **attrs do %>
<%= c 'page_header', styles: [:wide, :inheritBackgroundColor, :xlargePaddingTop] do %>
<%= c 'heading', tag: :h2 do %>
<%= t('.main_heading') %>
<% end %>
<% end %>

<%= c 'section', styles: [:wide] do %>
<p><%= t('.instructions.where_to_generate_html', link: 'https://signalcaptchas.org/registration/generate.html') %></p>
<p><%= t('.instructions.after_solving_captcha') %></p>
<% end %>

<%= c 'section', styles: [:wide] do %>
<%= c 'form', model: organization, url: organization_signal_register_path(organization), method: :post do %>
<%= c 'base_field', id: 'organization[signal][captcha]', label: 'Captcha' do |field| %>
<% c 'textarea', id: 'organization[signal][captcha]', value: nil %>
<% end %>

<section class="SignalCaptchaForm-useVoiceSection">
<label class="BaseField-labelText">
<%= c 'checkbox', id: 'organization[signal][use_voice]' %>
<%= t('.instructions.use_voice.label') %>
</label>
<p class="BaseField-helpText"><%= t('.instructions.use_voice.help') %></p>
</section>

<%= c 'submit_button', label: t('save') %>
<% end %>
<% end %>
<% end %>
13 changes: 13 additions & 0 deletions app/components/signal_captcha_form/signal_captcha_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module SignalCaptchaForm
class SignalCaptchaForm < ApplicationComponent
def initialize(organization:)
super

@organization = organization
end

attr_reader :organization
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.SignalVerifyPhoneNumberForm .SubmitButton {
margin-top: var(--spacing-unit);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<%= c 'main' do %>
<%= c 'page_header', styles: [:wide, :inheritBackgroundColor, :xlargePaddingTop, :spaceBetween] do %>
<%= c 'main', **attrs do %>
<%= c 'page_header', styles: [:wide, :inheritBackgroundColor, :xlargePaddingTop] do %>
<%= c 'heading' do %>
<%= "Verify Signal Number" %>
<%= t('.main_heading') %>
<% end %>
<% end %>

<%= c 'section', styles: [:wide, :largeBottomMargin] do %>
<%= c 'form', model: @organization, url: settings_verify_path, method: :post do %>
<%= c 'base_field', id: 'organization[signal][token]', label: 'Captcha' do |field| %>
<%= c 'form', model: organization, url: organization_signal_verify_path(organization), method: :post do %>
<%= c 'base_field', id: 'organization[signal][token]', label: 'Token' do |field| %>
<% c 'input', id: 'organization[signal][token]' %>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module SignalVerifyPhoneNumberForm
class SignalVerifyPhoneNumberForm < ApplicationComponent
def initialize(organization:)
super

@organization = organization
end

attr_reader :organization
end
end
64 changes: 64 additions & 0 deletions app/controllers/organizations/signal_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

module Organizations
class SignalController < ApplicationController
def captcha_form; end

def register
response = SignalAdapter::RegisterPhoneNumberService.new(organization_id: @organization.id, register_data: register_data).call
case response
Comment on lines +8 to +9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
response = SignalAdapter::RegisterPhoneNumberService.new(organization_id: @organization.id, register_data: register_data).call
case response
case SignalAdapter::RegisterPhoneNumberService.call(organization_id: @organization.id, register_data: register_data)

when Net::HTTPSuccess
redirect_to organization_signal_verify_path
else
handle_error_response(response)
render :captcha_form, status: :unprocessable_entity
end
end

def verify_form; end

def verify
token = params[:organization][:signal][:token]
response = SignalAdapter::VerifyPhoneNumberService.new(organization_id: @organization.id, token: token).call
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same ☝️

case response
when Net::HTTPSuccess
SignalAdapter::SetTrustModeJob.perform_later(signal_server_phone_number: @organization.signal_server_phone_number)
SignalAdapter::SetUsernameJob.perform_later(organization_id: @organization.id)
SignalAdapter::SetProfileInfoJob.perform_later(organization_id: @organization.id)
else
handle_error_response(response)
render :verify_form, status: :unprocessable_entity
end
end

private

def update_params
params.require(:organization).permit(:signal_server_phone_number)
end

def signal_server_phone_number
@organization.signal_server_phone_number
end

def register_data
{
captcha: params[:organization][:signal][:captcha],
use_voice: ActiveModel::Type::Boolean.new.cast(params[:organization][:signal][:use_voice])
}
end

def handle_error_response(response)
error_message = JSON.parse(response.body)['error']
exception = SignalAdapter::BadRequestError.new(error_code: response.code, message: error_message)
context = {
code: response.code,
message: response.message,
headers: response.to_hash,
body: error_message
}
ErrorNotifier.report(exception, context: context)
flash.now[:error] = error_message
end
end
end
84 changes: 0 additions & 84 deletions app/controllers/settings/signal_controller.rb

This file was deleted.

52 changes: 43 additions & 9 deletions app/dashboards/organization_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ class OrganizationDashboard < Administrate::BaseDashboard
created_at: Field::DateTime,
updated_at: Field::DateTime,
upgraded_business_plan_at: Field::DateTime,
threemarb_api_identity: Field::String,
threemarb_api_secret: Field::String,
threemarb_private: Field::String,
twilio_account_sid: Field::String,
twilio_api_key_sid: Field::String,
twilio_api_key_secret: Field::String,
onboarding_allowed: Field::JSONB,
onboarding_data_protection_link: Field::Url,
onboarding_data_processing_consent_additional_info: Field::Text,
Expand All @@ -31,14 +25,24 @@ class OrganizationDashboard < Administrate::BaseDashboard
whats_app_more_info_message: Field::Text,
whats_app_profile_about: Field::Text,
signal_complete_onboarding_link: Field::Url,
whats_app_quick_reply_button_text: Field::JSONB
whats_app_quick_reply_button_text: Field::JSONB,
email_from_address: Field::Email,
telegram_bot_username: Field::String,
telegram_bot_api_key: Field::String,
threemarb_api_identity: Field::String,
threemarb_api_secret: Field::String,
threemarb_private: Field::String,
signal_server_phone_number: SetupSignalLinkField,
messengers_about_text: Field::String
}.freeze

COLLECTION_ATTRIBUTES = %i[
name
contact_person
contributors
users
email_from_address
telegram_bot_username
threemarb_api_identity
signal_server_phone_number
].freeze

SHOW_PAGE_ATTRIBUTES = %i[
Expand All @@ -51,6 +55,35 @@ class OrganizationDashboard < Administrate::BaseDashboard
updated_at
upgraded_business_plan_at
whats_app_more_info_message
email_from_address
telegram_bot_username
threemarb_api_identity
signal_server_phone_number
messengers_about_text
].freeze

FORM_ATTRIBUTES_NEW = %i[
name
contact_person
business_plan
upgrade_discount
whats_app_profile_about
onboarding_data_protection_link
onboarding_data_processing_consent_additional_info
onboarding_imprint_link
onboarding_ask_for_additional_consent
onboarding_additional_consent_heading
onboarding_additional_consent_text
onboarding_allowed
channel_image
email_from_address
telegram_bot_username
telegram_bot_api_key
threemarb_api_identity
threemarb_api_secret
threemarb_private
signal_server_phone_number
messengers_about_text
].freeze

FORM_ATTRIBUTES_EDIT = %i[
Expand All @@ -70,6 +103,7 @@ class OrganizationDashboard < Administrate::BaseDashboard
channel_image
signal_complete_onboarding_link
whats_app_quick_reply_button_text
messengers_about_text
].freeze

COLLECTION_FILTERS = {}.freeze
Expand Down
13 changes: 13 additions & 0 deletions app/fields/setup_signal_link_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require 'administrate/field/base'

class SetupSignalLinkField < Administrate::Field::Base
def setup_signal_url
"/#{resource.id}/signal/register"
end

def signal_server_phone_number
data
end
end
Loading
Loading