Compare commits

...

5 Commits

Author SHA1 Message Date
bilal
253f6dc8f6 add specs to check if United States is default selected country on public signing form 2020-06-10 15:07:02 +02:00
bilal
1bd6d456ab set US as default country in country dropdown 2020-06-10 14:43:31 +02:00
Senad Uka
dc9ba08e1b Upstream sync 2020-06-10 11:19:35 +02:00
Senad Uka
cd5bbaeb62 Upstream sync master 2020-06-09 06:35:40 +02:00
Senad Uka
64bda6eab6 Upstream sync 2020-06-03 17:14:04 +02:00
48 changed files with 530 additions and 190 deletions

View File

@@ -1,13 +1,8 @@
$(document).on "turbolinks:load", ->
# Only connect if a broadcast-token meta tag is present
broadcast_meta = document.querySelector("meta[name=broadcast-token]")
return unless broadcast_meta
broadcastToken = broadcast_meta.getAttribute("content")
App.public = App.cable.subscriptions.create { channel: "BroadcastsChannel", token: broadcastToken },
subscribeToBroadcast = (broadcastToken) -> App.cable.subscriptions.create { channel: "BroadcastsChannel", token: broadcastToken },
connected: ->
# Called when the subscription is ready for use on the server
console.info "Subscribed to channel for broadcast:#{broadcastToken}"
disconnected: ->
# Called when the subscription has been terminated by the server
@@ -17,7 +12,7 @@ $(document).on "turbolinks:load", ->
switch data.event
when "broadcast_stream_update" then @refreshBroadcastVideo(data)
when "stream_recording_ready" then @showBroadcastRecordings(data)
when "file_upload_update" then @refreshFilesTab(data)
when "file_upload_update" then @refreshBroadcastFilesTab(data)
refreshBroadcastVideo: (data) ->
$("#broadcast_updates").html data.status_content
@@ -38,8 +33,12 @@ $(document).on "turbolinks:load", ->
$(".flash-message").html data.flash_content
$("#broadcast_recordings").html data.recordings_content
$("#broadcast_recordings_nav").html data.recordings_nav_content
refreshFilesTab: (data) ->
$("#broadcast_file_list").html data.files_content
$("#broadcast_files_pagination").html data.pagination_content
refreshBroadcastFilesTab: (data) ->
$("#broadcast_file_list_#{data.broadcast_token}").html data.files_content
$("#broadcast_files_pagination_#{data.broadcast_token}").html data.pagination_content
# Create a channel subscription for every broadcast included in the meta tags
get_token = (meta) -> meta.getAttribute("content")
broadcast_tokens = (get_token broadcast_meta for broadcast_meta in document.querySelectorAll("meta[name=broadcast-token]"))
subscribeToBroadcast token for token in broadcast_tokens

View File

