Skip to content

Commit

Permalink
fix: bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed Jun 12, 2024
1 parent 358ce78 commit ea3a818
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ node_modules
# Vite uses dotenv and suggests to ignore local-only env files. See
# https://vitejs.dev/guide/env-and-mode.html#env-files
*.local

/config/secrets/master.key
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ WORKDIR /osc
# Set production environment
ENV RAILS_LOG_TO_STDOUT="1"
ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_ENV production
ENV RAILS_ENV=production
ENV RACK_ENV=production
ENV NODE_ENV=production
# ENV BUNDLE_WITHOUT development
ENV NODE_ENV production

# Install application gems
COPY Gemfile Gemfile.lock ./
Expand All @@ -49,7 +50,7 @@ RUN ./docker_copy_files.sh
RUN bundle exec bootsnap precompile --gemfile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE=DUMMY bundle exec rails assets:precompile
RUN RACK_ENV=production RAILS_ENV=production NODE_ENV=production SECRET_KEY_BASE=DUMMY bundle exec rails assets:precompile

# Entrypoint prepares the database
ENTRYPOINT ["/osc/bin/docker-entrypoint"]
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.1)
nokogiri (1.16.4-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.4-x86_64-linux)
Expand Down Expand Up @@ -420,6 +422,7 @@ GEM
zeitwerk (2.6.13)

PLATFORMS
aarch64-linux
arm64-darwin-22
arm64-darwin-23
x86_64-linux
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bin/rails server
13 changes: 11 additions & 2 deletions app/controllers/screens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ class ScreensController < ApplicationController
expose :screen, id: -> { params[:slug] }, scope: -> { Screen.includes_associated }, find_by: :slug
expose :main_screen, -> { Screen.order(:order).first }

skip_before_action :authenticate_user!, only: [:index, :show]

# @route GET / (root)
# @route GET /screens (screens)
def index
redirect_to main_screen
redirect_to main_screen || new_screen_path
end

# @route GET /screens/:slug (screen)
def show
authorize screen
render inertia: "Screens/Show", props: {
screen: -> { screen.render(view: :show) },
screens: -> { Screen.all.render(view: :options) },
}
end

# @route GET /screens/new (new_screen)
def new
authorize Screen.new
render inertia: "Screens/New", props: {
screen: Screen.new.render(view: :form_data)
}
end

# @route GET /screens/edit (edit_screens)
# @route GET /screens/:slug/edit (edit_screen)
def edit
Expand Down
1 change: 0 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class UsersController < ApplicationController
include Searchable
include ContactableConcern

expose :users, -> { search(User.all.includes_associated, sortable_fields) }
expose :user, id: -> { params[:slug] }, scope: -> { Circle.includes_associated }, find_by: :slug
Expand Down
20 changes: 20 additions & 0 deletions app/frontend/Components/Section/Section.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { vars, theme } from '@/lib/theme'
import { rem } from '@mantine/core'
import { css } from '@linaria/core'

export const section = css`
${vars.lightSelector} {
background-color: ${vars.colors.white};
}
${vars.darkSelector} {
background-color: ${vars.colors.gray[9]};
}
box-shadow: ${vars.shadows.xs};
padding: 1rem 0.75rem;
border-top: 2px solid ${vars.colors.primaryColors.filled};
& + & {
margin-top: ${rem(10)};
}
`
9 changes: 0 additions & 9 deletions app/frontend/Components/Section/Section.module.css

This file was deleted.

5 changes: 3 additions & 2 deletions app/frontend/Components/Section/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import { Box, ElementProps, type BoxProps } from '@mantine/core'

import cx from 'clsx'
import classes from './Section.module.css'
import * as classes from './Section.css'

