Browse Source

feat: All participants can start a scheduled campaign session

Fixes: #49
develop
Martin Bober 1 month ago
parent
commit
e6ba864ef6
  1. 2
      app/controllers/campaign_sessions_controller.rb
  2. 54
      app/views/forum/_campaign_session.html.erb
  3. 1
      config/locales/campaign_sessions/de.yml
  4. 1
      config/locales/campaign_sessions/en.yml
  5. 8
      test/controllers/campaign_sessions_controller_test.rb

2
app/controllers/campaign_sessions_controller.rb

@ -604,7 +604,7 @@ class CampaignSessionsController < ApplicationController
end
def start
unless logged_in? and current_player?(@session.creator)
unless logged_in? and (current_player?(@session.creator) or @session.session_participants.where(player_id: current_player.id).any?)
head :forbidden
return
end

54
app/views/forum/_campaign_session.html.erb

@ -182,20 +182,15 @@
<script>
var session_id = <%= @thread.campaign_session.id %>;
<% if current_player?(@thread.campaign_session.creator) %>
var is_creator = true;
<% else %>
var is_creator = false;
<% end %>
function renderSessionBotNoConnection(container)
{
clearChildren(container);
var danger_alert = createHtmlElement("div", {
const danger_alert = createHtmlElement("div", {
"class": "alert alert-danger",
role: "alert"
});
var p = createHtmlElement("p");
const p = createHtmlElement("p");
p.appendChild(document.createTextNode(I18n['campaign_session']['show']['sessionbot_no_connection']));
danger_alert.appendChild(p);
container.appendChild(danger_alert);
@ -204,15 +199,15 @@
function renderSessionBotOnline(container, channel_name)
{
clearChildren(container);
var success_alert = createHtmlElement("div", {
const success_alert = createHtmlElement("div", {
"class": "alert alert-success",
role: "alert"
});
var p = createHtmlElement('p');
const p = createHtmlElement('p');
p.appendChild(document.createTextNode(t(I18n['campaign_session']['show']['sessionbot_online'], {channel_name: channel_name})));
success_alert.appendChild(p);
<% if logged_in? and @thread.campaign_session.session_participants.where(player: current_player, role: 'gm').any? %>
var gmScreenBtn = createHtmlElement('a', {
const gmScreenBtn = createHtmlElement('a', {
class: 'btn btn-default',
<% if @campaign.is_convention? %>
href: "<%=convention_session_gm_screen_path(@campaign.convention_name, @thread.campaign_session) %>",
@ -222,11 +217,11 @@
});
gmScreenBtn.appendChild(document.createTextNode("<%=t 'campaign.gm_screen' %>"));
success_alert.appendChild(gmScreenBtn);
var terminate_button = createHtmlElement('a', {
const terminate_button = createHtmlElement('a', {
"class": "btn btn-warning",
rel: "nofollow",
"data-method": "post",
href: "/campaigns/"+ <%= @campaign.id %> + "/sessions/" + <%= @thread.campaign_session.id %> + "/terminate"
href: "/campaigns/" + <%= @campaign.id %> +"/sessions/" + <%= @thread.campaign_session.id %> +"/terminate"
});
terminate_button.appendChild(document.createTextNode(I18n['campaign_session']['show']['sessionbot_terminate']));
success_alert.appendChild(terminate_button);
@ -256,28 +251,23 @@
function renderSessionBotOffline(container) {
clearChildren(container);
var error_alert = createHtmlElement("div", {
const error_alert = createHtmlElement("div", {
"class": "alert alert-warning",
role: "alert"
});
var p = createHtmlElement('p');
if (is_creator)
{
p.appendChild(document.createTextNode(I18n['campaign_session']['show']['sessionbot_offline_creator']));
error_alert.appendChild(p);
var start_button = createHtmlElement('a', {
"class": "btn btn-success",
rel: "nofollow",
"data-method": "post",
href: "/campaigns/"+ <%= @campaign.id %> + "/sessions/" + <%= @thread.campaign_session.id %> + "/start"
});
start_button.appendChild(document.createTextNode(I18n['campaign_session']['show']['sessionbot_start']));
error_alert.appendChild(start_button);
} else {
error_alert.appendChild(document.createTextNode(I18n['campaign_session']['show']['sessionbot_offline_muggle']));
}
const p = createHtmlElement('p');
p.appendChild(document.createTextNode(I18n['campaign_session']['show']['sessionbot_offline_creator']));
error_alert.appendChild(p);
const start_button = createHtmlElement('a', {
"class": "btn btn-success",
rel: "nofollow",
"data-method": "post",
href: "/campaigns/" + <%= @campaign.id %> +"/sessions/" + <%= @thread.campaign_session.id %> +"/start"
});
start_button.appendChild(document.createTextNode(I18n['campaign_session']['show']['sessionbot_start']));
error_alert.appendChild(start_button);
error_alert.appendChild(document.createTextNode(" "));
var refresh_button = createHtmlElement('a', {
const refresh_button = createHtmlElement('a', {
"class": "btn btn-default"
});
refresh_button.addEventListener('click', checkSessionBot);
@ -288,13 +278,13 @@
function checkSessionBot()
{
var container = document.getElementById("session_bot_container");
const container = document.getElementById("session_bot_container");
clearChildren(container);
$.ajax({
dataType: "json",
url: DICEBOT_URL + "/sessions",
success: function(response) {
for (var i=0; i<response.length; i++)
for (let i=0; i<response.length; i++)
{
if (response[i]['session_id'] === session_id){
renderSessionBotOnline(container, response[i]['channel_name']);

1
config/locales/campaign_sessions/de.yml

@ -158,7 +158,6 @@ de:
button_unknown: "Angabe zurückziehen"
button_ask_for_update: "Nach aktuellem Status fragen"
sessionbot_online: "SessionBot ist online. Betrete auf unserem Mumble Server den Kanal \"%{channel_name}\""
sessionbot_offline_muggle: "Leider ist die Sitzung noch nicht auf dem Mumble Server gestartet. Bitte warte bis der Ersteller der Sitzung die Sitzung gestartet hat."
sessionbot_offline_creator: "Wenn Du soweit bist, kannst du die Sitzung auf unserem Mumble Server starten."
sessionbot_refresh: "Aktualisieren"
sessionbot_start: "Sitzung starten"

1
config/locales/campaign_sessions/en.yml

@ -158,7 +158,6 @@ en:
button_unknown: "Unknown"
button_ask_for_update: "Ask for update"
sessionbot_online: "SessionBot is online. Visit our Mumble server and join channel \"%{channel_name}\""
sessionbot_offline_muggle: "Session has not been started. Please wait until the creator has started the session."
sessionbot_offline_creator: "You can start the session on our Mumble server as soon as you are ready."
sessionbot_refresh: "Refresh"
sessionbot_start: "Start session"

8
test/controllers/campaign_sessions_controller_test.rb

@ -649,6 +649,14 @@ class CampaignSessionsControllerTest < ActionController::TestCase
assert_redirected_to campaign_forum_path(@campaign, @session.forum_thread)
end
test 'participant should start session' do
log_in_as @session.session_participants.first.player
assert_difference 'SessionStartWorker.jobs.size', 1 do
post :start, campaign_id: @campaign.id, session_id: @session.id
end
assert_redirected_to campaign_forum_path(@campaign, @session.forum_thread)
end
test 'creator should start session' do
log_in_as @session.creator
assert_difference 'SessionStartWorker.jobs.size', 1 do

Loading…
Cancel
Save