Add private urls to tables
This commit is contained in:
parent
2f4d0eb34f
commit
e1deb80c6a
1
Gemfile
1
Gemfile
@ -76,3 +76,4 @@ group :test, :staging do
|
|||||||
gem 'simplecov', :require => false
|
gem 'simplecov', :require => false
|
||||||
end
|
end
|
||||||
gem 'capybara-screenshot', :group => :test
|
gem 'capybara-screenshot', :group => :test
|
||||||
|
gem 'friendly_id', '~> 5.4.0'
|
||||||
|
|||||||
@ -161,6 +161,8 @@ GEM
|
|||||||
i18n (>= 1.6, < 2)
|
i18n (>= 1.6, < 2)
|
||||||
ffi (1.15.4)
|
ffi (1.15.4)
|
||||||
formatador (0.3.0)
|
formatador (0.3.0)
|
||||||
|
friendly_id (5.4.2)
|
||||||
|
activerecord (>= 4.0.0)
|
||||||
globalid (0.5.2)
|
globalid (0.5.2)
|
||||||
activesupport (>= 5.0)
|
activesupport (>= 5.0)
|
||||||
guard (2.18.0)
|
guard (2.18.0)
|
||||||
@ -455,6 +457,7 @@ DEPENDENCIES
|
|||||||
ed25519
|
ed25519
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
faker
|
faker
|
||||||
|
friendly_id (~> 5.4.0)
|
||||||
guard-bundler
|
guard-bundler
|
||||||
guard-ctags-bundler
|
guard-ctags-bundler
|
||||||
guard-livereload
|
guard-livereload
|
||||||
|
|||||||
@ -160,3 +160,6 @@ footer
|
|||||||
#skyspaces
|
#skyspaces
|
||||||
width: 100%
|
width: 100%
|
||||||
height: 100%
|
height: 100%
|
||||||
|
|
||||||
|
.hide
|
||||||
|
display: none
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
button,
|
button,
|
||||||
input[type=submit]
|
input[type=submit]
|
||||||
font-size: 4vmin
|
font-size: 4vmin
|
||||||
|
&.smallbtn
|
||||||
|
font-size: 2vmin
|
||||||
|
|
||||||
#table-component,
|
#table-component,
|
||||||
#game-component-container-container
|
#game-component-container-container
|
||||||
|
|||||||
@ -2,6 +2,10 @@
|
|||||||
width: 100%
|
width: 100%
|
||||||
height: 100%
|
height: 100%
|
||||||
|
|
||||||
|
.owner-controls
|
||||||
|
form
|
||||||
|
display: inline-block
|
||||||
|
|
||||||
#table-controls
|
#table-controls
|
||||||
text-align: right
|
text-align: right
|
||||||
padding: 0 1em
|
padding: 0 1em
|
||||||
|
|||||||
@ -60,17 +60,18 @@ class TablesController < ApplicationController
|
|||||||
|
|
||||||
# GET /tables/new
|
# GET /tables/new
|
||||||
def new
|
def new
|
||||||
@table = Table.new
|
authorize @table = Table.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /tables/1/edit
|
# GET /tables/1/edit
|
||||||
def edit
|
def edit
|
||||||
|
authorize @table
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /tables
|
# POST /tables
|
||||||
# POST /tables.json
|
# POST /tables.json
|
||||||
def create
|
def create
|
||||||
@table = Table.new(table_params)
|
authorize @table = Table.new(table_params)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @table.save
|
if @table.save
|
||||||
@ -86,6 +87,7 @@ class TablesController < ApplicationController
|
|||||||
# PATCH/PUT /tables/1
|
# PATCH/PUT /tables/1
|
||||||
# PATCH/PUT /tables/1.json
|
# PATCH/PUT /tables/1.json
|
||||||
def update
|
def update
|
||||||
|
authorize @table
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @table.update(table_params)
|
if @table.update(table_params)
|
||||||
format.html { redirect_to @table, notice: 'Table was successfully updated.' }
|
format.html { redirect_to @table, notice: 'Table was successfully updated.' }
|
||||||
@ -100,6 +102,7 @@ class TablesController < ApplicationController
|
|||||||
# DELETE /tables/1
|
# DELETE /tables/1
|
||||||
# DELETE /tables/1.json
|
# DELETE /tables/1.json
|
||||||
def destroy
|
def destroy
|
||||||
|
authorize @table
|
||||||
@table.destroy
|
@table.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to tables_url, notice: 'Table was successfully destroyed.' }
|
format.html { redirect_to tables_url, notice: 'Table was successfully destroyed.' }
|
||||||
@ -110,7 +113,8 @@ class TablesController < ApplicationController
|
|||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_table
|
def set_table
|
||||||
@table = Table.find(params[:id])
|
# @table = Table.find(params[:id])
|
||||||
|
@table = Table.friendly.find(params[:id])
|
||||||
@game = @table.current_game
|
@game = @table.current_game
|
||||||
@seats = @table.seats.order(:id)
|
@seats = @table.seats.order(:id)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
class Table < ActiveRecord::Base
|
class Table < ActiveRecord::Base
|
||||||
|
extend FriendlyId
|
||||||
|
friendly_id :title, use: :slugged
|
||||||
#TODO has_many :moderators
|
#TODO has_many :moderators
|
||||||
has_many :seats
|
has_many :seats
|
||||||
has_many :users, through: :seats
|
has_many :users, through: :seats
|
||||||
@ -19,7 +21,7 @@ class Table < ActiveRecord::Base
|
|||||||
# }
|
# }
|
||||||
scope :play_now, lambda { |user|
|
scope :play_now, lambda { |user|
|
||||||
# where(status:nil).joins("LEFT OUTER JOIN players ON players.game_id = games.id").group("games.id").having("count(players) < 4").last || Table.create(title: "Game " + user.soft_token[0..4])
|
# where(status:nil).joins("LEFT OUTER JOIN players ON players.game_id = games.id").group("games.id").having("count(players) < 4").last || Table.create(title: "Game " + user.soft_token[0..4])
|
||||||
where(game:nil).last || Table.create(title: "Table " + user.soft_token[0..4])
|
where(game:nil).last || Table.create(title: user.soft_token[0..4])
|
||||||
}
|
}
|
||||||
|
|
||||||
def user_count
|
def user_count
|
||||||
|
|||||||
@ -14,6 +14,18 @@ class TablePolicy
|
|||||||
@current_user.admin? || @current_user == @user
|
@current_user.admin? || @current_user == @user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create?
|
||||||
|
@current_user.admin?
|
||||||
|
end
|
||||||
|
|
||||||
|
def new?
|
||||||
|
@current_user.admin?
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit?
|
||||||
|
@current_user.admin?
|
||||||
|
end
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
@current_user.admin? # TODO: Allow table owner to edit || @table.owner == @current_user
|
@current_user.admin? # TODO: Allow table owner to edit || @table.owner == @current_user
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
= link_to (image_tag "telegram-logo.png", height: 32, width: 32), "https://t.me/+IEp-tAetjYozYWM5"
|
-# = link_to (image_tag "telegram-logo.png", height: 32, width: 32), "https://t.me/+IEp-tAetjYozYWM5"
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
- if policy(@table).update?
|
|
||||||
.owner-controls
|
|
||||||
= link_to 'Edit', edit_table_path(@table)
|
|
||||||
= link_to 'Destroy', game, :method => :delete, :data => { :confirm => 'Are you sure?' }
|
|
||||||
|
|
||||||
-# #table-component-container-container= react_component 'Table', props = {url: "#{table_path @table}"}, html_options = {id: "table-component-container"}
|
-# #table-component-container-container= react_component 'Table', props = {url: "#{table_path @table}"}, html_options = {id: "table-component-container"}
|
||||||
#table-component
|
#table-component
|
||||||
|
|
||||||
%p= @table.title
|
%p
|
||||||
|
Table:
|
||||||
|
= @table.title
|
||||||
|
|
||||||
|
- if policy(@table).update?
|
||||||
|
.owner-controls
|
||||||
|
= button_to 'Rename', edit_table_path(@table), class: "smallbtn", method: :get
|
||||||
|
= button_to 'Delete', @game, :method => :delete, :data => { :confirm => 'Are you sure?' }, class: "smallbtn"
|
||||||
|
|
||||||
- if @game.already_has?(current_user)
|
- if @game.already_has?(current_user)
|
||||||
- if @game.startable?
|
- if @game.startable?
|
||||||
@ -57,3 +59,6 @@
|
|||||||
:javascript
|
:javascript
|
||||||
var soft_token = "#{current_user.soft_token}";
|
var soft_token = "#{current_user.soft_token}";
|
||||||
-# = javascript_include_tag 'table-loader'
|
-# = javascript_include_tag 'table-loader'
|
||||||
|
|
||||||
|
-# - if @table.skyspace_url
|
||||||
|
%iframe#skyspaces{allow:"camera #{@table.skyspace_url}; microphone #{@table.skyspace_url}", src: "#{@table.skyspace_url}"}
|
||||||
|
|||||||
107
config/initializers/friendly_id.rb
Normal file
107
config/initializers/friendly_id.rb
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
# FriendlyId Global Configuration
|
||||||
|
#
|
||||||
|
# Use this to set up shared configuration options for your entire application.
|
||||||
|
# Any of the configuration options shown here can also be applied to single
|
||||||
|
# models by passing arguments to the `friendly_id` class method or defining
|
||||||
|
# methods in your model.
|
||||||
|
#
|
||||||
|
# To learn more, check out the guide:
|
||||||
|
#
|
||||||
|
# http://norman.github.io/friendly_id/file.Guide.html
|
||||||
|
|
||||||
|
FriendlyId.defaults do |config|
|
||||||
|
# ## Reserved Words
|
||||||
|
#
|
||||||
|
# Some words could conflict with Rails's routes when used as slugs, or are
|
||||||
|
# undesirable to allow as slugs. Edit this list as needed for your app.
|
||||||
|
config.use :reserved
|
||||||
|
|
||||||
|
config.reserved_words = %w(new edit index session login logout users admin
|
||||||
|
stylesheets assets javascripts images)
|
||||||
|
|
||||||
|
# This adds an option to treat reserved words as conflicts rather than exceptions.
|
||||||
|
# When there is no good candidate, a UUID will be appended, matching the existing
|
||||||
|
# conflict behavior.
|
||||||
|
|
||||||
|
# config.treat_reserved_as_conflict = true
|
||||||
|
|
||||||
|
# ## Friendly Finders
|
||||||
|
#
|
||||||
|
# Uncomment this to use friendly finders in all models. By default, if
|
||||||
|
# you wish to find a record by its friendly id, you must do:
|
||||||
|
#
|
||||||
|
# MyModel.friendly.find('foo')
|
||||||
|
#
|
||||||
|
# If you uncomment this, you can do:
|
||||||
|
#
|
||||||
|
# MyModel.find('foo')
|
||||||
|
#
|
||||||
|
# This is significantly more convenient but may not be appropriate for
|
||||||
|
# all applications, so you must explicity opt-in to this behavior. You can
|
||||||
|
# always also configure it on a per-model basis if you prefer.
|
||||||
|
#
|
||||||
|
# Something else to consider is that using the :finders addon boosts
|
||||||
|
# performance because it will avoid Rails-internal code that makes runtime
|
||||||
|
# calls to `Module.extend`.
|
||||||
|
#
|
||||||
|
# config.use :finders
|
||||||
|
#
|
||||||
|
# ## Slugs
|
||||||
|
#
|
||||||
|
# Most applications will use the :slugged module everywhere. If you wish
|
||||||
|
# to do so, uncomment the following line.
|
||||||
|
#
|
||||||
|
# config.use :slugged
|
||||||
|
#
|
||||||
|
# By default, FriendlyId's :slugged addon expects the slug column to be named
|
||||||
|
# 'slug', but you can change it if you wish.
|
||||||
|
#
|
||||||
|
# config.slug_column = 'slug'
|
||||||
|
#
|
||||||
|
# By default, slug has no size limit, but you can change it if you wish.
|
||||||
|
#
|
||||||
|
# config.slug_limit = 255
|
||||||
|
#
|
||||||
|
# When FriendlyId can not generate a unique ID from your base method, it appends
|
||||||
|
# a UUID, separated by a single dash. You can configure the character used as the
|
||||||
|
# separator. If you're upgrading from FriendlyId 4, you may wish to replace this
|
||||||
|
# with two dashes.
|
||||||
|
#
|
||||||
|
# config.sequence_separator = '-'
|
||||||
|
#
|
||||||
|
# Note that you must use the :slugged addon **prior** to the line which
|
||||||
|
# configures the sequence separator, or else FriendlyId will raise an undefined
|
||||||
|
# method error.
|
||||||
|
#
|
||||||
|
# ## Tips and Tricks
|
||||||
|
#
|
||||||
|
# ### Controlling when slugs are generated
|
||||||
|
#
|
||||||
|
# As of FriendlyId 5.0, new slugs are generated only when the slug field is
|
||||||
|
# nil, but if you're using a column as your base method can change this
|
||||||
|
# behavior by overriding the `should_generate_new_friendly_id?` method that
|
||||||
|
# FriendlyId adds to your model. The change below makes FriendlyId 5.0 behave
|
||||||
|
# more like 4.0.
|
||||||
|
# Note: Use(include) Slugged module in the config if using the anonymous module.
|
||||||
|
# If you have `friendly_id :name, use: slugged` in the model, Slugged module
|
||||||
|
# is included after the anonymous module defined in the initializer, so it
|
||||||
|
# overrides the `should_generate_new_friendly_id?` method from the anonymous module.
|
||||||
|
#
|
||||||
|
# config.use :slugged
|
||||||
|
# config.use Module.new {
|
||||||
|
# def should_generate_new_friendly_id?
|
||||||
|
# slug.blank? || <your_column_name_here>_changed?
|
||||||
|
# end
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# FriendlyId uses Rails's `parameterize` method to generate slugs, but for
|
||||||
|
# languages that don't use the Roman alphabet, that's not usually sufficient.
|
||||||
|
# Here we use the Babosa library to transliterate Russian Cyrillic slugs to
|
||||||
|
# ASCII. If you use this, don't forget to add "babosa" to your Gemfile.
|
||||||
|
#
|
||||||
|
# config.use Module.new {
|
||||||
|
# def normalize_friendly_id(text)
|
||||||
|
# text.to_slug.normalize! :transliterations => [:russian, :latin]
|
||||||
|
# end
|
||||||
|
# }
|
||||||
|
end
|
||||||
5
db/migrate/20230505072838_add_skyspace_url_to_table.rb
Normal file
5
db/migrate/20230505072838_add_skyspace_url_to_table.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class AddSkyspaceUrlToTable < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :tables, :skyspace_url, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
6
db/migrate/20230510103640_add_slug_to_tables.rb
Normal file
6
db/migrate/20230510103640_add_slug_to_tables.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class AddSlugToTables < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :tables, :slug, :string
|
||||||
|
add_index :tables, :slug, unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
21
db/migrate/20230510103647_create_friendly_id_slugs.rb
Normal file
21
db/migrate/20230510103647_create_friendly_id_slugs.rb
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIGRATION_CLASS =
|
||||||
|
if ActiveRecord::VERSION::MAJOR >= 5
|
||||||
|
ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
|
||||||
|
else
|
||||||
|
ActiveRecord::Migration
|
||||||
|
end
|
||||||
|
|
||||||
|
class CreateFriendlyIdSlugs < MIGRATION_CLASS
|
||||||
|
def change
|
||||||
|
create_table :friendly_id_slugs do |t|
|
||||||
|
t.string :slug, :null => false
|
||||||
|
t.integer :sluggable_id, :null => false
|
||||||
|
t.string :sluggable_type, :limit => 50
|
||||||
|
t.string :scope
|
||||||
|
t.datetime :created_at
|
||||||
|
end
|
||||||
|
add_index :friendly_id_slugs, [:sluggable_type, :sluggable_id]
|
||||||
|
add_index :friendly_id_slugs, [:slug, :sluggable_type], length: { slug: 140, sluggable_type: 50 }
|
||||||
|
add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], length: { slug: 70, sluggable_type: 50, scope: 70 }, unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
16
db/schema.rb
16
db/schema.rb
@ -10,11 +10,22 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2021_11_08_045859) do
|
ActiveRecord::Schema.define(version: 2023_05_10_103647) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
create_table "friendly_id_slugs", force: :cascade do |t|
|
||||||
|
t.string "slug", null: false
|
||||||
|
t.integer "sluggable_id", null: false
|
||||||
|
t.string "sluggable_type", limit: 50
|
||||||
|
t.string "scope"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true
|
||||||
|
t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type"
|
||||||
|
t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "games", force: :cascade do |t|
|
create_table "games", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
@ -85,6 +96,9 @@ ActiveRecord::Schema.define(version: 2021_11_08_045859) do
|
|||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "current_game_id"
|
t.integer "current_game_id"
|
||||||
|
t.string "skyspace_url"
|
||||||
|
t.string "slug"
|
||||||
|
t.index ["slug"], name: "index_tables_on_slug", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user