interface ISectionProps extends BoxProps, ElementProps<'section'> {
fullHeight?: boolean
Expand All @@ -11,7 +12,7 @@ const Section = ({ children, fullHeight = false, className, ...props }: ISection
return (
<Box
component="section"
className={ cx(classes, className, { fullHeight }) }
className={ cx(classes.section, className, { fullHeight }) }
{ ...props }
>
{ children }
Expand Down
16 changes: 16 additions & 0 deletions app/frontend/Pages/Error/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

interface ErrorProps {
status: any
}

const Error = ({ status }: ErrorProps) => {
return (
<>
<div>Error</div>
<div>{ status }</div>
</>
)
}

export default Error
2 changes: 1 addition & 1 deletion app/frontend/Pages/Screens/Components/Control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Control = forwardRef<HTMLButtonElement,ControlProps>((
ref,
) => {
const sharedProps = {
className: cx(className, { [classes.editControl]: edit }),
className: cx(className),
ref,
}

Expand Down
22 changes: 6 additions & 16 deletions app/frontend/types/routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,31 +468,31 @@ export const newProtocol: ((

/**
* Generates rails route to
* /servers/new(.:format)
* /screens/new(.:format)
* @param {object | undefined} options
* @returns {string} route path
*/
export const newServer: ((
export const newScreen: ((
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

/**
* Generates rails route to
* /users/new(.:format)
* /servers/new(.:format)
* @param {object | undefined} options
* @returns {string} route path
*/
export const newUser: ((
export const newServer: ((
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

/**
* Generates rails route to
* /users/confirmation/new(.:format)
* /users/new(.:format)
* @param {object | undefined} options
* @returns {string} route path
*/
export const newUserConfirmation: ((
export const newUser: ((
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

Expand Down Expand Up @@ -636,16 +636,6 @@ export const user: ((
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

/**
* Generates rails route to
* /users/confirmation(.:format)
* @param {object | undefined} options
* @returns {string} route path
*/
export const userConfirmation: ((
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

/**
* Generates rails route to
* /users/password(.:format)
Expand Down
20 changes: 6 additions & 14 deletions app/frontend/types/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,27 +831,27 @@ export const newProtocol = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6

/**
* Generates rails route to
* /servers/new(.:format)
* /screens/new(.:format)
* @param {object | undefined} options
* @returns {string} route path
*/
export const newServer = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6,"servers"],[2,[7,"/"],[2,[6,"new"],[1,[2,[8,"."],[3,"format"]]]]]]]);
export const newScreen = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6,"screens"],[2,[7,"/"],[2,[6,"new"],[1,[2,[8,"."],[3,"format"]]]]]]]);

/**
* Generates rails route to
* /users/new(.:format)
* /servers/new(.:format)
* @param {object | undefined} options
* @returns {string} route path
*/
export const newUser = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6,"users"],[2,[7,"/"],[2,[6,"new"],[1,[2,[8,"."],[3,"format"]]]]]]]);
export const newServer = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6,"servers"],[2,[7,"/"],[2,[6,"new"],[1,[2,[8,"."],[3,"format"]]]]]]]);

/**
* Generates rails route to
* /users/confirmation/new(.:format)
* /users/new(.:format)
* @param {object | undefined} options
* @returns {string} route path
*/
export const newUserConfirmation = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6,"users"],[2,[7,"/"],[2,[6,"confirmation"],[2,[7,"/"],[2,[6,"new"],[1,[2,[8,"."],[3,"format"]]]]]]]]]);
export const newUser = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6,"users"],[2,[7,"/"],[2,[6,"new"],[1,[2,[8,"."],[3,"format"]]]]]]]);

/**
* Generates rails route to
Expand Down Expand Up @@ -962,14 +962,6 @@ export const updateRailsDiskService = /*#__PURE__*/ __jsr.r({"encoded_token":{"r
*/
export const user = /*#__PURE__*/ __jsr.r({"id":{"r":true},"format":{}}, [2,[7,"/"],[2,[6,"users"],[2,[7,"/"],[2,[3,"id"],[1,[2,[8,"."],[3,"format"]]]]]]]);

/**
* Generates rails route to
* /users/confirmation(.:format)
* @param {object | undefined} options
* @returns {string} route path
*/
export const userConfirmation = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6,"users"],[2,[7,"/"],[2,[6,"confirmation"],[1,[2,[8,"."],[3,"format"]]]]]]]);