@@ -39,7 +39,7 @@ function selectBroadcast(clicked_element, checkbox) {
if (broadcast_ids.length >= 2) {
multi_view_ids = $.param({multi_view_ids: broadcast_ids});
broadcast_url = "/en/projects/" + project_id + "/broadcasts/" + broadcast_ids[0] + "?" + multi_view_ids
$("#multi_view_broadcasts").attr("href", broadcast_url);
$("#multi_view_broadcasts").attr("target", "_blank");
$("#multi_view_broadcasts").removeClass('disabled');

View File

@@ -6,6 +6,11 @@
@import "dropzone/dist/dropzone";
@import 'bootstrap-datepicker';
// Global styles
label {
text-transform: capitalize;
}
// Wordmarks
.suite-wordmark {
font-weight: normal;

View File

@@ -35,11 +35,12 @@ class BroadcastsChannel < ApplicationCable::Channel
recordings_nav_content: recordings_nav_content
end
def self.file_upload_updates(broadcast, files, pagination_content)
def self.broadcast_file_upload_updates(broadcast, files, pagination_content)
files_content = ApplicationController.render partial: "broadcasts/file", collection: files
broadcast_to broadcast, {
event: :file_upload_update,
broadcast_token: broadcast.token,
files_content: files_content,
pagination_content: pagination_content
}

View File

@@ -61,7 +61,8 @@ class AcquiredMediaReleasesController < ApplicationController
:name,
:territory,
:term,
:person_name,
:person_first_name,
:person_last_name,
:person_phone,
:person_email,
:person_company,

View File

@@ -1,6 +1,6 @@
class BroadcastsController < ApplicationController
layout "project"
before_action :set_project
before_action :build_broadcast, only: [:new, :create]
before_action :set_broadcast, only: [:show, :destroy, :update]
@@ -24,19 +24,19 @@ class BroadcastsController < ApplicationController
end
end
def show
@conference_url = url_for [@broadcast.project, @broadcast, :zoom_meeting]
@recordings = @broadcast.broadcast_recordings.order_by_recent.paginate(page: params[:page])
@files = @broadcast.files.order("created_at DESC").paginate(page: params[:files_page])
render layout: 'application'
end
def update
@broadcast.update(broadcast_params)
@files = @broadcast.files.order("created_at DESC").paginate(page: 1)
pagination_content = ApplicationController.render html: helpers.will_paginate(@files, params: { active_tab: params[:active_tab] })
BroadcastsChannel.file_upload_updates(@broadcast, @files, pagination_content)
end
def show
@conference_url = url_for [@broadcast.project, @broadcast, :zoom_meeting]
@recordings = @broadcast.broadcast_recordings.order_by_recent.paginate(page: params[:page])
@files = @broadcast.files.order("created_at DESC").paginate(page: params[:page])
render layout: 'application'
pagination_content = ApplicationController.render html: helpers.will_paginate(@files, params: { active_tab: params[:active_tab], page: params[:page], active_files_tab: params[:active_files_tab] })
BroadcastsChannel.broadcast_file_upload_updates(@broadcast, @files, pagination_content)
end
def destroy
@@ -71,7 +71,10 @@ class BroadcastsController < ApplicationController
def set_multi_view_broadcasts
authorized_broadcasts = authorize policy_scope(Broadcast).where(id: params[:multi_view_ids]).order_by_recent
@multi_view_broadcasts = authorized_broadcasts.map { |b| MultiViewBroadcast.new(b, params[:multi_view_ids]) }
@multi_view_broadcasts = authorized_broadcasts.map do |b|
files_page = params[:files_page] if params[:active_files_tab] == b.token
MultiViewBroadcast.new(b, params[:multi_view_ids], files_page)
end
end
def filtered_broadcasts
@@ -90,20 +93,29 @@ class BroadcastsController < ApplicationController
class MultiViewBroadcast
include Rails.application.routes.url_helpers
delegate_missing_to :@broadcast
def initialize(broadcast, multi_view_ids)
def initialize(broadcast, multi_view_ids, paginate_page)
@broadcast = broadcast
@multi_view_ids = multi_view_ids
@paginate_page = paginate_page
end
def url
project_broadcast_path(@broadcast.project, @broadcast, multi_view_ids: @multi_view_ids, locale: I18n.locale)
end
def files
@broadcast.files.order("created_at DESC").paginate(page: @paginate_page)
end
def uid
id
end
def self.model_name
Broadcast.model_name
end
end
end

View File

@@ -68,7 +68,8 @@ class LocationReleasesController < ApplicationController
:territory_id, :territory_text,
:term_id, :term_text,
:restriction_id, :restriction_text,
:filming_started_on, :filming_ended_on
:filming_started_on, :filming_ended_on,
:filming_hours
)
end

View File

@@ -45,6 +45,9 @@ class Public::AcquiredMediaReleasesController < Public::BaseController
params.require(:acquired_media_release).permit(
:name,
:description,
:person_first_name,
:person_last_name,
:person_email,
:person_title,
:person_phone,
:person_fax,

View File

@@ -6,8 +6,8 @@ class Public::BroadcastsController < Public::BaseController
@conference_url = broadcast_zoom_meeting_url(@broadcast.token)
@multi_view_broadcasts = multi_view_broadcasts
@recordings = @broadcast.broadcast_recordings.order_by_recent.paginate(page: params[:page])
@files = @broadcast.files.order("created_at DESC").paginate(page: params[:page])
@files = @broadcast.files.order("created_at DESC").paginate(page: params[:files_page])
render 'broadcasts/show'
end
@@ -15,8 +15,8 @@ class Public::BroadcastsController < Public::BaseController
@broadcast.update(broadcast_params)
@files = @broadcast.files.order("created_at DESC").paginate(page: 1)
pagination_content = ApplicationController.render html: helpers.will_paginate(@files, params: { active_tab: params[:active_tab] })
BroadcastsChannel.file_upload_updates(@broadcast, @files, pagination_content)
pagination_content = ApplicationController.render html: helpers.will_paginate(@files,params: { active_tab: params[:active_tab], page: params[:page], active_files_tab: params[:active_files_tab] })
BroadcastsChannel.broadcast_file_upload_updates(@broadcast, @files, pagination_content)
end
private
@@ -29,7 +29,10 @@ class Public::BroadcastsController < Public::BaseController
Broadcast.
where(token: params[:multi_view_tokens]).
order_by_recent.
map { |b| MultiViewBroadcast.new(b, params[:multi_view_tokens]) }
map do |b|
files_page = params[:files_page] if params[:active_files_tab] == b.token
MultiViewBroadcast.new(b, params[:multi_view_tokens], files_page)
end
end
def set_broadcast
@@ -38,20 +41,29 @@ class Public::BroadcastsController < Public::BaseController
class MultiViewBroadcast
include Rails.application.routes.url_helpers
delegate_missing_to :@broadcast
def initialize(broadcast, multi_view_tokens)
def initialize(broadcast, multi_view_tokens, paginate_page)
@broadcast = broadcast
@multi_view_tokens = multi_view_tokens
@paginate_page = paginate_page
end
def url
broadcast_url(uid, multi_view_tokens: @multi_view_tokens, host: AppHost.new.domain_with_port, locale: I18n.locale)
end
def files
@broadcast.files.order("created_at DESC").paginate(page: @paginate_page)
end
def uid
token
end
def self.model_name
Broadcast.model_name
end
end
end

View File

@@ -63,7 +63,8 @@ class Public::LocationReleasesController < Public::BaseController
:person_address_zip,
:person_address_country,
:signature_base64,
:locale, :contract_template, :filming_started_on, :filming_ended_on
:locale, :contract_template, :filming_started_on, :filming_ended_on,
:filming_hours
)
end

View File

@@ -43,7 +43,8 @@ class AcquiredMediaRelease < ApplicationRecord
person_address_street1 person_address_street2 person_address_city person_address_state person_address_zip person_address_country
]
CATEGORIES = ["Artwork", "Film Footage", "Video Footage", "Still Photograph"].freeze
# CATEGORIES = ["Artwork", "Film Footage", "Video Footage", "Still Photograph"].freeze
CATEGORIES = ["Film Footage", "Video Footage", "Still Photograph"].freeze
def minor?
false

View File

@@ -117,7 +117,7 @@ class Project < ApplicationRecord
current_zoom_meeting = zoom_meetings.active.first
unless current_zoom_meeting.present?
zoom_user = ZoomUser.free.first || ZoomUser.create
zoom_user = ZoomUser.for_new_meeting
current_zoom_meeting = ZoomMeeting.create(zoom_user: zoom_user, project: self)
end

View File

@@ -1,19 +1,28 @@
require 'zoom_gateway'
require 'securerandom'
class ZoomUser < ApplicationRecord
has_many :zoom_meetings, dependent: :nullify
enum tier: [:basic, :pro]
after_create :create_api_user, if: -> { api_id.nil? }
before_destroy :abort_destroy
scope :current_account, -> { where(account_number: ZoomGateway.ACCOUNT_NUMBER) }
scope :free, -> { where.not(id: ZoomMeeting.active.pluck(:zoom_user_id)) }
def api_email
self.class.api_email(self.id)
end
def create_api_user
self.api_id = gateway.create_host(api_email)
retries ||= 0
self.api_id = gateway.create_host(self.class.generate_api_email)
self.account_number = ZoomGateway.ACCOUNT_NUMBER
save
rescue ZoomGateway::UserAlreadyExists => e
retries += 1
if retries < 3
retry # new api email will be generated automatically
else
raise e
end
end
def delete_api_user
@@ -22,9 +31,22 @@ class ZoomUser < ApplicationRecord
save
end
def current_account?
account_number == ZoomGateway.ACCOUNT_NUMBER
end
# Static methods
class << self
def api_email(id)
"host#{id}@directme"
def generate_api_email
"host#{SecureRandom.random_number(10000)}@directme"
end
def for_new_meeting
user = public_send(ZoomGateway.USER_TYPE_NAME).current_account.free.first
if user.nil?
user = public_send(ZoomGateway.USER_TYPE_NAME).current_account.create
end
user
end
end

View File

@@ -4,7 +4,7 @@
<div class="form-row">
<%= form.text_field :name, required: true, wrapper_class: "col-12" %>
</div>
<%= form.form_group :categories, label: { text: "Categories" } do %>
<%= form.form_group :categories, label: { text: "Licensed property type" } do %>
<% AcquiredMediaRelease::CATEGORIES.each do |category| %>
<%= form.check_box :categories, { multiple: true, label: category }, category, false %>
<% end %>

View File

@@ -1,4 +1,4 @@
<%= bootstrap_form_for model, layout: :inline, remote: true do |form| %>
<%= form.file_field :files, direct_upload: true, multiple: true, accept: "*", hide_label: true, wrapper_class: "w-65 mr-2" %>
<%= form.file_field :files, direct_upload: true, multiple: true, accept: "*", hide_label: true, wrapper_class: "w-65 mr-2", id: "broadcast_files_#{token}" %>
<%= form.button fa_icon("upload", text: "Add File"), class: "btn btn-primary", type: :submit, data: { disable_with: fa_icon("spinner", text: "Adding File") } %>
<% end %>

View File

@@ -0,0 +1,21 @@
<div class="text-center pb-2" id="broadcast_file_form_<%= broadcast.token %>">
<% if controller.class.module_parent.to_s == "Public" %>
<%= render partial: "public/broadcasts/file_form", locals: { model: [broadcast], token: broadcast.token } %>
<% else %>
<%= render partial: "broadcasts/file_form", locals: { model: [broadcast.project, broadcast], token: broadcast.token } %>
<% end %>
</div>
<div class="overflow-auto mh-30">
<ul class="list-unstyled d-flex flex-column align-items-center text-center" id="broadcast_file_list_<%= broadcast.token %>">
<% if files.present? %>
<%= render partial: "broadcasts/file", collection: files %>
<% else %>
<li class="my-3">
Files will appear here.
</li>
<% end %>
</ul>
<div class="d-flex mt-2 justify-content-center" id="broadcast_files_pagination_<%= broadcast.token %>">
<%= will_paginate(files, param_name: 'files_page', params: { active_files_tab: broadcast.token }) if files.present? %>
</div>
</div>

View File

@@ -5,6 +5,12 @@
<% if @broadcast %>
<meta name="broadcast-token" content="<%= @broadcast.token %>">
<% end %>
<% # Subscribe to Action Cable for every broadcast including those in multi-view %>
<% @multi_view_broadcasts.each do |multi_view_broadcast| %>
<% if multi_view_broadcast.token != @broadcast.token %>
<meta name="broadcast-token" content="<%= multi_view_broadcast.token %>">
<% end %>
<% end %>
<% end %>
<% content_for :header do %>
@@ -24,9 +30,7 @@
<div class="d-flex justify-content-between align-items-center">
<h1 class="h3 m-0"><%= @broadcast.name %></h1>
<div class="dropdown">
<a class="btn btn-light border dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Switch View
</a>
<%= link_to "Switch View", "#", class: "btn btn-light border dropdown-toggle", role: "button", id: "dropdownMenuLink", data: { toggle: "dropdown" }, aria: { haspopup: "true", expanded: "false" } %>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<h5 class="dropdown-header">Live Streams</h5>
<span class="dropdown-item active"><%= fa_icon("check", text: @broadcast.name.titleize) %></span>
@@ -72,13 +76,10 @@
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs">
<li class="nav-item">
<a class="<%= class_string("nav-link", "active" => !params[:active_tab].present?) %>" href="#home" data-toggle="tab">Home</a>
<%= link_to "Home", "#home", class: class_string("nav-link", "active" => !params[:active_tab].present?), data: { toggle: "tab" } %>
</li>
<li class="nav-item">
<a class="<%= class_string("nav-link", "active" => params[:active_tab] == "files") %>" href="#files" data-toggle="tab">Files</a>
</li>
<li class="nav-item">
<a class="<%= class_string("nav-link", "active" => params[:active_tab] == "recordings") %>" href="#recordings" data-toggle="tab">Previous Sessions</a>
<%= link_to "Previous Sessions", "#recordings", class: class_string("nav-link", "active" => params[:active_tab] == "recordings"), data: { toggle: "tab" } %>
</li>
</ul>
</div>
@@ -118,29 +119,6 @@
<p class="card-text">If you want to join the ZOOM meeting dedicated to this broadcast, follow the link below.</p>
<%= link_to 'Video Conference', @conference_url, class: 'btn btn-primary btn-block', target: '_blank' %>
</div>
<div class="<%= class_string("tab-pane fade show", "active" => params[:active_tab] == 'files') %>" id="files">
<div class="text-center pb-2" id="broadcast_file_form">
<% if controller.class.module_parent.to_s == "Public" %>
<%= render partial: "public/broadcasts/file_form", locals: { model: [@broadcast], token: @broadcast.token } %>
<% else %>
<%= render partial: "broadcasts/file_form", locals: { model: [@project, @broadcast] } %>
<% end %>
</div>
<div class="overflow-auto mh-30">
<ul class="list-unstyled d-flex flex-column align-items-center text-center" id="broadcast_file_list">
<% if @files.present? %>
<%= render partial: "broadcasts/file", collection: @files %>
<% else %>
<li class="my-3">
Files will appear here.
</li>
<% end %>
</ul>
<div class="d-flex mt-2 justify-content-center" id="broadcast_files_pagination">
<%= will_paginate(@files, params: { active_tab: 'files' }) if @files.present? %>
</div>
</div>
</div>
<div class="<%= class_string("tab-pane fade show", "active" => params[:active_tab] == 'recordings') %>" id="recordings">
<div id="broadcast_recordings">
<%= render partial: 'broadcasts/broadcast_recordings', locals: { recordings: @recordings, broadcast: @broadcast } %>
@@ -149,5 +127,36 @@
</div>
</div>
</div>
<!-- files section -->
<div id="files" class="card shadow-sm mb-3">
<div class="card-header">
<h2 class="h5">Files</h2>
<% if @multi_view_broadcasts %>
<ul class="nav nav-tabs card-header-tabs">
<% @multi_view_broadcasts.each_with_index do |mvb, index| %>
<li class="nav-item">
<%= link_to mvb.name, "#files_broadcast_#{mvb.token}", class: class_string("nav-link", "active" => (params[:active_files_tab] == mvb.token || (params[:active_files_tab].nil? && index == 0))), data: { toggle: "tab" } %>
</li>
<% end %>
</ul>
<% end %>
</div>
<div class="card-body p-3">
<div class="tab-content">
<% if @multi_view_broadcasts.present? %>
<% @multi_view_broadcasts.each_with_index do |mvb, index| %>
<div class="<%= class_string("tab-pane fade show", "active" => (params[:active_files_tab] == mvb.token || (params[:active_files_tab].nil? && index == 0))) %>" id="files_broadcast_<%= mvb.token %>">
<%= render partial: 'broadcasts/files_section', locals: { broadcast: mvb, files: mvb.files } %>
</div>
<% end %>
<% else %>
<div class="tab-pane fade show active" id="files_broadcast_<%= @broadcast.id %>">
<%= render partial: 'broadcasts/files_section', locals: { broadcast: @broadcast, files: @files } %>
</div>
<% end %>
</div>
</div>
</div>
</div>
<div>

View File

@@ -1,9 +1,9 @@
$("#broadcast_file_form").html("<%= j render(partial: "broadcasts/file_form", locals: { model: [@project, @broadcast] }) %>");
$("#broadcast_file_form_<%= @broadcast.token %>").html("<%= j render(partial: "broadcasts/file_form", locals: { model: [@project, @broadcast], token: @broadcast.token }) %>");
var file_id = "#<%= dom_id(@files.first) %>"
if ($("#broadcast_file_list").has(file_id).length == 0) {
$("#broadcast_file_list").html("<%= j render(partial: "broadcasts/file", collection: @files) %>");
$("#broadcast_files_pagination").html("<%= j will_paginate(@files) %>");
if ($("#broadcast_file_list_<%= @broadcast.token %>").has(file_id).length == 0) {
$("#broadcast_file_list_<%= @broadcast.token %>").html("<%= j render(partial: "broadcasts/file", collection: @files) %>");
$("#broadcast_files_pagination_<%= @broadcast.token %>").html("<%= j will_paginate(@files, param_name: 'files_page', params: { active_files_tab: @broadcast.token }) %>");
}
bsCustomFileInput.init();
bsCustomFileInput.init();

View File

@@ -29,6 +29,7 @@
<% if releasable.model_name == "LocationRelease" %>
<%= description_list_pair "Filming Started On:", releasable&.filming_started_on&.strftime("%D") %>
<%= description_list_pair "Filming Ended On:", releasable&.filming_ended_on&.strftime("%D") %>
<%= description_list_pair "Filming Hours:", releasable&.filming_hours %>
<% end %>
<% if contract_template.fee? %>
<%= description_list_pair "Fee:", number_to_currency(contract_template.fee) %>

View File

@@ -11,14 +11,10 @@
<%= field_set_tag content_tag(:span, t(".signer_details.heading"), class: "h6 text-muted text-uppercase") do %>
<div class="form-row">
<%= form.text_field :person_first_name, wrapper_class: "col-sm-3" %>
<%= form.text_field :person_last_name, wrapper_class: "col-sm-3" %>
<%= form.text_field :person_first_name, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_last_name, wrapper_class: "col-sm-6" %>
<%= form.phone_field :person_phone, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.email_field :person_email, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.text_field :person_company, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_title, wrapper_class: "col-sm-6" %>
</div>
@@ -38,6 +34,7 @@
<div class="form-row">
<%= form.text_field :filming_started_on, wrapper_class: "col-sm-6", class: "datepicker-control", readonly: true %>
<%= form.text_field :filming_ended_on, wrapper_class: "col-sm-6", class: "datepicker-control", readonly: true %>
<%= form.text_field :filming_hours, wrapper_class: "col-sm-12" %>
</div>
<% end %>

View File

@@ -13,14 +13,10 @@
<%= field_set_tag content_tag(:span, t(".signer_details.heading"), class: "h6 text-muted text-uppercase") do %>
<div class="form-row">
<%= form.text_field :person_first_name, wrapper_class: "col-sm-3" %>
<%= form.text_field :person_last_name, wrapper_class: "col-sm-3" %>
<%= form.text_field :person_first_name, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_last_name, wrapper_class: "col-sm-6" %>
<%= form.phone_field :person_phone, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.email_field :person_email, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.text_field :person_company, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_title, wrapper_class: "col-sm-6" %>
</div>

View File

@@ -15,12 +15,12 @@
<%= card_field_set_tag t(".acquired_media_info.heading") do %>
<div class="form-row">
<%= form.text_field :name, required: true, wrapper_class: "col-12", label: 'Licensor ("Owner")' %>
<%= form.text_field :name, required: true, wrapper_class: "col-12" %>
</div>
<div class="form-row">
<%= form.text_area :description, wrapper_class: "col-12" %>
</div>
<%= form.form_group :categories, label: { text: "Categories" } do %>
<%= form.form_group :categories, label: { text: "Licensed property type" } do %>
<% AcquiredMediaRelease::CATEGORIES.each do |category| %>
<%= form.check_box :categories, { multiple: true, label: category }, category, false %>
<% end %>
@@ -31,8 +31,11 @@
<%= card_field_set_tag t(".personal_info.heading") do %>
<div class="form-row">
<%= form.text_field :person_first_name, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_last_name, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_title, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_phone, wrapper_class: "col-sm-6", label: 'Phone' %>
<%= form.phone_field :person_phone, wrapper_class: "col-sm-6", label: 'Phone' %>
<%= form.email_field :person_email, wrapper_class: "col-sm-6", label: 'Email' %>
<%= form.text_field :person_fax, wrapper_class: "col-sm-6", label: 'Fax' %>
</div>
<%= render "shared/address_fields", form: form, subject: "person" %>

View File

@@ -1,4 +1,4 @@
<%= bootstrap_form_for model, url: broadcast_url(token: token), layout: :inline, remote: true do |form| %>
<%= form.file_field :files, direct_upload: true, multiple: true, accept: "*", hide_label: true, wrapper_class: "w-65 mr-2" %>
<%= form.file_field :files, direct_upload: true, multiple: true, accept: "*", hide_label: true, wrapper_class: "w-65 mr-2", id: "broadcast_files_#{token}" %>
<%= form.button fa_icon("upload", text: "Add File"), class: "btn btn-primary", type: :submit, data: { disable_with: fa_icon("spinner", text: "Adding File") } %>
<% end %>

View File

@@ -1,9 +1,9 @@
$("#broadcast_file_form").html("<%= j render(partial: "public/broadcasts/file_form", locals: { model: [@project, @broadcast], token: @broadcast.token }) %>");
$("#broadcast_file_form_<%= @broadcast.token %>").html("<%= j render(partial: "public/broadcasts/file_form", locals: { model: [@project, @broadcast], token: @broadcast.token }) %>");
var file_id = "#<%= dom_id(@files.first) %>"
if ($("#broadcast_file_list").has(file_id).length == 0) {
$("#broadcast_file_list").html("<%= j render(partial: "broadcasts/file", collection: @files) %>");
$("#broadcast_files_pagination").html("<%= j will_paginate(@files) %>");
if ($("#broadcast_file_list_<%= @broadcast.token %>").has(file_id).length == 0) {
$("#broadcast_file_list_<%= @broadcast.token %>").html("<%= j render(partial: "broadcasts/file", collection: @files) %>");
$("#broadcast_files_pagination_<%= @broadcast.token %>").html("<%= j will_paginate(@files) %>");
}
bsCustomFileInput.init();

View File

@@ -27,11 +27,7 @@
<%= form.text_field :person_first_name, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_last_name, wrapper_class: "col-sm-6" %>
<%= form.phone_field :person_phone, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.email_field :person_email, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.text_field :person_company, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_title, wrapper_class: "col-sm-6" %>
</div>
@@ -45,6 +41,7 @@
<div class="form-row">
<%= form.text_field :filming_started_on, wrapper_class: "col-sm-6", class: "datepicker-control", readonly: true %>
<%= form.text_field :filming_ended_on, wrapper_class: "col-sm-6", class: "datepicker-control", readonly: true %>
<%= form.text_field :filming_hours, wrapper_class: "col-sm-12" %>
</div>
<% end %>

View File

@@ -27,11 +27,7 @@
<%= form.text_field :person_first_name, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_last_name, wrapper_class: "col-sm-6" %>
<%= form.phone_field :person_phone, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.email_field :person_email, wrapper_class: "col-sm-6" %>
</div>
<div class="form-row">
<%= form.text_field :person_company, wrapper_class: "col-sm-6" %>
<%= form.text_field :person_title, wrapper_class: "col-sm-6" %>
</div>

View File

@@ -11,6 +11,6 @@
</div>
<%= form.form_group "#{field_name_prefix}address_country" do %>
<%= form.label "#{field_name_prefix}address_country" %>
<%= form.country_select "#{field_name_prefix}address_country", { priority: %w(US CA), prompt: true }, class: "form-control custom-select" %>
<%= form.country_select "#{field_name_prefix}address_country", { selected: 'US', priority: %w(US CA), prompt: true }, class: "form-control custom-select" %>
<% end %>

View File

@@ -305,6 +305,8 @@ en:
graphics_only_edl_file: If you do not upload a Graphics Only EDL, the software will not generate a Graphics Cue List.
label:
acquired_media_release:
description: Description of licensed property
name: Name of licensed property
person_address: Address
person_address_city: City
person_address_country: Country
@@ -314,6 +316,8 @@ en:
person_address_zip: Zip code
person_company: Company
person_email: Email address
person_first_name: Licensor/Owner first name
person_last_name: Licensor/Owner last name
person_name: Name
person_phone: Phone number
person_title: Title
@@ -327,16 +331,23 @@ en:
address_city: City
address_country: Country
address_state: State
address_street1: Address
address_street1: Address of Property
address_street2: Address (Line 2)
address_zip: Zip code
filming_ended_on: Filming end date
filming_started_on: Filming start date
name: Name of property
person_address_city: City
person_address_country: Country
person_address_state: State
person_address_street1: Address
person_address_street2: Address (Line 2)
person_address_zip: Zip code
person_first_name: Owner first name
person_last_name: Owner last name
material_release:
description: Description of licensed material
name: Name of licensed material
person_address: Address
person_address_city: City
person_address_country: Country
@@ -346,6 +357,8 @@ en:
person_address_zip: Zip code
person_company: Company
person_email: Email address
person_first_name: Licensor/Owner first name
person_last_name: Licensor/Owner last name
person_name: Name
person_phone: Phone number
person_title: Title
@@ -544,7 +557,7 @@ en:
photos:
heading: 4 of 4 Photos
signer_details:
heading: 2 of 4 Signer Details
heading: 2 of 4 Owner Details
index:
actions:
new: Import Release
@@ -578,7 +591,7 @@ en:
photos:
heading: 4 of 4 Photos
signer_details:
heading: 2 of 4 Signer Details
heading: 2 of 4 Licensor/Owner Details
index:
actions:
new: Import Release
@@ -741,9 +754,7 @@ en:
legal:
heading: Legal
personal_info:
heading: Person Details
personal_info:
heading: Signer's Contact Information
heading: Licensor/Owner Contact Information
signature:
heading: Signature
appearance_releases:
@@ -782,7 +793,7 @@ en:
new:
cancel: Cancel
contact_info:
heading: Signer Information
heading: Owner Contact Information
filming_info:
heading: Filming Information
legal:
@@ -797,7 +808,7 @@ en:
new:
cancel: Cancel
contact_info:
heading: Signer's Contact Information
heading: Licensor/Owner Contact Information
legal:
heading: Legal
release_info:

View File

@@ -0,0 +1,7 @@
class AssignAccountNumberAndTypeToZoomUsers < ActiveRecord::DataMigration
def up
ZoomUser.find_each do |zu|
zu.update account_number: ENV.fetch('ZOOM_ACCOUNT_NUMBER'), tier: (ENV['ZOOM_USER_TYPE'] == 'pro' ? 1 : 0)
end
end
end

View File

@@ -0,0 +1,6 @@
class AddAccountNumberAndTypeToZoomUsers < ActiveRecord::Migration[6.0]
def change
add_column :zoom_users, :account_number, :string
add_column :zoom_users, :tier, :integer, default: 0
end
end

View File

@@ -0,0 +1,5 @@
class AddFilmingHoursToLocationReleases < ActiveRecord::Migration[6.0]
def change
add_column :location_releases, :filming_hours, :text
end
end

View File

@@ -1592,7 +1592,9 @@ CREATE TABLE public.zoom_users (
id bigint NOT NULL,
api_id character varying,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
updated_at timestamp(6) without time zone NOT NULL,
account_number character varying,
tier integer DEFAULT 0
);
@@ -3499,6 +3501,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200427073429'),
('20200428091105'),
('20200507110804'),
('20200512161738');
('20200512161738'),
('20200526113516');

View File

@@ -3,6 +3,7 @@ class ZoomGateway
class MeetingExpired < StandardError; end
class UserNotFound < StandardError; end
class TooManyHosts < StandardError; end
class UserAlreadyExists < StandardError; end
class << self
def USER_TYPE_NAME
@@ -23,8 +24,12 @@ class ZoomGateway
"#{self.USER_TYPE_NAME}-directme-host"
end
def ACCOUNT_NUMBER
ENV['ZOOM_ACCOUNT_NUMBER']
end
def enable_recordings?
ENV['ZOOM_ENABLE_RECORDINGS'] == '1'
ENV['ZOOM_ENABLE_RECORDINGS'] == 'true'
end
def apply_limits?
@@ -97,6 +102,8 @@ class ZoomGateway
raise UserNotFound, error.message
elsif error.status_code == 3001
raise MeetingExpired, error.message
elsif error.status_code == 1005
raise UserAlreadyExists, error.message
else
raise error
end

View File

@@ -50,4 +50,21 @@ RSpec.describe BroadcastsChannel, type: :channel do
})
end
end
describe ".broadcast_file_upload_updates" do
it 'broadcasts to the channel with the right data' do
broadcast = create(:broadcast, :with_stream, :with_files, skip_create_callback: true)
files_content = ApplicationController.render partial: "broadcasts/file", collection: broadcast.files
expect {
BroadcastsChannel.broadcast_file_upload_updates(broadcast, broadcast.files, "pagination_content")
}.to have_broadcasted_to(broadcast).with({
event: 'file_upload_update',
broadcast_token: broadcast.token,
files_content: files_content,
pagination_content: "pagination_content"
})
end
end
end

View File

@@ -111,17 +111,6 @@ RSpec.describe BroadcastsController, type: :controller do
end
end
describe "#update" do
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, project: project ) }
it "uploads files to broadcast" do
patch :update, params: { project_id: project.id, id: broadcast.id, broadcast: file_params }, xhr: true
expect(broadcast.files.count).to eq(1)
expect(broadcast.files.first.filename).to eq("contract.pdf")
end
end
describe "#show" do
let(:broadcast) { create(:broadcast, project: project, name: "Another Broadcast") }
@@ -198,6 +187,25 @@ RSpec.describe BroadcastsController, type: :controller do
end
end
describe "#update" do
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, project: project ) }
it "uploads files to broadcast" do
patch :update, params: { project_id: project.id, id: broadcast.id, broadcast: file_params }, xhr: true
expect(broadcast.files.count).to eq(1)
expect(broadcast.files.first.filename).to eq("contract.pdf")
end
it "sends an update to the broadcasts channel" do
allow(BroadcastsChannel).to receive(:broadcast_file_upload_updates)
patch :update, params: { project_id: project.id, id: broadcast.id, broadcast: file_params }, xhr: true
expect(BroadcastsChannel).to have_received(:broadcast_file_upload_updates)
end
end
describe "#destroy" do
let!(:broadcast_2) { create(:broadcast, :with_stream, skip_create_callback: true, project: project, name: "Another Broadcast") }

