Compare commits

..

2 Commits

Author SHA1 Message Date
Bilal
853f1207f2 add specs 2020-09-16 12:13:13 +03:00
Bilal
0e8c226b7c show accounts for current user on /accounts endpoint 2020-09-16 12:13:13 +03:00
11 changed files with 79 additions and 62 deletions

View File

@@ -17,7 +17,6 @@ $(document).on "turbolinks:load", ->
when "video_status_update" then @showVideoStatusUpdate(data.content)
when "download_status_update" then @showDownloadStatusUpdate(data.content)
when "conference_recording_ready" then @showDownloadStatusUpdate(data.content)
when "appearance_matching_flash_message" then @showMatchingStatusUpdate(data.content)
showVideoStatusUpdate: (content) ->
$("[data-ujs-target='video-analysis-msg']").replaceWith content
@@ -25,7 +24,3 @@ $(document).on "turbolinks:load", ->
showDownloadStatusUpdate: (content) ->
$(".flash-message").html content
$(".toast").toast('show')
showMatchingStatusUpdate: (content) ->
$(".flash-message").html content
$(".toast").toast('show')

View File

@@ -33,15 +33,4 @@ class ProjectsChannel < ApplicationCable::Channel
content = ApplicationController.render partial: 'application/flash', locals: { flash: flash }
broadcast_to project, event: :conference_recording_ready, content: content
end
def self.appearance_matching_flash_message(project, message, flash_type = :notice)
if (flash_type == :notice)
flash = OpenStruct.new notice: message
else
flash = OpenStruct.new alert: message
end
content = ApplicationController.render partial: 'application/flash', locals: { flash: flash }
broadcast_to project, event: :appearance_matching_flash_message, content: content
end
end

View File

@@ -0,0 +1,5 @@
class Api::AccountsController < Api::ApiController
def show
render jsonapi: current_user.accounts
end
end

View File

@@ -6,10 +6,7 @@ class MatchAppearanceReleasesJob < ApplicationJob
def perform(project, attachments)
filtered_attachments_object = filter_attachments attachments
if filtered_attachments_object[:keys].blank?
ProjectsChannel.appearance_matching_flash_message project, failed_message, :alert
return
end
return if filtered_attachments_object[:keys].blank?
matching_request = MatchingRequest.create project: project, attachments: filtered_attachments_object[:signed_ids]
@@ -20,8 +17,6 @@ class MatchAppearanceReleasesJob < ApplicationJob
handle_matches matches, project, key_signed_id_hash
handle_unmatches matches, project, key_signed_id_hash
matching_request.destroy
ProjectsChannel.appearance_matching_flash_message project, success_message
end
private
@@ -118,12 +113,4 @@ class MatchAppearanceReleasesJob < ApplicationJob
signed_ids: filtered_attachments_signed_ids
}
end
def success_message
I18n.t 'appearance_releases.create.matching_completed'
end
def failed_message
I18n.t 'appearance_releases.create.matching_failed'
end
end

View File

@@ -0,0 +1,21 @@
class SerializableAccount < JSONAPI::Serializable::Resource
type "account"
attributes :name
attribute :users do
@object.users.map do |user|
if user.avatar.attached?
avatar = Rails.application.routes.url_helpers.rails_blob_url(user.avatar, host: AppHost.new.domain_with_port)
else
avatar = nil
end
{
email: user.email,
name: user.full_name,
role: user.account_auths.map(&:role).compact.join(", "),
avatar: avatar
}
end
end
end

View File

@@ -3,14 +3,14 @@
<!-- Position toasts -->
<div class="position-absolute" style="top: 0.5rem; right: 0.5rem;">
<% if flash.alert.present? %>
<div id="flash-message" class="toast fade show bg-black text-white toast-min-w-border-radius" data-autohide="false">
<div class="toast fade show bg-black text-white toast-min-w-border-radius" data-autohide="false">
<div class="toast-body toast-border-left-danger">
<button type="button" class="close text-white ml-2" data-dismiss="toast">&times;</button>
<p><%= flash.alert.html_safe %></p>
</div>
</div>
<% elsif flash.notice.present? %>
<div id="flash-message" class="toast fade show bg-black text-white toast-min-w-border-radius" data-autohide="false">
<div class="toast fade show bg-black text-white toast-min-w-border-radius" data-autohide="false">
<div class="toast-body toast-border-left-primary">
<button type="button" class="close text-white ml-2" data-dismiss="toast">&times;</button>
<p><%= flash.notice.html_safe %></p>
@@ -19,3 +19,4 @@
<% end %>
</div>
</div>

View File

@@ -151,8 +151,6 @@ en:
failed_import: Failed to create appearance release for files listed below
matching_started: Matching started
no_attachments: Failed to import - no attachments
matching_completed: Matching completed. Reload page to see new releases
matching_failed: Matching failed
edit:
heading: Edit Appearance Release
form:

View File

@@ -58,8 +58,6 @@ es:
failed_import: Failed to create appearance release for files listed below (ES)
matching_started: Matching started (ES)
no_attachments: Failed to import - no attachments (ES)
matching_completed: Matching completed (ES)
matching_failed: Matching failed (ES)
form:
guardian_2_info:
heading: Second Guardian Information (if company requires) (ES)

View File

@@ -171,6 +171,7 @@ Rails.application.routes.draw do
post 'user_token' => 'user_token#create'
post 'users' => 'users#create'
resource :profiles, only: [:show]
resource :accounts, only: [:show]
resources :projects, only: [:index] do
resources :broadcasts, only: [:index, :show, :update]
RELEASES.each do |release|

View File

@@ -0,0 +1,48 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::AccountsController, type: :controller do
let(:current_user) { create(:user, first_name: 'Current') }
let(:new_acc) { create(:account, name: 'New Acc') }
let(:different_user) { create(:user, first_name: 'Different') }
let(:new_auth) { create(:account_auth, account: new_acc, user: different_user)}
describe '#show' do
it 'responds with accounts info for the current user' do
sign_in_to_api(current_user)
get :show
expect(response).to be_successful
current_user.accounts.each do |acc|
expect(response.body).to have_content acc.name
acc.users.each do |user|
expect(response.body).to have_content user.full_name
expect(response.body).to have_content user.email
end
end
end
it 'does not include other users accounts' do
different_user.update(account_auths: [new_auth])
sign_in_to_api(current_user)
get :show
expect(response).to be_successful
different_user.accounts.each do |acc|
expect(response.body).not_to have_content acc.name
acc.users.each do |user|
expect(response.body).not_to have_content user.full_name
expect(response.body).not_to have_content user.email
end
end
end
end
end

View File

@@ -13,7 +13,6 @@ describe MatchAppearanceReleasesJob do
it "returns if no attachment is sent" do
expect(MatchingRequest).not_to receive(:create)
attachments = []
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), failure_flash_message, :alert)
MatchAppearanceReleasesJob.perform_now project, attachments
end
@@ -21,7 +20,6 @@ describe MatchAppearanceReleasesJob do
expect(MatchingRequest).not_to receive(:create)
dummy_video = create(:video)
attachments = [dummy_video.file.blob.signed_id]
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), failure_flash_message, :alert)
MatchAppearanceReleasesJob.perform_now project, attachments
end
@@ -46,8 +44,6 @@ describe MatchAppearanceReleasesJob do
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message)
expect {
MatchAppearanceReleasesJob.perform_now project, signed_ids
}.to change{AppearanceRelease.count}.by(1)
@@ -77,8 +73,6 @@ describe MatchAppearanceReleasesJob do
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message)
expect {
MatchAppearanceReleasesJob.perform_now project, signed_ids
}.to change{AppearanceRelease.count}.by(1)
@@ -115,8 +109,6 @@ describe MatchAppearanceReleasesJob do
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message)
MatchAppearanceReleasesJob.perform_now project, signed_ids
expect(AppearanceRelease.last.identifier).to eq mock_match.identifier
@@ -152,8 +144,6 @@ describe MatchAppearanceReleasesJob do
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message)
expect {
MatchAppearanceReleasesJob.perform_now project, signed_ids
}.to change{AppearanceRelease.count}.by(2)
@@ -197,8 +187,6 @@ describe MatchAppearanceReleasesJob do
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message)
MatchAppearanceReleasesJob.perform_now project, signed_ids
expect(AppearanceRelease.last.identifier).to eq mock_match.identifier
@@ -240,8 +228,6 @@ describe MatchAppearanceReleasesJob do
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message)
MatchAppearanceReleasesJob.perform_now project, signed_ids
expect(AppearanceRelease.last.identifier).to eq mock_match.identifier
@@ -289,8 +275,6 @@ describe MatchAppearanceReleasesJob do
expect(BrayniacAI::QrMatching).to receive(:create!).with(qr_matching_payload).and_return(qr_matching_mock_response)
expect(dummy_matching_request).to receive(:destroy)
expect(ProjectsChannel).to receive(:appearance_matching_flash_message).with(kind_of(Project), success_flash_message)
MatchAppearanceReleasesJob.perform_now project, signed_ids
releases = AppearanceRelease.last(2)
@@ -304,14 +288,4 @@ describe MatchAppearanceReleasesJob do
expect(releases[1].contract.attached?).to eq true
end
end
private
def success_flash_message
I18n.t 'appearance_releases.create.matching_completed'
end
def failure_flash_message
I18n.t 'appearance_releases.create.matching_failed'
end
end