/**
* Generates rails route to
* /users/password(.:format)
Expand Down
Empty file removed app/lib/tasks/annotate.rb
Empty file.
4 changes: 3 additions & 1 deletion app/models/screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Screen < ApplicationRecord

scope :includes_associated, -> { includes([:controls]) }

validates :title, format: { without: /new/ }

accepts_nested_attributes_for :controls, reject_if: ->(attributes) { attributes['title'].blank? }, allow_destroy: true

private
Expand All @@ -43,6 +45,6 @@ def set_screen_order
return unless self.order.nil?

last_screen = Screen.order(:order).last
self.order = last_screen.order + 1
self.order = last_screen.nil? ? 1 : last_screen.order + 1
end
end
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class User < ApplicationRecord
resourcify
rolify

# :omniauthable, :timeoutable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :confirmable, :lockable, :trackable
# :omniauthable, :timeoutable, :confirmable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :lockable, :trackable

scope :includes_associated, -> { includes([:circles]) }

Expand Down
4 changes: 3 additions & 1 deletion app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def destroy?
private

def standard_auth(_action)
user.has_role?(:super_admin)
return true if user&.has_role?(:super_admin)

!user.nil?
end
end
15 changes: 12 additions & 3 deletions bin/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/bin/bash -e

# If running the rails server then create or migrate existing database
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
./bin/rails db:prepare
# Check if master.key exists
if [ ! -f /osc/config/secrets/master.key ]; then
echo "Generating master.key..."
# Run the rails credentials:edit command in non-interactive mode
EDITOR="echo" rails credentials:edit
fi

rm -f tmp/pids/server.pid

/osc/bin/rails db:prepare
/osc/bin/rails db:seed

RACK_ENV="production" RAILS_ENV="production" NODE_ENV="production" /osc/bin/rails server

exec "${@}"
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# config.assets.css_compressor = :sass

# Do not fall back to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# config.assets.compile = false

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
resources :users
resources :servers, param: :slug
get "screens/edit", to: "screens#edit", as: "edit_screens"
resources :screens, param: :slug, except: [:new]
resources :screens, param: :slug
resources :protocols, param: :slug
resources :commands, param: :slug
resources :controls, only: [:create, :update, :destroy]
Expand Down
2 changes: 1 addition & 1 deletion config/secrets/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
xHhAOBZLKEaTJ/9qV9XhMqoBGlI7ImpGAEQhUTc1VJ9kgcp8K3H50oFMew3XPO4WNp30MMAy3xRQ4d2/xLG8PDUZ9dINxOae+lCro/vbJPNe3eYkVHAB/2O0iSeFSrr+Cg2D/NsM0cWy4X0H/E7+b0xNah/NvBokM51/OUOGa2q6c7621WzOHz7ODElpVeNkF3UrUHnbFfKCstATj4sjkV9HYx3iDoMmANITpvG/Z+To75zBacVqGJ59+G3bsdsnW61FuTdIsLMElgzgZY1FKzJMnDG8VA6QeBG2YzPnzgV+07RzwTFZ3PbsFi7m134SOZzoX6DlQX+zVtUM8d6qO465uLM3VPllTLgb8sy4/vdElolna2rgMsiXsd/P47UJMAwbdfPgVG9sWJ+uiUhHEXdswPd3LchffncH--7YUaJqXSCfgaa9GR--iy2s+hie4ej5vbzXddVObw==
TXuAMWs7AfNfRonXDEUv++Ed24cTyGBwQEb85xbEjPVl+yqCv9OZ9j0F46vxnd1vXo5kG3Pr8PNo5xUx9hkLZh6JNCFRkpSgOzt5zDPrzW5Hg7C987F+BWU2dhJ9KCwP7+qWTE3BO/Z/BT7ekGFzyuu48oVDlOR1Z0fA4uFBwWl30Ihh97Zcp9nn78cJYvGCqGruJF8Lzc+N+PWXEG8Fl53MzfYOuLKOyqOx7H0LbIKJ2QRNRt66N5qEcE2WXMrhEMEiZjYFoaOdceGPYYqByeEBodiQr91y9FlkVDqhqKPlZb4pvrcZhbxSRkLIxgSROUZjaw7V0n09CyUgfHRyHAEnxJpQ0ZvMTrKI3YDFYFS/0Y1J/1KohdlzmeGTHLsGshvXl6RzTnie9nGoF8pwaGB2FjPq--1kPIShbOUb8jaR+W--1ral2EJGXvcmtzxx4sqm7A==
3 changes: 3 additions & 0 deletions db/seeds/01_required.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if Screen.count === 0
Screen.create title: "Main"
end
35 changes: 35 additions & 0 deletions docker_copy_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

source_paths=(
./yarn
./app
./bin
./config
./db
./lib
./public
./ruby-version
./.yarnrc.yml
./config.ru
./Gemfile
./Gemfile.lock
./package.json
./postcss.config.mjs
./Rakefile
./static.json
./tsconfig.json
./vite.config.ts
./yarn.lock
)

destination_dir=/osc/

cp "${source_paths[@]}" "$destination_dir"

mkdir ./log
mkdir ./tmp

rm -f /osc/config/secrets/master.key
rm -f /osc/config/secrets/credentials.yml.enc

exit 0
3 changes: 3 additions & 0 deletions lib/custom_failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def respond_to_failure_types
# Account with unconfirmed email
elsif message == :unconfirmed
redirect_to new_user_confirmation_path({ email: params[:user][:email] })
elsif message == :unauthenticated
self.headers['x-inertia'] = true
redirect_to new_user_session_path
end
end

Expand Down
Loading

0 comments on commit ea3a818

Please sign in to comment.