View File

@@ -92,6 +92,14 @@ RSpec.describe Public::BroadcastsController, type: :controller do
expect(broadcast.files.count).to eq(1)
expect(broadcast.files.first.filename).to eq("contract.pdf")
end
it "sends an update to the broadcasts channel" do
allow(BroadcastsChannel).to receive(:broadcast_file_upload_updates)
patch :update, params: { token: broadcast.token, broadcast: file_params }, xhr: true
expect(BroadcastsChannel).to have_received(:broadcast_file_upload_updates)
end
end
after do

View File

@@ -1,5 +1,9 @@
require 'zoom_gateway'
FactoryBot.define do
factory :zoom_user do
account_number ZoomGateway.ACCOUNT_NUMBER
trait ZoomGateway.USER_TYPE_NAME
trait :with_api_id do
api_id "api_user_id"
end

View File

@@ -5,6 +5,13 @@ feature "User managing acquired_media releases" do
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario "United States is default country" do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_acquired_media_release_path(project.account, project, contract_template)
expect(country_field_value).to eq "US"
end
scenario "creating a release", js: true do
contract_template = create(:contract_template, project: project)
@@ -19,7 +26,7 @@ feature "User managing acquired_media releases" do
click_button "I have read and agree to the above"
expect(AcquiredMediaRelease.last.categories).to include("Artwork")
expect(AcquiredMediaRelease.last.categories).to include("Video Footage")
expect(AcquiredMediaRelease.last.categories).to include("Still Photograph")
expect(page).to have_content("Your release was successfully submitted. Thank you.")
end
@@ -205,12 +212,16 @@ feature "User managing acquired_media releases" do
private
def country_field_value
find_field("acquired_media_release[person_address_country]").value
end
def acquired_media_name_field
"acquired_media_release[name]"
end
def acquired_media_category_fields
find(:css, "#acquired_media_release_categories_artwork").set(true)
find(:css, "#acquired_media_release_categories_video_footage").set(true)
find(:css, "#acquired_media_release_categories_still_photograph").set(true)
end

