Compare commits

..

3 Commits

Author SHA1 Message Date
Bilal
4ae8525ba8 add specs 2020-08-03 16:13:25 +02:00
Bilal
69d4ef0fb2 monkeypatch knock 2020-08-03 15:28:22 +02:00
Bilal
566f8dae05 sign in user when token is fetched 2020-08-03 14:13:49 +02:00
7 changed files with 86 additions and 16 deletions

View File

@@ -1,5 +1,12 @@
# frozen_string_literal: true
require './lib/knock_monkeypatch'
class Api::UserTokenController < Knock::AuthTokenController
include Oath::ControllerHelpers
skip_before_action :verify_authenticity_token
before_action :sign_in_user
rescue_from Exception, :with => :return_error
@@ -10,7 +17,7 @@ class Api::UserTokenController < Knock::AuthTokenController
logger.error "==Handled======="
logger.error exception.message
logger.error exception.backtrace.join("\n")
logger.error "==Handled======="
logger.error "==Handled======="
case exception
when ActiveRecord::RecordNotFound
@status = 404
@@ -27,12 +34,18 @@ class Api::UserTokenController < Knock::AuthTokenController
end
# for some reason render json_errors is not working
# simulating JSON API support
render json: {
# simulating JSON API support
render json: {
errors: [{
status: @status.to_s,
title: @message
}]
}
end
private
def sign_in_user
sign_in(entity)
end
end

View File

@@ -8,10 +8,6 @@
<div class="card-body">
<%= errors_summary_for @release %>
<%= bootstrap_form_with model: @release, method: :post, url: public_send("account_project_contract_template_#{@contract_template.release_type}_release_amendments_path"), local: true do |form| %>
<%= card_field_set_tag t('.signed_contract_preview') do %>
<embed class="embeded-contract-preview" type="application/pdf" src="<%= url_for([@release, :contracts, format: "pdf"]) %>" width="80%" height="1200" />
<% end %>
<%= card_field_set_tag t(".amendment.heading") do %>
<p><%= @contract_template.amendment_clause %></p>
<% end %>

View File

@@ -1138,7 +1138,6 @@ en:
copy_url: Copy sign amendment URL
signature:
heading: Signature
signed_contract_preview: Signed Contract Preview
appearance_releases:
create:
notice: Your release has been signed. Thank you!

View File

@@ -504,7 +504,6 @@ es:
copy_url: Copy sign amendment URL (ES)
signature:
heading: Signature (ES)
signed_contract_preview: Signed Contract Preview (ES)
appearance_releases:
create:
notice: La autorización está firmada. ¡Gracias!

7
lib/knock_monkeypatch.rb Normal file
View File

@@ -0,0 +1,7 @@
module Knock
class AuthTokenController < ApplicationController
skip_before_action :authenticate
alias authenticate_with_token authenticate
before_action :authenticate_with_token
end
end

View File

@@ -0,0 +1,63 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::UserTokenController, type: :request do
let(:current_user) { create(:user) }
describe '#create' do
it 'returns error if credentials are not corrent and does not set cookie' do
post create_endpoint, params: wrong_auth_params
expect(response).to be_successful
expect(response.body).to match record_not_found
expect(cookie_data).to eq nil
end
it 'sends token and cookie if credentials are correct' do
post create_endpoint, params: correct_auth_params
expect(response).to be_successful
expect(response.body).not_to match record_not_found
expect(response.body).to match token_response
expect(cookie_data).not_to eq nil
end
end
private
def wrong_auth_params
{
auth: {
email: 'wrong_email@api-test.com',
password: 'password'
}
}
end
def correct_auth_params
{
auth: {
email: current_user.email,
password: 'password'
}
}
end
def create_endpoint
'/api/v1/user_token'
end
def record_not_found
/Record not found/
end
def token_response
/jwt/
end
def cookie_data
cookies[:_easy_release_session]
end
end

View File

@@ -251,9 +251,6 @@ feature "User managing location releases" do
new_window = window_opened_by { click_link sign_amendment_link }
within_window new_window do
expect(page).to have_content amendments_heading
expect(page).to have_content signed_contract_preview.upcase
expect(page).to have_selector 'embed'
fill_in amendment_signer_name_field, with: 'Big Signer'
draw_signature file_fixture("signature.png"), amendment_signature_field
@@ -693,10 +690,6 @@ feature "User managing location releases" do
t 'public.amendments.new.amendment.heading'
end
def signed_contract_preview
t 'public.amendments.new.signed_contract_preview'
end
def amendment_signer_name_field
'location_release[amendment_signer_name]'
end