From 557b43c9117dbeca58313aa5f0061e8afbd96f52 Mon Sep 17 00:00:00 2001 From: Jez Caudle Date: Tue, 8 Feb 2022 17:33:34 +0000 Subject: [PATCH] Starting companies and admin --- Gemfile | 3 +- Gemfile.lock | 10 + app/assets/config/manifest.js | 2 + app/assets/stylesheets/actiontext.css | 31 ++ app/assets/stylesheets/application.css | 512 ++++++++++++++++++ .../{ => admin}/companies_controller.rb | 0 app/controllers/home_controller.rb | 12 + app/helpers/home_helper.rb | 2 + app/javascript/application.js | 5 + app/models/ability.rb | 34 ++ app/models/company.rb | 1 + app/models/user.rb | 27 + app/views/active_storage/blobs/_blob.html.erb | 14 + app/views/home/.index.html.erb.kate-swp | Bin 68 -> 0 bytes app/views/home/index.html.erb | 19 + .../action_text/contents/_content.html.erb | 3 + app/views/layouts/application.html.erb | 13 +- bin/importmap | 4 + config/importmap.rb | 3 + config/routes.rb | 8 +- .../20220206152358_devise_create_users.rb | 45 ++ ...te_active_storage_tables.active_storage.rb | 57 ++ ...6_create_action_text_tables.action_text.rb | 26 + ...220208164226_create_users_and_companies.rb | 8 + db/schema.rb | 71 ++- test/controllers/home_controller_test.rb | 7 + test/fixtures/action_text/rich_texts.yml | 4 + test/fixtures/users.yml | 11 + test/models/user_test.rb | 7 + vendor/javascript/.keep | 0 30 files changed, 934 insertions(+), 5 deletions(-) create mode 100644 app/assets/stylesheets/actiontext.css rename app/controllers/{ => admin}/companies_controller.rb (100%) create mode 100644 app/controllers/home_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/javascript/application.js create mode 100644 app/models/ability.rb create mode 100644 app/models/user.rb create mode 100644 app/views/active_storage/blobs/_blob.html.erb delete mode 100644 app/views/home/.index.html.erb.kate-swp create mode 100644 app/views/layouts/action_text/contents/_content.html.erb create mode 100755 bin/importmap create mode 100644 config/importmap.rb create mode 100644 db/migrate/20220206152358_devise_create_users.rb create mode 100644 db/migrate/20220206184745_create_active_storage_tables.active_storage.rb create mode 100644 db/migrate/20220206184746_create_action_text_tables.action_text.rb create mode 100644 db/migrate/20220208164226_create_users_and_companies.rb create mode 100644 test/controllers/home_controller_test.rb create mode 100644 test/fixtures/action_text/rich_texts.yml create mode 100644 test/fixtures/users.yml create mode 100644 test/models/user_test.rb create mode 100644 vendor/javascript/.keep diff --git a/Gemfile b/Gemfile index 21b65ac..f62e165 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem 'devise' +gem 'cancancan' ruby "3.0.3" @@ -48,7 +49,7 @@ gem "bootsnap", require: false # gem "sassc-rails" # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] -# gem "image_processing", "~> 1.2" +gem "image_processing", "~> 1.2" group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem diff --git a/Gemfile.lock b/Gemfile.lock index 830e484..ca9b64a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -73,6 +73,7 @@ GEM bootsnap (1.10.3) msgpack (~> 1.2) builder (3.2.4) + cancancan (3.3.0) capybara (3.36.0) addressable matrix @@ -96,10 +97,14 @@ GEM warden (~> 1.2.3) digest (3.1.0) erubi (1.10.0) + ffi (1.15.5) globalid (1.0.0) activesupport (>= 5.0) i18n (1.9.1) concurrent-ruby (~> 1.0) + image_processing (1.12.1) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) importmap-rails (1.0.2) actionpack (>= 6.0.0) railties (>= 6.0.0) @@ -118,6 +123,7 @@ GEM marcel (1.0.2) matrix (0.4.2) method_source (1.0.0) + mini_magick (4.11.0) mini_mime (1.1.2) mini_portile2 (2.7.1) minitest (5.15.0) @@ -184,6 +190,8 @@ GEM actionpack (>= 5.0) railties (>= 5.0) rexml (3.2.5) + ruby-vips (2.1.4) + ffi (~> 1.12) rubyzip (2.3.2) selenium-webdriver (4.1.0) childprocess (>= 0.5, < 5.0) @@ -229,9 +237,11 @@ PLATFORMS DEPENDENCIES bootsnap + cancancan capybara debug devise + image_processing (~> 1.2) importmap-rails jbuilder mysql2 (~> 0.5) diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index 5918193..ddd546a 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,2 +1,4 @@ //= link_tree ../images //= link_directory ../stylesheets .css +//= link_tree ../../javascript .js +//= link_tree ../../../vendor/javascript .js diff --git a/app/assets/stylesheets/actiontext.css b/app/assets/stylesheets/actiontext.css new file mode 100644 index 0000000..3cfcb2b --- /dev/null +++ b/app/assets/stylesheets/actiontext.css @@ -0,0 +1,31 @@ +/* + * Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and + * the trix-editor content (whether displayed or under editing). Feel free to incorporate this + * inclusion directly in any other asset bundle and remove this file. + * + *= require trix +*/ + +/* + * We need to override trix.css’s image gallery styles to accommodate the + * element we wrap around attachments. Otherwise, + * images in galleries will be squished by the max-width: 33%; rule. +*/ +.trix-content .attachment-gallery > action-text-attachment, +.trix-content .attachment-gallery > .attachment { + flex: 1 0 33%; + padding: 0 0.5em; + max-width: 33%; +} + +.trix-content .attachment-gallery.attachment-gallery--2 > action-text-attachment, +.trix-content .attachment-gallery.attachment-gallery--2 > .attachment, .trix-content .attachment-gallery.attachment-gallery--4 > action-text-attachment, +.trix-content .attachment-gallery.attachment-gallery--4 > .attachment { + flex-basis: 50%; + max-width: 50%; +} + +.trix-content action-text-attachment .attachment { + padding: 0 !important; + max-width: 100% !important; +} diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 288b9ab..0e590a1 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,515 @@ *= require_tree . *= require_self */ + +/* Set the global variables for everything. Change these to use your own fonts and colours. */ +:root { + /* Set sans-serif & mono fonts */ + --sans-font: -apple-system, BlinkMacSystemFont, "Avenir Next", Avenir, + "Nimbus Sans L", Roboto, Noto, "Segoe UI", Arial, Helvetica, + "Helvetica Neue", sans-serif; + --mono-font: Consolas, Menlo, Monaco, "Andale Mono", "Ubuntu Mono", monospace; + + /* Body font size. By default, effectively 18.4px, based on 16px as 'root em' */ + --base-fontsize: 1.15rem; + + /* Major third scale progression - see https://type-scale.com/ */ + --header-scale: 1.25; + + /* Line height is set to the "Golden ratio" for optimal legibility */ + --line-height: 1.618; + + /* Default (light) theme */ + --bg: #fff; + --accent-bg: #f5f7ff; + --text: #212121; + --text-light: #585858; + --border: #d8dae1; + --accent: #0d47a1; + --accent-light: #90caf9; + --code: #d81b60; + --preformatted: #444; + --marked: #ffdd33; + --disabled: #efefef; +} + +/* Dark theme */ +@media (prefers-color-scheme: dark) { + :root { + --bg: #212121; + --accent-bg: #2b2b2b; + --text: #dcdcdc; + --text-light: #ababab; + --border: #666; + --accent: #ffb300; + --accent-light: #ffecb3; + --code: #f06292; + --preformatted: #ccc; + --disabled: #111; + } + + img, + video { + opacity: 0.6; + } +} + +html { + /* Set the font globally */ + font-family: var(--sans-font); +} + +/* Make the body a nice central block */ +body { + color: var(--text); + background: var(--bg); + font-size: var(--base-fontsize); + line-height: var(--line-height); + display: flex; + min-height: 100vh; + flex-direction: column; + flex: 1; + margin: 0 auto; + max-width: 45rem; + padding: 0 0.5rem; + overflow-x: hidden; + word-break: break-word; + overflow-wrap: break-word; +} + +/* Make the header bg full width, but the content inline with body */ +header { + background: var(--accent-bg); + border-bottom: 1px solid var(--border); + text-align: center; + padding: 2rem 0.5rem; + width: 100vw; + position: relative; + box-sizing: border-box; + left: 50%; + right: 50%; + margin-left: -50vw; + margin-right: -50vw; +} + +/* Remove margins for header text */ +header h1, +header p { + margin: 0; +} + +/* Add a little padding to ensure spacing is correct between content and nav */ +main { + padding-top: 1.5rem; +} + +/* Fix line height when title wraps */ +h1, +h2, +h3 { + line-height: 1.1; +} + +/* Format navigation */ +nav { + font-size: 1rem; + line-height: 2; + padding: 1rem 0; +} + +nav a { + margin: 1rem 1rem 0 0; + border: 1px solid var(--border); + border-radius: 5px; + color: var(--text) !important; + display: inline-block; + padding: 0.1rem 1rem; + text-decoration: none; + transition: 0.4s; +} + +nav a:hover { + color: var(--accent) !important; + border-color: var(--accent); +} + +nav a.current:hover { + text-decoration: none; +} + +footer { + margin-top: 4rem; + padding: 2rem 1rem 1.5rem 1rem; + color: var(--text-light); + font-size: 0.9rem; + text-align: center; + border-top: 1px solid var(--border); +} + +/* Format headers */ +h1 { + font-size: calc( + var(--base-fontsize) * var(--header-scale) * var(--header-scale) * + var(--header-scale) * var(--header-scale) + ); + margin-top: calc(var(--line-height) * 1.5rem); +} + +h2 { + font-size: calc( + var(--base-fontsize) * var(--header-scale) * var(--header-scale) * + var(--header-scale) + ); + margin-top: calc(var(--line-height) * 1.5rem); +} + +h3 { + font-size: calc( + var(--base-fontsize) * var(--header-scale) * var(--header-scale) + ); + margin-top: calc(var(--line-height) * 1.5rem); +} + +h4 { + font-size: calc(var(--base-fontsize) * var(--header-scale)); + margin-top: calc(var(--line-height) * 1.5rem); +} + +h5 { + font-size: var(--base-fontsize); + margin-top: calc(var(--line-height) * 1.5rem); +} + +h6 { + font-size: calc(var(--base-fontsize) / var(--header-scale)); + margin-top: calc(var(--line-height) * 1.5rem); +} + +/* Format links & buttons */ +a, +a:visited { + color: var(--accent); +} + +a:hover { + text-decoration: none; +} + +a button, +button, +[role="button"], +input[type="submit"], +input[type="reset"], +input[type="button"] { + border: none; + border-radius: 5px; + background: var(--accent); + font-size: 1rem; + color: var(--bg); + padding: 0.7rem 0.9rem; + margin: 0.5rem 0; + transition: 0.4s; +} + +a button[disabled], +button[disabled], +[role="button"][aria-disabled="true"], +input[type="submit"][disabled], +input[type="reset"][disabled], +input[type="button"][disabled], +input[type="checkbox"][disabled], +input[type="radio"][disabled], +select[disabled] { + cursor: default; + opacity: 0.5; + cursor: not-allowed; +} + +input:disabled, +textarea:disabled, +select:disabled { + cursor: not-allowed; + background-color: var(--disabled); +} + +input[type="range"] { + padding: 0; +} + +/* Set the cursor to '?' while hovering over an abbreviation */ +abbr { + cursor: help; +} + +button:focus, +button:enabled:hover, +[role="button"]:focus, +[role="button"]:not([aria-disabled="true"]):hover, +input[type="submit"]:focus, +input[type="submit"]:enabled:hover, +input[type="reset"]:focus, +input[type="reset"]:enabled:hover, +input[type="button"]:focus, +input[type="button"]:enabled:hover, +input[type="checkbox"]:focus, +input[type="checkbox"]:enabled:hover, +input[type="radio"]:focus, +input[type="radio"]:enabled:hover { + filter: brightness(1.4); + cursor: pointer; +} + +/* Format the expanding box */ +details { + background: var(--accent-bg); + border: 1px solid var(--border); + border-radius: 5px; + margin-bottom: 1rem; +} + +summary { + cursor: pointer; + font-weight: bold; + padding: 0.6rem 1rem; +} + +details[open] { + padding: 0.6rem 1rem 0.75rem 1rem; +} + +details[open] summary { + margin-bottom: 0.5rem; + padding: 0; +} + +details[open] > *:last-child { + margin-bottom: 0; +} + +/* Format tables */ +table { + border-collapse: collapse; + width: 100%; + margin: 1.5rem 0; +} + +td, +th { + border: 1px solid var(--border); + text-align: left; + padding: 0.5rem; +} + +th { + background: var(--accent-bg); + font-weight: bold; +} + +tr:nth-child(even) { + /* Set every other cell slightly darker. Improves readability. */ + background: var(--accent-bg); +} + +table caption { + font-weight: bold; + margin-bottom: 0.5rem; +} + +/* Lists */ +ol, +ul { + padding-left: 3rem; +} + +/* Format forms */ +textarea, +select, +input { + font-size: inherit; + font-family: inherit; + padding: 0.5rem; + margin-bottom: 0.5rem; + color: var(--text); + background: var(--bg); + border: 1px solid var(--border); + border-radius: 5px; + box-shadow: none; + box-sizing: border-box; + width: 60%; + -moz-appearance: none; + -webkit-appearance: none; + appearance: none; +} + +/* Add arrow to */ +select { + background-image: linear-gradient(45deg, transparent 49%, var(--text) 51%), + linear-gradient(135deg, var(--text) 51%, transparent 49%); + background-position: calc(100% - 20px), calc(100% - 15px); + background-size: 5px 5px, 5px 5px; + background-repeat: no-repeat; +} + +select[multiple] { + background-image: none !important; +} + +/* checkbox and radio button style */ +input[type="checkbox"], +input[type="radio"] { + vertical-align: bottom; + position: relative; +} + +input[type="radio"] { + border-radius: 100%; +} + +input[type="checkbox"]:checked, +input[type="radio"]:checked { + background: var(--accent); +} + +input[type="checkbox"]:checked::after { + /* Creates a rectangle with colored right and bottom borders which is rotated to look like a check mark */ + content: " "; + width: 0.1em; + height: 0.25em; + border-radius: 0; + position: absolute; + top: 0.05em; + left: 0.18em; + background: transparent; + border-right: solid var(--bg) 0.08em; + border-bottom: solid var(--bg) 0.08em; + font-size: 1.8em; + transform: rotate(45deg); +} +input[type="radio"]:checked::after { + /* creates a colored circle for the checked radio button */ + content: " "; + width: 0.25em; + height: 0.25em; + border-radius: 100%; + position: absolute; + top: 0.125em; + background: var(--bg); + left: 0.125em; + font-size: 32px; +} + +/* Make the textarea wider than other inputs */ +textarea { + width: 80%; +} + +/* Makes input fields wider on smaller screens */ +@media only screen and (max-width: 720px) { + textarea, + select, + input { + width: 100%; + } +} + +/* Ensures the checkbox and radio inputs do not have a set width like other input fields */ +input[type="checkbox"], +input[type="radio"] { + width: auto; +} + +/* do not show border around file selector button */ +input[type="file"] { + border: 0; +} + +/* Without this any HTML using
shows ugly borders and has additional padding/margin. (Issue #3) */ +fieldset { + border: 0; + padding: 0; + margin: 0; +} + +/* Misc body elements */ + +hr { + color: var(--border); + border-top: 1px; + margin: 1rem auto; +} + +mark { + padding: 2px 5px; + border-radius: 4px; + background: var(--marked); +} + +main img, +main video { + max-width: 100%; + height: auto; + border-radius: 5px; +} + +figure { + margin: 0; +} + +figcaption { + font-size: 0.9rem; + color: var(--text-light); + text-align: center; + margin-bottom: 1rem; +} + +blockquote { + margin: 2rem 0 2rem 2rem; + padding: 0.4rem 0.8rem; + border-left: 0.35rem solid var(--accent); + opacity: 0.8; + font-style: italic; +} + +cite { + font-size: 0.9rem; + color: var(--text-light); + font-style: normal; +} + +/* Use mono font for code like elements */ +code, +pre, +pre span, +kbd, +samp { + font-size: 1.075rem; + font-family: var(--mono-font); + color: var(--code); +} + +kbd { + color: var(--preformatted); + border: 1px solid var(--preformatted); + border-bottom: 3px solid var(--preformatted); + border-radius: 5px; + padding: 0.1rem; +} + +pre { + padding: 1rem 1.4rem; + max-width: 100%; + overflow: auto; + overflow-x: auto; + color: var(--preformatted); + background: var(--accent-bg); + border: 1px solid var(--border); + border-radius: 5px; +} + +/* Fix embedded code within pre */ +pre code { + color: var(--preformatted); + background: none; + margin: 0; + padding: 0; +} diff --git a/app/controllers/companies_controller.rb b/app/controllers/admin/companies_controller.rb similarity index 100% rename from app/controllers/companies_controller.rb rename to app/controllers/admin/companies_controller.rb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..550fcef --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,12 @@ +class HomeController < ApplicationController + def index + if user_signed_in? + if current_user.admin? + + else + end + end + + @companies = Company.all + end +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 0000000..a31a955 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1,5 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "@hotwired/turbo-rails" +import "controllers" +import "trix" +import "@rails/actiontext" diff --git a/app/models/ability.rb b/app/models/ability.rb new file mode 100644 index 0000000..ef26a8c --- /dev/null +++ b/app/models/ability.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class Ability + include CanCan::Ability + + def initialize(user) + # Define abilities for the passed in user here. For example: + # + # user ||= User.new # guest user (not logged in) + # if user.admin? + # can :manage, :all + # else + # can :read, :all + # end + # + # The first argument to `can` is the action you are giving the user + # permission to do. + # If you pass :manage it will apply to every action. Other common actions + # here are :read, :create, :update and :destroy. + # + # The second argument is the resource the user can perform the action on. + # If you pass :all it will apply to every resource. Otherwise pass a Ruby + # class of the resource. + # + # The third argument is an optional hash of conditions to further filter the + # objects. + # For example, here the user can only update published articles. + # + # can :update, Article, :published => true + # + # See the wiki for details: + # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities + end +end diff --git a/app/models/company.rb b/app/models/company.rb index f3ebdf4..702eb00 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,4 +1,5 @@ class Company < ApplicationRecord + has_and_belongs_to_many :users validates :name, presence: true validates :name, uniqueness: true diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..9513fc1 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,27 @@ +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + has_and_belongs_to_many :companies + devise :database_authenticatable, + :recoverable, :rememberable, :validatable + + def admin? + true if self.role == 1000 + end + + def user? + true if self.role == 100 + end + + def roletxt + role = "undefined" + if self.role == 1000 + role = "Admin" + end + + if self.role == 100 + role = "User" + end + role + end +end diff --git a/app/views/active_storage/blobs/_blob.html.erb b/app/views/active_storage/blobs/_blob.html.erb new file mode 100644 index 0000000..49ba357 --- /dev/null +++ b/app/views/active_storage/blobs/_blob.html.erb @@ -0,0 +1,14 @@ +
attachment--<%= blob.filename.extension %>"> + <% if blob.representable? %> + <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %> + <% end %> + +
+ <% if caption = blob.try(:caption) %> + <%= caption %> + <% else %> + <%= blob.filename %> + <%= number_to_human_size blob.byte_size %> + <% end %> +
+
diff --git a/app/views/home/.index.html.erb.kate-swp b/app/views/home/.index.html.erb.kate-swp deleted file mode 100644 index 85de230df532078e8fb358f95d37045358040d61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 68 zcmZQzU=Z?7EJ;-eE>A2_aLdd|RWQ;sU|?Vnneg|)ol`15EZ@F7;rH^0hu}PYg|y&s RpbR4r%esP@Oh6`sD*)<16Jh`W diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 90fde0d..0f574ba 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,2 +1,21 @@

CAF Compliance Tracking

By Hidden Agenda Ltd

+ +<% if !user_signed_in? %> +Not Signed in. + +<% else %> + <%#= current_user.roletxt %> + <% if current_user.admin? %> +

Companies

+ <%= link_to "Add Company", new_company_path %> + + <% @companies.each do |company| %> + <% end %> + <% end %> + + <% if current_user.user? %> + User Stuff here! + <% end %> + +<% end %> diff --git a/app/views/layouts/action_text/contents/_content.html.erb b/app/views/layouts/action_text/contents/_content.html.erb new file mode 100644 index 0000000..9e3c0d0 --- /dev/null +++ b/app/views/layouts/action_text/contents/_content.html.erb @@ -0,0 +1,3 @@ +
+ <%= yield -%> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 505543f..e18f8cf 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,12 +7,21 @@ <%= csp_meta_tag %> <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + <%= javascript_importmap_tags %> - +
<% if notice %>

<%= notice %>

<% end %> <% if alert %>

<%= alert %>

<% end %> - + +
<%= yield %> diff --git a/bin/importmap b/bin/importmap new file mode 100755 index 0000000..36502ab --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 0000000..9d84985 --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,3 @@ +# Pin npm packages by running ./bin/importmap + +pin "application", preload: true diff --git a/config/routes.rb b/config/routes.rb index 53bed76..72a99ad 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,11 @@ Rails.application.routes.draw do - resources :companies + devise_for :users + #resources :companies + + namespace :admin do + resources :companies + end + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Defines the root path route ("/") diff --git a/db/migrate/20220206152358_devise_create_users.rb b/db/migrate/20220206152358_devise_create_users.rb new file mode 100644 index 0000000..0de0b90 --- /dev/null +++ b/db/migrate/20220206152358_devise_create_users.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class DeviseCreateUsers < ActiveRecord::Migration[7.0] + def change + create_table :users do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, default: 0, null: false + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + t.string :unlock_token # Only if unlock strategy is :email or :both + t.datetime :locked_at + + t.integer :role + + t.timestamps null: false + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + add_index :users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20220206184745_create_active_storage_tables.active_storage.rb b/db/migrate/20220206184745_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..8a7bfe1 --- /dev/null +++ b/db/migrate/20220206184745_create_active_storage_tables.active_storage.rb @@ -0,0 +1,57 @@ +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[5.2] + def change + # Use Active Record's configured type for primary and foreign keys + primary_key_type, foreign_key_type = primary_and_foreign_key_types + + create_table :active_storage_blobs, id: primary_key_type do |t| + t.string :key, null: false + t.string :filename, null: false + t.string :content_type + t.text :metadata + t.string :service_name, null: false + t.bigint :byte_size, null: false + t.string :checksum + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [ :key ], unique: true + end + + create_table :active_storage_attachments, id: primary_key_type do |t| + t.string :name, null: false + t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type + t.references :blob, null: false, type: foreign_key_type + + if connection.supports_datetime_with_precision? + t.datetime :created_at, precision: 6, null: false + else + t.datetime :created_at, null: false + end + + t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + + create_table :active_storage_variant_records, id: primary_key_type do |t| + t.belongs_to :blob, null: false, index: false, type: foreign_key_type + t.string :variation_digest, null: false + + t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end + + private + def primary_and_foreign_key_types + config = Rails.configuration.generators + setting = config.options[config.orm][:primary_key_type] + primary_key_type = setting || :primary_key + foreign_key_type = setting || :bigint + [primary_key_type, foreign_key_type] + end +end diff --git a/db/migrate/20220206184746_create_action_text_tables.action_text.rb b/db/migrate/20220206184746_create_action_text_tables.action_text.rb new file mode 100644 index 0000000..1be48d7 --- /dev/null +++ b/db/migrate/20220206184746_create_action_text_tables.action_text.rb @@ -0,0 +1,26 @@ +# This migration comes from action_text (originally 20180528164100) +class CreateActionTextTables < ActiveRecord::Migration[6.0] + def change + # Use Active Record's configured type for primary and foreign keys + primary_key_type, foreign_key_type = primary_and_foreign_key_types + + create_table :action_text_rich_texts, id: primary_key_type do |t| + t.string :name, null: false + t.text :body, size: :long + t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type + + t.timestamps + + t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true + end + end + + private + def primary_and_foreign_key_types + config = Rails.configuration.generators + setting = config.options[config.orm][:primary_key_type] + primary_key_type = setting || :primary_key + foreign_key_type = setting || :bigint + [primary_key_type, foreign_key_type] + end +end diff --git a/db/migrate/20220208164226_create_users_and_companies.rb b/db/migrate/20220208164226_create_users_and_companies.rb new file mode 100644 index 0000000..e4ab1d8 --- /dev/null +++ b/db/migrate/20220208164226_create_users_and_companies.rb @@ -0,0 +1,8 @@ +class CreateUsersAndCompanies < ActiveRecord::Migration[7.0] + def change + create_table :companies_users, id: false do |t| + t.belongs_to :user + t.belongs_to :company + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 520c437..f3329ea 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,45 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_06_142432) do +ActiveRecord::Schema.define(version: 2022_02_08_164226) do + + create_table "action_text_rich_texts", charset: "latin1", force: :cascade do |t| + t.string "name", null: false + t.text "body", size: :long + t.string "record_type", null: false + t.bigint "record_id", null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true + end + + create_table "active_storage_attachments", charset: "latin1", force: :cascade do |t| + t.string "name", null: false + t.string "record_type", null: false + t.bigint "record_id", null: false + t.bigint "blob_id", null: false + t.datetime "created_at", precision: 6, null: false + t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true + end + + create_table "active_storage_blobs", charset: "latin1", force: :cascade do |t| + t.string "key", null: false + t.string "filename", null: false + t.string "content_type" + t.text "metadata" + t.string "service_name", null: false + t.bigint "byte_size", null: false + t.string "checksum" + t.datetime "created_at", precision: 6, null: false + t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true + end + + create_table "active_storage_variant_records", charset: "latin1", force: :cascade do |t| + t.bigint "blob_id", null: false + t.string "variation_digest", null: false + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end create_table "companies", charset: "latin1", force: :cascade do |t| t.string "name" @@ -18,4 +56,35 @@ ActiveRecord::Schema.define(version: 2022_02_06_142432) do t.datetime "updated_at", precision: 6, null: false end + create_table "companies_users", id: false, charset: "latin1", force: :cascade do |t| + t.bigint "user_id" + t.bigint "company_id" + t.index ["company_id"], name: "index_companies_users_on_company_id" + t.index ["user_id"], name: "index_companies_users_on_user_id" + end + + create_table "users", charset: "latin1", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at", precision: 6 + t.datetime "remember_created_at", precision: 6 + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at", precision: 6 + t.datetime "last_sign_in_at", precision: 6 + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.integer "failed_attempts", default: 0, null: false + t.string "unlock_token" + t.datetime "locked_at", precision: 6 + t.integer "role" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true + end + + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" end diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 0000000..eac0e33 --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class HomeControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/action_text/rich_texts.yml b/test/fixtures/action_text/rich_texts.yml new file mode 100644 index 0000000..8b371ea --- /dev/null +++ b/test/fixtures/action_text/rich_texts.yml @@ -0,0 +1,4 @@ +# one: +# record: name_of_fixture (ClassOfFixture) +# name: content +# body:

In a million stars!

diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..d7a3329 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..5c07f49 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/vendor/javascript/.keep b/vendor/javascript/.keep new file mode 100644 index 0000000..e69de29