View File

@@ -46,15 +46,17 @@ feature "User managing broadcasts" do
expect(page).to have_content("Live stream is waiting to begin.")
expect(page).to have_content("Copy URL")
click_on "Files"
expect(page).to have_content("contract.pdf")
within "#files" do
expect(page).to have_content("contract.pdf")
end
click_on "Previous Sessions"
expect(page).to have_content(recording.download_file_name)
end
scenario "visit multi-view broadcast page", js: true do
broadcasts = create_list(:broadcast, 4, :with_stream, project: project)
broadcast_one = create(:broadcast, :with_stream, :with_files, name: "Broadcast 1", project: project)
broadcast_two = create(:broadcast, :with_stream, :with_files, name: "Broadcast 2", project: project)
visit project_broadcasts_path(project)
click_checkboxes
@@ -64,8 +66,16 @@ feature "User managing broadcasts" do
expect(page).to have_content("Switch View")
click_on "Switch View"
expect(page).to have_link(broadcasts.first.name)
expect(page).to have_link(broadcasts.second.name)
expect(page).to have_link("Broadcast 1")
expect(page).to have_link("Broadcast 2")
within "#files" do
click_on "Broadcast 1"
expect(page).to have_content("contract.pdf")
click_on "Broadcast 2"
expect(page).to have_content("contract.pdf")
end
end
end
end
@@ -77,7 +87,7 @@ feature "User managing broadcasts" do
end
def click_checkboxes
all('input[type="checkbox"]')[0].click
all('input[type="checkbox"]')[1].click
all('input[type="checkbox"]')[2].click
end
end

