Skip to content

Commit

Permalink
Merge branch 'main' into protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
aviemet committed Apr 1, 2024
2 parents 590fa6f + 5181417 commit 0e4b153
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 26 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ gem "boolean_timestamp", "~> 1.1"
gem "jsonb_accessor", "~> 1.3"
gem "oj_serializers", "~> 2.0"
gem "types_from_serializers", "~> 2.1"
gem "public_activity", "~> 3.0"

# Helpers
gem "factory_bot", ">= 6.2"
gem "js-routes", "~> 2.2"
gem "foreman", "~> 0.87.2"
gem "amazing_print", "~> 1.4"
# gem "ruby-osc", "~> 1.0"
gem "eventmachine", "~> 1.2"
# gem "ruby-osc", "~> 1.0"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data"
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ GEM
pry (>= 0.10.4)
psych (5.1.2)
stringio
public_activity (3.0.1)
actionpack (>= 6.1.0)
activerecord (>= 6.1)
i18n (>= 0.5.0)
railties (>= 6.1.0)
public_suffix (5.0.4)
puma (6.4.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -444,6 +449,7 @@ DEPENDENCIES
pg (~> 1.1)
pg_search (~> 2.3)
pry-rails (~> 0.3.9)
public_activity (~> 3.0)
puma (~> 6.0)
pundit (~> 2.3)
pundit-matchers (~> 3.1)
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/api/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ class Api::ProtocolsController < ApplicationController

# @route PUT /api/protocol/:id/execute (api_execute_protocol)
def execute
render json: protocol, status: :accepted
protocol.create_activity key: :slug, owner: current_user

SendOscCommandsJob.perform_later(protocol)

render json: protocol, status: :accepted
end
end
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
include Pundit::Authorization
include PublicActivity::StoreController

protect_from_forgery with: :exception

Expand All @@ -22,8 +23,7 @@ class ApplicationController < ActionController::Base
}

if current_user
share_object[:menu] = {
}
share_object[:menu] = {}
end

