Skip to content

Commit

Permalink
Merge pull request #11617 from vpereira/sign_up_component
Browse files Browse the repository at this point in the history
Create SignUp component
  • Loading branch information
vpereira committed Sep 16, 2021
2 parents c8f01be + 0ca9cc3 commit 04ffff7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- if CONFIG['proxy_auth_mode'] == :on
- if CONFIG['proxy_auth_register_page'].blank?
- if proxy_auth_enabled?
- if proxy_auth_register_page.blank?
%p Sorry, signing up is currently disabled
- else
%p= link_to 'Use this link to Sign Up', CONFIG['proxy_auth_register_page']
%p= link_to 'Use this link to Sign Up', proxy_auth_register_page
- else
= form_tag(users_path, method: :post, class: 'sign-up', autocomplete: 'off') do
.form-group
Expand Down
20 changes: 20 additions & 0 deletions src/api/app/components/sign_up_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

class SignUpComponent < ApplicationComponent
attr_accessor :submit_btn_text

def initialize(submit_btn_text: 'Sign Up', create_page: false, config: CONFIG)
super

@config = config
@submit_btn_text = sanitize(create_page ? 'Create' : submit_btn_text)
end

def proxy_auth_enabled?
@config['proxy_auth_mode'] == :on
end

def proxy_auth_register_page
@config['proxy_auth_register_page']
end
end
2 changes: 1 addition & 1 deletion src/api/app/views/webui/main/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.card.mb-3
%h5.card-header New here? Sign up!
.card-body
= render partial: 'webui/shared/sign_up', locals: { submit_btn_text: 'Sign Up' }
= render SignUpComponent.new
- if @status_messages.present? || User.admin_session?
= render partial: 'status_messages', locals: { status_messages: @status_messages }
= render(partial: 'latest_updates') if @latest_updates && (::Configuration.anonymous || User.session)
4 changes: 2 additions & 2 deletions src/api/app/views/webui/users/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.card-body
.col-lg-6.pl-0
- if can_register?
%h3= @pagetitle.capitalize
= render partial: 'webui/shared/sign_up', locals: { submit_btn_text: @submit_btn_text.capitalize }
%h3= @pagetitle.titleize
= render SignUpComponent.new(create_page: params.key?(:submit_btn_text))
- else
%p Sorry, sign up is disabled
11 changes: 11 additions & 0 deletions src/api/spec/components/previews/sign_up_component_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class SignUpComponentPreview < ViewComponent::Preview
# Preview at http://HOST:PORT/rails/view_components/sign_up_component/sign_up
def sign_up
render(SignUpComponent.new(config: {}))
end

# Preview at http://HOST:PORT/rails/view_components/sign_up_component/create
def create
render(SignUpComponent.new(config: {}, create_page: true))
end
end
19 changes: 19 additions & 0 deletions src/api/spec/components/sign_up_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'rails_helper'

RSpec.describe SignUpComponent, type: :component do
context 'signing up disabled' do
let(:config) { { 'proxy_auth_mode' => :on } }

it do
expect(render_inline(described_class.new(config: config)).to_html).to have_text('signing up is currently disabled')
end

context 'there is a proxy auth register page' do
let(:config) { { 'proxy_auth_mode' => :on, 'proxy_auth_register_page' => 'http://foo.org' } }

it do
expect(render_inline(described_class.new(config: config)).to_html).to have_text('Use this link to Sign Up')
end
end
end
end

0 comments on commit 04ffff7

Please sign in to comment.