View File

@@ -5,6 +5,13 @@ feature "User managing location releases" do
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario "United States is default country" do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_location_release_path(project.account, project, contract_template)
expect(country_field_value).to eq "US"
end
scenario "creating a release", js: true do
contract_template = create(:contract_template, project: project)
@@ -17,6 +24,7 @@ feature "User managing location releases" do
fill_in person_phone_field, with: "555-555-5555"
fill_in person_email_field, with: "jane.doe@test.com"
fill_in person_address_street1_field, with: "100 Broadway"
fill_in filming_hours_field, with: "04:00 - 22:00"
draw_signature file_fixture("signature.png"), "location_release_signature_base64"
end
@@ -51,6 +59,7 @@ feature "User managing location releases" do
by "filling out the remaining information" do
fill_in_release_fields name: "Test Location Release"
fill_in filming_hours_field, with: "04:00 - 22:00"
click_button create_release_button
expect(page).to have_content(create_release_notice)
expect(page).to have_photo("location_photo.png")
@@ -136,6 +145,7 @@ feature "User managing location releases" do
:native,
project: project,
name: "Benny's Burritos",
filming_hours: "06:00 - 20:00",
tag_list: "Restaurant",
notes: [
build(:note,
@@ -172,6 +182,8 @@ feature "User managing location releases" do
expect(pdf_body).to have_content("Restaurant")
expect(pdf_body).to have_content photos_heading.upcase
expect(pdf_body).to have_content("location_photo.png")
expect(pdf_body).to have_content("Filming Hours")
expect(pdf_body).to have_content("06:00 - 20:00")
end
context "when the user is associate" do
@@ -190,6 +202,10 @@ feature "User managing location releases" do
private
def country_field_value
find_field("location_release[person_address_country]").value
end
def photos_heading(photos_count = 1)
t 'contracts.photos.heading', count: photos_count
end
@@ -222,6 +238,10 @@ feature "User managing location releases" do
"location_release[person_phone]"
end
def filming_hours_field
"location_release[filming_hours]"
end
def have_photo(filename, attr: "src")
have_selector("img[#{attr}*='#{filename}']")
end

View File

@@ -5,6 +5,13 @@ feature "User managing material releases" do
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario "United States is default country" do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_material_release_path(project.account, project, contract_template)
expect(country_field_value).to eq "US"
end
scenario "creating a release", js: true do
contract_template = create(:contract_template, project: project)
@@ -180,6 +187,10 @@ feature "User managing material releases" do
private
def country_field_value
find_field("material_release[person_address_country]").value
end
def photos_heading(photos_count = 1)
t 'contracts.photos.heading', count: photos_count
end

View File

@@ -5,6 +5,13 @@ feature "User managing talent releases" do
let(:project) { create(:project, members: current_user, account: current_user.primary_account) }
context "when signed out" do
scenario "United States is default country" do
contract_template = create(:contract_template, project: project)
visit new_account_project_contract_template_talent_release_path(project.account, project, contract_template)
expect(country_field_value).to eq "US"
end
scenario "creating a release for an adult", js: true do
contract_template = create(:contract_template, project: project)
@@ -274,6 +281,10 @@ feature "User managing talent releases" do
private
def country_field_value
find_field("talent_release[person_address_country]").value
end
def photos_heading(photos_count = 1)
t 'contracts.photos.heading', count: photos_count
end

View File

@@ -521,8 +521,8 @@ feature "User performs video analysis" do
new_path = polymorphic_path([:new, video, release, :video_release_confirmation])
first("form[action='#{new_path}']").click_button
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -572,8 +572,8 @@ feature "User performs video analysis" do
new_path = polymorphic_path([:new, video, release, :video_release_confirmation])
first("form[action='#{new_path}']").click_button
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -748,8 +748,8 @@ feature "User performs video analysis" do
open_graphics_element_modal(video)
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -796,8 +796,8 @@ feature "User performs video analysis" do
open_graphics_element_modal(video)
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -1188,8 +1188,8 @@ feature "User performs video analysis" do
open_audio_confirmation_modal
expect(page).to have_field("Origin", with: "Original Music")
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
expect(page).to have_field("Source EDL", with: "Audio")
click_on "Show/Hide EDL Events"
@@ -1219,10 +1219,10 @@ feature "User performs video analysis" do
expect(page).to have_field("Source EDL", with: "All Tracks")
expect(page).to have_field("Channel", with: "A1")
expect(page).to have_field("Origin", with: "Library Music")
expect(page).to have_field("Timecode in", with: "01:00:00:00")
expect(page).to have_field("Timecode In", with: "01:00:00:00")
expect(page).to have_field("Timecode out", with: "01:00:02:00")
expect(page).to have_field("Duration", with: "00:00:02")
expect(page).to have_field("Source file name", with: "source_file_name.wav")
expect(page).to have_field("Source File Name", with: "source_file_name.wav")
expect(page).to have_field("Clip name", with: "clip_name")
expect(page).to have_field("Description", with: "description")
@@ -1323,8 +1323,8 @@ feature "User performs video analysis" do
open_unreleased_modal(video)
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -1371,8 +1371,8 @@ feature "User performs video analysis" do
open_unreleased_modal(video)
expect(page).to have_content "Timecode in"
expect(page).to have_content "Source file name"
expect(page).to have_content "Timecode In"
expect(page).to have_content "Source File Name"
click_on "Show/Hide EDL Events"
within "#edl_events" do
@@ -1445,7 +1445,7 @@ feature "User performs video analysis" do
first("#suggested_matches form[action='#{new_path}']").click_button
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
within "form[action='#{create_path}']" do
click_button "Confirm Release"
@@ -1462,7 +1462,7 @@ feature "User performs video analysis" do
$("#audio_matches .releasable-match button")[0].click()
JS
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
end
def select_option(select_id, text)
@@ -1486,7 +1486,7 @@ feature "User performs video analysis" do
JS
expect(page).to have_field("Origin", with: "Library Music")
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
within "form[action='#{create_path}']" do
expect(page).to have_selector("#matched_file_name", text: "library_file_name")
@@ -1518,7 +1518,7 @@ feature "User performs video analysis" do
first("form[action='#{new_path}']", text: text).click_button
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
within "form[action='#{create_path}']" do
click_button "Confirm Release"
@@ -1536,7 +1536,7 @@ feature "User performs video analysis" do
first("#music_releases form[action='#{new_path}']", text: text).click_button
expect(page).to have_field("Origin", with: "Original Music")
expect(page).to have_content "Timecode in"
expect(page).to have_content "Timecode In"
within "form[action='#{create_path}']" do
select "Vocal", from: "Music type"

View File

@@ -66,19 +66,26 @@ RSpec.describe ZoomGateway do
end
context '.enable_recordings?' do
it 'is truthy when ZOOM_ENABLE_RECORDINGS is set to 1' do
stub_env_variable('ZOOM_ENABLE_RECORDINGS', '1')
it 'is truthy when ZOOM_ENABLE_RECORDINGS is set to true' do
stub_env_variable('ZOOM_ENABLE_RECORDINGS', 'true')
expect(ZoomGateway.enable_recordings?).to be_truthy
end
it 'is falsey otherwise' do
stub_env_variable('ZOOM_ENABLE_RECORDINGS', '0')
stub_env_variable('ZOOM_ENABLE_RECORDINGS', '1')
expect(ZoomGateway.enable_recordings?).to be_falsey
stub_env_variable('ZOOM_ENABLE_RECORDINGS', '2')
stub_env_variable('ZOOM_ENABLE_RECORDINGS', 'false')
expect(ZoomGateway.enable_recordings?).to be_falsey
end
end
context '.ACCOUNT_NUMBER' do
it 'depends on ENV["ZOOM_ACCOUNT_NUMBER"]' do
stub_env_variable('ZOOM_ACCOUNT_NUMBER', 'xxx-yyy-zzz')
expect(ZoomGateway.ACCOUNT_NUMBER).to eq('xxx-yyy-zzz')
end
end
end
describe ".find_meeting" do
@@ -117,9 +124,7 @@ RSpec.describe ZoomGateway do
end
it 'raises an exception' do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with('ZOOM_USER_TYPE').and_return('pro')
allow(ENV).to receive(:[]).with('ZOOM_PRO_USERS_LIMIT').and_return('2')
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_PRO_USERS_LIMIT: 2)
expect { gateway.create_host('host-email@address') }.to raise_error(ZoomGateway::TooManyHosts)
end
@@ -133,11 +138,4 @@ RSpec.describe ZoomGateway do
end
end
private
def stub_env_variable(name, value)
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with(name.to_s).and_return(value.to_s)
end
end

View File

@@ -147,10 +147,4 @@ describe AppHost do
expect(app_domain.protocol).to eq :http
end
end
private
def stub_env(key, value)
allow(ENV).to receive(:fetch).with(key).and_return(value)
end
end

View File

@@ -79,7 +79,7 @@ RSpec.describe Project, type: :model do
context 'there is no meeting' do
context 'there is a free user available' do
let!(:free_zoom_user) { create(:zoom_user, api_id: 'user_id') }
let!(:free_zoom_user) { create(:zoom_user, :with_api_id) }
before do
allow_any_instance_of(ZoomGateway).to receive(:create_meeting).and_return('new-meeting-id')

View File

@@ -1,3 +1,4 @@
require 'zoom_gateway'
require 'rails_helper'
RSpec.describe ZoomUser, type: :model do
@@ -5,6 +6,10 @@ RSpec.describe ZoomUser, type: :model do
it { is_expected.to have_many(:zoom_meetings).dependent(:nullify) }
end
describe "enums" do
it { is_expected.to define_enum_for(:tier).with_values([:basic, :pro]) }
end
describe 'callbacks' do
let(:zoom_user) { build(:zoom_user) }
@@ -22,10 +27,120 @@ RSpec.describe ZoomUser, type: :model do
zoom_user.save
expect(zoom_user.api_id).to eq "retrieved_api_id"
end
it 'assigns current account number' do
allow_any_instance_of(ZoomGateway).to receive(:create_host).and_return("retrieved_api_id")
ENV['ZOOM_ACCOUNT_NUMBER'] = 'xxx-yyy-zzz'
zoom_user.save
expect(zoom_user.account_number).to eq 'xxx-yyy-zzz'
end
end
context '#before_destroy' do
pending 'aborts if there is api_id assigned'
end
end
describe 'scopes' do
context '.current_account' do
before do
create_list(:zoom_user, 10, :with_api_id, account_number: 'first-account-id')
create_list(:zoom_user, 25, :with_api_id, account_number: 'second-account-id')
end
it 'only returns users from currently set account' do
ENV['ZOOM_ACCOUNT_NUMBER'] = 'first-account-id'
expect(ZoomUser.current_account.count).to eq 10
expect(ZoomUser.current_account.pluck(:account_number).uniq.count).to eq 1
expect(ZoomUser.current_account.pluck(:account_number).uniq.first).to eq 'first-account-id'
end
end
context '.free' do
let(:free_user) { create(:zoom_user, :with_api_id) }
let(:busy_user) { create(:zoom_user, :with_api_id) }
let(:second_busy_user) { create(:zoom_user, :with_api_id) }
let!(:meeting_started) { create(:zoom_meeting, zoom_user: busy_user, status: :started) }
let!(:meeting_created) { create(:zoom_meeting, zoom_user: second_busy_user, status: :created) }
it 'returns only the users without started / created meetings' do
users = ZoomUser.free
expect(users).to include(free_user)
expect(users).not_to include(busy_user)
expect(users).not_to include(second_busy_user)
end
end
end
describe '.current_account?' do
let(:zoom_user) { create(:zoom_user, :with_api_id, account_number: 'xxx-xxx-xxx') }
it 'returns true if it belongs to currently set account' do
ENV['ZOOM_ACCOUNT_NUMBER'] = 'xxx-xxx-xxx'
expect(zoom_user.current_account?).to be_truthy
end
it 'returns false if it doesn\'t belong to currently set account' do
ENV['ZOOM_ACCOUNT_NUMBER'] = 'yyy-yyy-yyy'
expect(zoom_user.current_account?).to be_falsey
end
end
context 'static methods' do
describe '.generate_api_email' do
it 'contains @' do
expect(ZoomUser.generate_api_email).to include('@')
end
end
describe '.for_new_meeting' do
let(:a_basic) { create(:zoom_user, :with_api_id, account_number: 'aaa', tier: :basic) }
let(:b_basic) { create(:zoom_user, :with_api_id, account_number: 'bbb', tier: :basic) }
let(:a_pro) { create(:zoom_user, :with_api_id, account_number: 'aaa', tier: :pro) }
let(:b_pro) { create(:zoom_user, :with_api_id, account_number: 'bbb', tier: :pro) }
it 'picks free user of requested type from current account' do
[a_basic, a_pro, b_basic, b_pro]
stub_env_variables(ZOOM_USER_TYPE: 'basic', ZOOM_ACCOUNT_NUMBER: 'aaa')
expect(ZoomUser.for_new_meeting).to eq(a_basic)
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_ACCOUNT_NUMBER: 'aaa')
expect(ZoomUser.for_new_meeting).to eq(a_pro)
stub_env_variables(ZOOM_USER_TYPE: 'basic', ZOOM_ACCOUNT_NUMBER: 'bbb')
expect(ZoomUser.for_new_meeting).to eq(b_basic)
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_ACCOUNT_NUMBER: 'bbb')
expect(ZoomUser.for_new_meeting).to eq(b_pro)
end
context 'no free user' do
before do
allow_any_instance_of(ZoomGateway).to receive(:create_host).and_return('host-id')
end
it 'creates new user if there is no requested user free available under account' do
[a_basic, a_pro, b_basic]
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_ACCOUNT_NUMBER: 'bbb')
expect_any_instance_of(ZoomGateway).to receive(:create_host)
ZoomUser.for_new_meeting
end
it 'creates new user if requested user is busy' do
[a_basic, a_pro, b_basic, b_pro]
stub_env_variables(ZOOM_USER_TYPE: 'pro', ZOOM_ACCOUNT_NUMBER: 'aaa')
create(:zoom_meeting, zoom_user: a_pro, status: :started)
expect_any_instance_of(ZoomGateway).to receive(:create_host)
ZoomUser.for_new_meeting
end
end
end
end
end

View File

@@ -0,0 +1,16 @@
module EnvHelper
def stub_env_variables(vars)
allow(ENV).to receive(:[]).and_call_original
vars.each do |variable, value|
allow(ENV).to receive(:[]).with(variable.to_s).and_return(value)
end
end
def stub_env_variable(key, value)
stub_env_variables({key => value})
end
end
RSpec.configure do |config|
config.include EnvHelper
end