implement reset token

This commit is contained in:
Bilal
2020-07-14 10:42:11 +02:00
parent 4c49a5db03
commit 1e78eaae3f
6 changed files with 53 additions and 0 deletions

View File

@@ -33,6 +33,11 @@ class BroadcastsController < ApplicationController
end end
def update def update
unless params.has_key?(:broadcast)
@broadcast.regenerate_token
redirect_to([@project, @broadcast], notice: t('.reset_notice')) and return
end
@broadcast.update(broadcast_params) @broadcast.update(broadcast_params)
@files = @broadcast.files.order("created_at DESC").paginate(page: 1) @files = @broadcast.files.order("created_at DESC").paginate(page: 1)

View File

@@ -102,6 +102,7 @@
<i class="fa fa-clipboard"></i> <i class="fa fa-clipboard"></i>
Copy URL Copy URL
</button> </button>
<%= link_to t('.actions.reset_url'), [@project, @broadcast], method: :patch, class: "btn btn-danger" %>
</div> </div>
<% else %> <% else %>
<input type="text" class="form-control" value="<%= broadcast_url(@broadcast.token) %>" readonly> <input type="text" class="form-control" value="<%= broadcast_url(@broadcast.token) %>" readonly>
@@ -110,6 +111,7 @@
<i class="fa fa-clipboard"></i> <i class="fa fa-clipboard"></i>
Copy URL Copy URL
</button> </button>
<%= link_to t('.actions.reset_url'), [@project, @broadcast], method: :patch, class: "btn btn-danger" %>
</div> </div>
<% end %> <% end %>
</div> </div>

View File

@@ -217,6 +217,9 @@ en:
new: new:
heading: heading:
Create Live Stream Create Live Stream
show:
actions:
reset_url: Reset URL
splash: splash:
actions: actions:
book_demo: Schedule a Demo book_demo: Schedule a Demo
@@ -235,6 +238,8 @@ en:
share_stream: Share live stream link with clients share_stream: Share live stream link with clients
stream_from_mobile_app: Stream from ME Suite Mobile app, or via a professional camera stream_from_mobile_app: Stream from ME Suite Mobile app, or via a professional camera
stream_multiple_cameras: Stream multiple cameras at one time stream_multiple_cameras: Stream multiple cameras at one time
update:
reset_notice: The Share URL has been reset, and the previous URL will no longer work. Please click "Copy URL" and share it again with those who you want to have access to this live stream
bulk_taggings: bulk_taggings:
new_bulk_tag_modal: new_bulk_tag_modal:
submit: Add submit: Add

View File

@@ -81,6 +81,9 @@ es:
do_not_copy_warning: "Do not copy (ES)" do_not_copy_warning: "Do not copy (ES)"
serial_number_label: "Serial Number (ES)" serial_number_label: "Serial Number (ES)"
broadcasts: broadcasts:
show:
actions:
reset_url: Reset URL (ES)
splash: splash:
actions: actions:
book_demo: Schedule a Demo book_demo: Schedule a Demo
@@ -99,6 +102,8 @@ es:
share_stream: Share live stream link with clients share_stream: Share live stream link with clients
stream_from_mobile_app: Stream from ME Suite Mobile app, or via a professional camera stream_from_mobile_app: Stream from ME Suite Mobile app, or via a professional camera
stream_multiple_cameras: Stream multiple cameras at one time stream_multiple_cameras: Stream multiple cameras at one time
update:
reset_notice: The Share URL has been reset, and the previous URL will no longer work. Please click "Copy URL" and share it again with those who you want to have access to this live stream
contract_templates: contract_templates:
blank_contracts: blank_contracts:
create: create:

View File

@@ -203,6 +203,15 @@ RSpec.describe BroadcastsController, type: :controller do
expect(BroadcastsChannel).to have_received(:broadcast_file_upload_updates) expect(BroadcastsChannel).to have_received(:broadcast_file_upload_updates)
end end
it "regenerates token if #update is called without broadcast param" do
old_token = broadcast.token
patch :update, params: { project_id: project.id, id: broadcast.id }
expect(response).to redirect_to [project, broadcast]
expect(flash.notice).to eq token_reset_notice
expect(Broadcast.last.token).not_to eq old_token
end
end end
describe "#destroy" do describe "#destroy" do
@@ -252,4 +261,8 @@ RSpec.describe BroadcastsController, type: :controller do
def create_stream def create_stream
t 'broadcasts.splash.actions.create_stream' t 'broadcasts.splash.actions.create_stream'
end end
def token_reset_notice
t 'broadcasts.update.reset_notice'
end
end end

View File

@@ -63,6 +63,21 @@ feature 'User managing broadcasts' do
expect(page).to have_content(recording.download_file_name) expect(page).to have_content(recording.download_file_name)
end end
scenario 'Clicking Reset URL regenerates broadcast token' do
broadcast = create(:broadcast, :with_stream, :with_files, project: project)
old_token = broadcast.token
visit project_broadcast_path(project, broadcast)
expect(page).to have_content reset_url
expect(page).to have_xpath "//input[@readonly][@value='#{broadcast_url(old_token)}']"
click_link reset_url
expect(Broadcast.last.token).not_to eq old_token
expect(page).to have_xpath "//input[@readonly][@value='#{broadcast_url(Broadcast.last.token)}']"
expect(page).to have_content token_reset_notice
end
scenario 'user can go back and forth between live session and previous sessions', js: true do scenario 'user can go back and forth between live session and previous sessions', js: true do
broadcast = create(:broadcast, :with_stream, :with_files, project: project) broadcast = create(:broadcast, :with_stream, :with_files, project: project)
recording = create(:broadcast_recording, broadcast: broadcast) recording = create(:broadcast_recording, broadcast: broadcast)
@@ -189,4 +204,12 @@ feature 'User managing broadcasts' do
def create_stream def create_stream
t 'broadcasts.splash.actions.create_stream' t 'broadcasts.splash.actions.create_stream'
end end
def reset_url
t 'broadcasts.show.actions.reset_url'
end
def token_reset_notice
t 'broadcasts.update.reset_notice'
end
end end