share_object
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/Components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const TableComponent: TableComponent & TableObjects = ({
className,
wrapper = true,
fixed = false,
rowSpacing = true,
rowSpacing = false,
striped = true,
highlightOnHover = true,
...props
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/Pages/Servers/Index/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Routes } from '@/lib'
import { IndexPageTemplate } from '@/Layouts/AppLayout/Components'
import { IndexPageTemplate } from '@/Features'
import { NewIcon } from '@/Components/Icons'
import ServersTable from '../Table'

Expand Down
12 changes: 12 additions & 0 deletions app/frontend/types/routes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ export const apiSpotlights: ((
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

/**
* Generates rails route to
* /api/users/:id/update_table_preferences(.:format)
* @param {any} id
* @param {object | undefined} options
* @returns {string} route path
*/
export const apiUpdateTablePreferences: ((
id: RequiredRouteParameter,
options?: {format?: OptionalRouteParameter} & RouteOptions
) => string) & RouteHelperExtras;

/**
* Generates rails route to
* /api/users/:id/update_user_preferences(.:format)
Expand Down
9 changes: 9 additions & 0 deletions app/frontend/types/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,15 @@ export const apiExecuteProtocol = /*#__PURE__*/ __jsr.r({"id":{"r":true},"format
*/
export const apiSpotlights = /*#__PURE__*/ __jsr.r({"format":{}}, [2,[7,"/"],[2,[6,"api"],[2,[7,"/"],[2,[6,"spotlights"],[1,[2,[8,"."],[3,"format"]]]]]]]);

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

/**
* Generates rails route to
* /api/users/:id/update_user_preferences(.:format)
Expand Down
2 changes: 2 additions & 0 deletions app/jobs/send_osc_commands_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ def perform(protocol)
client.send(OscService::Message.new(command.message))
end
end
rescue Errno::ECONNREFUSED
server.create_activity key: :hostname
end
end
2 changes: 2 additions & 0 deletions app/models/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#
class Command < ApplicationRecord
include PgSearch::Model
include PublicActivity::Model

pg_search_scope(
:search,
Expand All @@ -37,6 +38,7 @@ class Command < ApplicationRecord
},
)

tracked owner: proc { |controller| controller&.current_user }
resourcify

enum :payload_type, { integer: 0, float: 1, string: 2, blob: 3, time: 4, symbol: 5, character: 6, boolean: 7 }
Expand Down
2 changes: 2 additions & 0 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
class Protocol < ApplicationRecord
include PgSearch::Model
include PublicActivity::Model

pg_search_scope(
:search,
Expand All @@ -25,6 +26,7 @@ class Protocol < ApplicationRecord
},
)

tracked owner: proc { |controller| controller&.current_user }
resourcify

slug :title
Expand Down
2 changes: 2 additions & 0 deletions app/models/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
class Server < ApplicationRecord
include PgSearch::Model
include PublicActivity::Model

pg_search_scope(
:search,
Expand All @@ -22,6 +23,7 @@ class Server < ApplicationRecord
},
)

tracked owner: proc { |controller| controller&.current_user }
resourcify

has_many :commands, dependent: :nullify
Expand Down
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# table_preferences :jsonb
# unconfirmed_email :string
# unlock_token :string
# user_preferences :jsonb
Expand All @@ -41,10 +42,14 @@
# index_users_on_invited_by (invited_by_type,invited_by_id)
# index_users_on_invited_by_id (invited_by_id)
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_table_preferences (table_preferences) USING gin
# index_users_on_unlock_token (unlock_token) UNIQUE
# index_users_on_user_preferences (user_preferences) USING gin
#
class User < ApplicationRecord
include PublicActivity::Model

tracked owner: proc { |controller| controller&.current_user }
resourcify
rolify

Expand Down
8 changes: 8 additions & 0 deletions app/policies/server_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ServerPolicy < ApplicationPolicy
class Scope < Scope
# NOTE: Be explicit about which records you allow access to!
# def resolve
# scope.all
# end
end
end
2 changes: 2 additions & 0 deletions app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# table_preferences :jsonb
# unconfirmed_email :string
# unlock_token :string
# user_preferences :jsonb
Expand All @@ -41,6 +42,7 @@
# index_users_on_invited_by (invited_by_type,invited_by_id)
# index_users_on_invited_by_id (invited_by_id)
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_table_preferences (table_preferences) USING gin
# index_users_on_unlock_token (unlock_token) UNIQUE
# index_users_on_user_preferences (user_preferences) USING gin
#
Expand Down
1 change: 1 addition & 0 deletions config/routes/api.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace :api do
resources :users, only: [:create, :update]
patch "users/:id/update_user_preferences" => "users#update_user_preferences", as: :update_user_preferences
patch "users/:id/update_table_preferences" => "users#update_table_preferences", as: :update_table_preferences

resources :spotlights, only: [:index]

Expand Down
3 changes: 3 additions & 0 deletions db/migrate/20230521142961_add_fields_to_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ def change
change_table :users, bulk: true do |t|
t.boolean :active, default: true, null: false

t.jsonb :table_preferences, default: {}
t.index :table_preferences, using: :gin

t.jsonb :user_preferences, default: {}
t.index :user_preferences, using: :gin
end
Expand Down
25 changes: 25 additions & 0 deletions db/migrate/20240331175622_create_activities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

# Migration responsible for creating a table with activities
class CreateActivities < ActiveRecord::Migration[6.1]
def self.up
create_table :activities do |t|
t.belongs_to :trackable, polymorphic: true
t.belongs_to :owner, polymorphic: true
t.string :key
t.text :parameters
t.belongs_to :recipient, polymorphic: true

t.timestamps
end

add_index :activities, %i[trackable_id trackable_type]
add_index :activities, %i[owner_id owner_type]
add_index :activities, %i[recipient_id recipient_type]
end

# Drop table
def self.down
drop_table :activities
end
end
23 changes: 22 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# table_preferences :jsonb
# unconfirmed_email :string
# unlock_token :string
# user_preferences :jsonb
Expand All @@ -41,6 +42,7 @@
# index_users_on_invited_by (invited_by_type,invited_by_id)
# index_users_on_invited_by_id (invited_by_id)
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_table_preferences (table_preferences) USING gin
# index_users_on_unlock_token (unlock_token) UNIQUE
# index_users_on_user_preferences (user_preferences) USING gin
#
Expand Down
2 changes: 2 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# reset_password_sent_at :datetime
# reset_password_token :string
# sign_in_count :integer default(0), not null
# table_preferences :jsonb
# unconfirmed_email :string
# unlock_token :string
# user_preferences :jsonb
Expand All @@ -41,6 +42,7 @@
# index_users_on_invited_by (invited_by_type,invited_by_id)
# index_users_on_invited_by_id (invited_by_id)
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_table_preferences (table_preferences) USING gin
# index_users_on_unlock_token (unlock_token) UNIQUE
# index_users_on_user_preferences (user_preferences) USING gin
#
Expand Down
27 changes: 27 additions & 0 deletions spec/policies/server_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'rails_helper'

RSpec.describe ServerPolicy, type: :policy do
let(:user) { User.new }

subject { described_class }

permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
end

permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end

permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end

permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end

permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
end
end
Loading

0 comments on commit 0e4b153

Please sign in to comment.