Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

an/destination and template api keys #16

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/images/landing/cat-logo-black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion app/assets/stylesheets/pages/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
text-align: center;
}

.logout-container {
.menu-container {
text-align: right;
}

Expand All @@ -21,3 +21,7 @@
.logout-button:hover {
color: #630555;
}

.home-container p {
text-align: left;
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/pages/login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
color: #a7a7a7 !important;
}

.devise-links {
.devise-links, p {
text-align: center;
}
12 changes: 0 additions & 12 deletions app/controllers/clubhouse_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,4 @@ def initialize_clubhouse_setup

redirect_to root_url
end

def set_destination_workspace_api_key
current_user.update_attribute(:clubhouse_api_token, params["destination_workspace_api_key"])

redirect_to root_url
end

def delete_destination_workspace_api_key
current_user.update_attribute(:clubhouse_api_token, nil)

redirect_to root_url
end
end
42 changes: 42 additions & 0 deletions app/controllers/keys_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class KeysController < ApplicationController
# puts('fewfew', current_user)

before_action :check_authentication, only: [:index]

def check_authentication
unless current_user
flash[:notice] = "This page is not available"
redirect_to root_path
end
end

def index
@current_user = current_user
render "keys/index"
end

def set_template_workspace_api_key
current_user.update_attribute(:template_clubhouse_api_token, params["template_workspace_api_key"])

redirect_to keys_url
end

def delete_template_workspace_api_key
current_user.update_attribute(:template_clubhouse_api_token, nil)

redirect_to keys_url
end

def set_destination_workspace_api_key
current_user.update_attribute(:destination_clubhouse_api_token, params["destination_workspace_api_key"])

redirect_to keys_url
end

def delete_destination_workspace_api_key
current_user.update_attribute(:destination_clubhouse_api_token, nil)

redirect_to keys_url
end
end

3 changes: 3 additions & 0 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<div class='page-container'>
<div class='form-container'>
<h1>CAT</h1>
<p>Clubhouse Automation Tool</p>
<%= image_tag "landing/cat-logo-black.svg", :class => "col-12", size: '150x150' %>
<h1>Login</h1>

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
Expand Down
58 changes: 24 additions & 34 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
<div class='page-container'>
<div class='home-container'>
<div class='logout-container'>
<div class='menu-container'>
<%= link_to root_url, class: 'logout-button', method: :delete do %>
<%= fa_icon "home 2x"%>
<% end %>
<%= link_to keys_path, class: 'logout-button' do %>
<%= fa_icon "key 2x"%>
<% end %>
<%= link_to destroy_user_session_path, class: 'logout-button', method: :delete do %>
<%= fa_icon "sign-out 2x"%>
<% end %>
</div>
<div>
<h1>Clubhouse API Token</h1>
<% if !@current_user.clubhouse_api_token %>
<%= form_tag clubhouse_set_destination_workspace_api_key_path do |f| %>
<div class='form-group'>
<%= text_field_tag(:destination_workspace_api_key, nil, placeholder: 'Enter your API token', class: 'form-control') %>
</div>
<div class='form-group'>
<%= submit_tag "Add Token", class: 'btn btn-primary' %>
</div>
<% end %>
<% else %>
<p>You already have an API token set. If you'd like to add a new one please delete your current token.</p>
<%= form_tag clubhouse_delete_destination_workspace_api_key_path do |f| %>
<div class='form-group'>
<%= submit_tag "Delete Token", class: 'btn btn-primary' %>
</div>
<% end %>
<% end %>
</div>

<div>
<h1>Clubhouse Projects</h1>
<%= form_tag clubhouse_initialize_clubhouse_setup_path do |f| %>
<div class='row justify-content-center form-group'>
<% @template_projects.each do |item| %>
<div class='col-4'>
<%= check_box_tag "template_projects[#{item['id']}]", item['name'] %>
<%= label_tag("project #{item['id']}", item['name']) %>
</div>
<% if @template_projects.length < 2 %>
<p>Clubhouse Projects <%= @template_projects %> </p>
<% else %>
<%= form_tag clubhouse_initialize_clubhouse_setup_path do |f| %>
<div class='row justify-content-center form-group'>
<% @template_projects.each do |item| %>
<div class='col-4'>
<%= check_box_tag "template_projects[#{item['id']}]", item['name'] %>
<%= label_tag("project #{item['id']}", item['name']) %>
</div>
<% end %>
</div>
<div class='form-group'>
<%= submit_tag "Initiallize Clubhouse", class: 'btn btn-primary' %>
</div>
<% end %>
<% end %>
</div>
<div class='form-group'>
<%= submit_tag "Initiallize Clubhouse", class: 'btn btn-primary' %>
</div>
<% end %>
</div>
</div>
</div>

</div>
56 changes: 56 additions & 0 deletions app/views/keys/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<div class='page-container'>
<div class='home-container'>
<div class='menu-container'>
<%= link_to root_url, class: 'logout-button', method: :delete do %>
<%= fa_icon "home 2x"%>
<% end %>
<%= link_to keys_path, class: 'logout-button' do %>
<%= fa_icon "key 2x"%>
<% end %>
<%= link_to destroy_user_session_path, class: 'logout-button', method: :delete do %>
<%= fa_icon "sign-out 2x"%>
<% end %>
</div>
<div>
<h1>Clubhouse API Keys</h1>
<h4>Template API Key</h4>
<% if !@current_user.template_clubhouse_api_token %>
<%= form_tag(keys_set_template_workspace_api_key_path, {class: "row"}) do |f| %>
<div class='form-group col-10'>
<%= text_field_tag(:template_workspace_api_key, nil, placeholder: 'Enter your template API token', class: 'form-control') %>
</div>
<div class='form-group col-2'>
<%= submit_tag "Save", class: 'btn btn-primary' %>
</div>
<% end %>
<% else %>
<%= form_tag(keys_delete_template_workspace_api_key_path, {class: "row"}) do |f| %>
<p class='col-10 form-para'>Template workspace API token set.</p>
<div class='form-group col-2'>
<%= submit_tag "Delete", class: 'btn btn-primary' %>
</div>
<% end %>
<% end %>
</div>

<div>
<h4>Destination API Key</h4>
<% if !@current_user.destination_clubhouse_api_token %>
<%= form_tag(keys_set_destination_workspace_api_key_path, {class: "row"}) do |f| %>
<div class='form-group col-10'>
<%= text_field_tag(:destination_workspace_api_key, nil, placeholder: 'Enter your destination API token', class: 'form-control') %>
</div>
<div class='form-group col-2'>
<%= submit_tag "Save", class: 'btn btn-primary' %>
</div>
<% end %>
<% else %>
<%= form_tag(keys_delete_destination_workspace_api_key_path, {class: "row"}) do |f| %>
<p class='col-10 form-para'>Template workspace API token set.</p>
<div class='form-group col-2'>
<%= submit_tag "Delete", class: 'btn btn-primary' %>
</div>
<% end %>
<% end %>
</div>
</div>
1 change: 0 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>

<body>
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

config.webpacker.check_yarn_integrity = false

# Email config
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
# config.navigational_formats = ['*/*', :html]

# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
config.sign_out_via = :get
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change because for some reason I kept getting an error even though my logout button was using the :delete method. I'm not sure why it thinks it was :get but this was the only way around. I'm not confident this is the right change but I had to make it so the app would stop breaking.

Thoughts?


# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
Expand Down
8 changes: 5 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Rails.application.routes.draw do
ActiveAdmin.routes(self)
get "home/index"
get "home/test"
match "/keys" => "keys#index", :via => "get"
post "clubhouse/initialize_clubhouse_setup"
post "clubhouse/set_destination_workspace_api_key"
post "clubhouse/delete_destination_workspace_api_key"
post "keys/set_template_workspace_api_key"
post "keys/delete_template_workspace_api_key"
post "keys/set_destination_workspace_api_key"
post "keys/delete_destination_workspace_api_key"
devise_for :users
require "sidekiq/web"
mount Sidekiq::Web => "/sidekiq"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeApiKeyOnUserFromDestinationToTemplate < ActiveRecord::Migration[6.0]
def change
rename_column :users, :clubhouse_api_token, :template_clubhouse_api_token
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDestinationClubhouseApiKeyToUser < ActiveRecord::Migration[6.0]
def change
add_column :users, :destination_clubhouse_api_token, :string
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_03_31_185241) do
ActiveRecord::Schema.define(version: 2020_06_30_165219) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -54,7 +54,8 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "admin", default: false
t.string "clubhouse_api_token"
t.string "template_clubhouse_api_token"
t.string "destination_clubhouse_api_token"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Expand Down