This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fixed session-based flash messages.

  • Loading branch information...
armcburney committed Apr 15, 2018
1 parent 3db4f04 commit fbfdae166a13b4e3e42d480a6b90750bc0e25f4c
View
@@ -4,6 +4,7 @@ source("https://rubygems.org")
gem "faye-websocket", ">= 0.10.7", "< 1.0.0" # web socket connection for Sinatra
gem "sinatra", ">= 2.0.1", "< 3.0.0" # Our web application library
gem "sinatra-contrib", ">= 2.0.0", "< 3.0.0" # TODO: document why we have this here @taquitos
gem "sinatra-flash"
# web server that we need to support web socket connections with sinatra
gem "thin", ">= 1.7.2", "< 2.0.0"
@@ -41,7 +42,7 @@ gem "bundler", "~> 1.16.0"
# fastlane dependencies
# TODO: point to minimum release instead of GitHub once
# we shipped a new release
# we shipped a new release
gem "fastfile-parser", git: "https://github.com/fastlane/fastfile-parser", require: false
gem "fastlane", git: "https://github.com/fastlane/fastlane"
gem "taskqueue", git: "https://github.com/fastlane/TaskQueue", require: false
View
@@ -246,6 +246,8 @@ GEM
rack-protection (= 2.0.1)
sinatra (= 2.0.1)
tilt (>= 1.3, < 3)
sinatra-flash (0.3.0)
sinatra (>= 1.0.0)
slack-notifier (2.3.2)
term-ansicolor (1.6.0)
tins (~> 1.0)
@@ -321,6 +323,7 @@ DEPENDENCIES
rufus-scheduler
sinatra (>= 2.0.1, < 3.0.0)
sinatra-contrib (>= 2.0.0, < 3.0.0)
sinatra-flash
taskqueue!
thin (>= 1.7.2, < 2.0.0)
tty-command (>= 0.7.0, < 1.0.0)
@@ -13,7 +13,7 @@ class ConfigurationController < AuthenticatedControllerBase
HOME = "/configuration_erb"
get HOME do
locals = { title: "Configuration", variables: {} }
locals = { title: "Configuration" }
erb(:index, locals: locals, layout: FastlaneCI.default_layout)
end
@@ -30,18 +30,12 @@ class ConfigurationController < AuthenticatedControllerBase
post "#{HOME}/keys" do
if valid_params?(params, post_parameter_list_for_validation)
Services.environment_variable_service.write_keys_file!(locals: params)
variables = {
status: STATUS[:success],
message: "#{Services.environment_variable_service.keys_file_path_relative_to_home} file written."
}
flash[:success] = "#{Services.environment_variable_service.keys_file_path_relative_to_home} file written."
else
variables = {
status: STATUS[:error],
message: "#{Services.environment_variable_service.keys_file_path_relative_to_home} file NOT written."
}
flash[:error] = "#{Services.environment_variable_service.keys_file_path_relative_to_home} file NOT written."
end
locals = { title: "Configuration", variables: variables }
locals = { title: "Configuration" }
erb(:index, locals: locals, layout: FastlaneCI.default_layout)
end
@@ -2,33 +2,15 @@
<html>
<head>
<title>fastlane CI</title>
<link rel="stylesheet" href="/custom.css">
<link rel="stylesheet" href="/material.min.css">
<script src="/material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<!--
<%= erb :"../../global/notification_banner" %>
-->
<!-- More info https://github.com/fastlane/ci/issues/514 -->
<%= yield %>
</body>
</html>
<!-- Modal display script -->
<script>
var dialog = document.querySelector('dialog');
if (dialog) {
if (!dialog.showModal) dialogPolyfill.registerDialog(dialog);
<% if message %>
dialog.showModal();
<% end %>
dialog.querySelector('.close').addEventListener('click', function() {
dialog.close();
});
}
</script>
@@ -1,11 +1,14 @@
<dialog class="modal-dialog">
<h4 class="modal-title"><code>fastlane.ci</code> notification</h4>
<% flash.keys.each do |type| %>
<div class="flash_<%= type %>">
<% case type
when :success %>
<i class="fa fa-check"></i>
<% when :warning %>
<i class="fa fa-info-circle"></i>
<% when :error %>
<i class="fa fa-times-circle"></i>
<% end %>
<div class="mdl-dialog__content">
<%= message %>
<%= type.to_s.upcase + ": " + flash[type] %>
</div>
<div class="mdl-dialog__actions mdl-dialog__actions--full-width">
<button type="button" class="mdl-button close">Okay</button>
</div>
</dialog>
<% end %>
@@ -12,11 +12,6 @@ class OnboardingController < ControllerBase
# variable to avoid displaying the same message multiple times
before do
@progress = false
if !session[:message].nil? && request.get?
@message = session[:message]
session[:message] = nil
end
end
get HOME do
@@ -66,13 +61,13 @@ class OnboardingController < ControllerBase
)
)
session[:message] = <<~HTML
#{Services.environment_variable_service.keys_file_path_relative_to_home} file written with the configuration
values:<br /> FASTLANE_CI_ENCRYPTION_KEY=#{params[:encryption_key]}
flash[:success] = <<~HTML
<code>#{Services.environment_variable_service.keys_file_path_relative_to_home}</code> file written with the
configuration value <code>FASTLANE_CI_ENCRYPTION_KEY=#{params[:encryption_key]}</code>
HTML
else
session[:message] = <<~HTML
ERROR: #{Services.environment_variable_service.keys_file_path_relative_to_home} file not written.
flash[:error] = <<~HTML
#{Services.environment_variable_service.keys_file_path_relative_to_home} file not written.
HTML
end
@@ -99,17 +94,13 @@ class OnboardingController < ControllerBase
)
)
session[:message] = <<~HTML
#{Services.environment_variable_service.keys_file_path_relative_to_home} file written with the configuration
values:<br />
<ul>
<li>FASTLANE_CI_PASSWORD=#{params[:ci_user_password]}</li>
</ul>
flash[:success] = <<~HTML
<code>#{Services.environment_variable_service.keys_file_path_relative_to_home}</code> file written with the
configuration values <code>FASTLANE_CI_BOT_API_TOKEN</code> and <code>FASTLANE_CI_PASSWORD</code>
HTML
else
session[:message] = <<~HTML
ERROR: #{Services.environment_variable_service.keys_file_path_relative_to_home} file not written.
flash[:error] = <<~HTML
<code>#{Services.environment_variable_service.keys_file_path_relative_to_home}</code> file not written.
HTML
end
@@ -131,7 +122,7 @@ class OnboardingController < ControllerBase
api_token = params[:initial_onboarding_user_api_token].strip
if api_token.length != 40
error_message = "Invalid API token, please ensure you entered an API token and not a password"
session[:message] = error_message
flash[:error] = error_message
logger.error(error_message)
logger.error("API tokens are generated by GitHub and are 40 characters long")
@@ -151,13 +142,9 @@ class OnboardingController < ControllerBase
)
)
session[:message] = <<~HTML
#{Services.environment_variable_service.keys_file_path_relative_to_home} file written with the
configuration values:
<ul>
<li>FASTLANE_CI_INITIAL_ONBOARDING_USER_API_TOKEN='#{params[:initial_onboarding_user_api_token]}'</li>
</ul>
flash[:success] = <<~HTML
<code>#{Services.environment_variable_service.keys_file_path_relative_to_home}</code> file written with the
configuration value <code>FASTLANE_CI_INITIAL_ONBOARDING_USER_API_TOKEN</code>
HTML
else
scopes, required = scope_validation_error
@@ -166,12 +153,12 @@ class OnboardingController < ControllerBase
# rubocop:disable Metrics/LineLength
error_message = "Token should be in \"#{required}\" scope, currently it's in #{scopes_list_wording} #{scopes_wording}."
# rubocop:enable Metrics/LineLength
session[:message] = "ERROR: #{error_message} See the image below."
flash[:error] = "#{error_message} See the image below."
logger.error(error_message)
end
else
path = Services.environment_variable_service.keys_file_path_relative_to_home
session[:message] = "ERROR: #{path} file not written."
flash[:error] = "#{path} file not written."
end
redirect("#{HOME}/initial_onboarding_user")
@@ -198,12 +185,12 @@ class OnboardingController < ControllerBase
Services.onboarding_service.clone_remote_repository_locally
Launch.start_github_workers
session[:message] = <<~HTML
flash[:success] = <<~HTML
Remote repo #{params[:repo_url]} successfully created
HTML
else
session[:message] = <<~HTML
ERROR: Remote repository was not successfully created
flash[:error] = <<~HTML
Remote repository was not successfully created
HTML
end
@@ -219,7 +206,7 @@ class OnboardingController < ControllerBase
def validate_api_token_correct(api_token, route)
if api_token.length != 40
error_message = "Invalid API token, please ensure you entered an API token and not a password"
session[:message] = error_message
flash[:error] = error_message
logger.error(error_message)
logger.error("API tokens are generated by GitHub and are 40 characters long")
@@ -75,8 +75,8 @@ def configuration_repository_exists?
# Return cached true value, if it was successful, otherwise keep checking because it might have been fixed
return @config_repo_exists unless @config_repo_exists.nil? || (@config_repo_exists == false)
github_action(bot_user_client) do
@config_repo_exists = bot_user_client.repository?(repo_shortform)
github_action(onboarding_user_client) do
@config_repo_exists = onboarding_user_client.repository?(repo_shortform)
end
return @config_repo_exists
@@ -109,7 +109,7 @@ def add_bot_user_as_collaborator
invitation_id = invite_bot_user_to_configuration_repository
if invitation_id.nil?
if !invitation_id.nil?
return accept_invitation_to_repository_as_bot_user(invitation_id)
else
raise "Could not add bot user as a collaborator. Invitation was not sent to collaborate on #{repo_shortform}."
@@ -1,6 +1,7 @@
require "sinatra/base"
require "sinatra/reloader"
require "sinatra/custom_logger"
require "sinatra/flash"
require "set"
require "logger"
@@ -14,13 +15,12 @@ module FastlaneCI
# Handles default configuration like auto-reloading, session management, and erb path correcting
#
class ControllerBase < Sinatra::Base
enable :sessions
register SetupChecker
include FastlaneCI::Logging
register Sinatra::Flash
# A message to be displayed in a pop-up after POST requests
#
# @return [String]
attr_reader :message
include FastlaneCI::Logging
# Enum for status of POST operations
STATUS = { success: :success, error: :error }
View
@@ -0,0 +1,26 @@
@import url('//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
.flash_success, .flash_warning, .flash_error {
padding: 12px;
}
.flash_success {
color: #4F8A10;
background-color: #DFF2BF;
}
.flash_warning {
color: #9F6000;
background-color: #FEEFB3;
}
.flash_error {
color: #D8000C;
background-color: #FFD2D2;
}
.flash_success i, .flash_warning i, .flash_error i {
margin: 10px 30px;
font-size: 2em;
vertical-align: middle;
}

0 comments on commit fbfdae1

Please sign in to comment.