Basic foundation for public collections

This commit is contained in:
Jorge Manrubia
2025-06-09 12:38:10 +02:00
parent 7d027f6699
commit 38e3582689
6 changed files with 98 additions and 3 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
class Collection < ApplicationRecord
include AutoClosing, Accessible, Broadcastable, Entropic, Filterable, Workflowing
include AutoClosing, Accessible, Broadcastable, Entropic, Filterable, Publishable, Workflowing
belongs_to :creator, class_name: "User", default: -> { Current.user }
+5
View File
@@ -0,0 +1,5 @@
class Collection::Publication < ApplicationRecord
belongs_to :collection
has_secure_token :key
end
+20
View File
@@ -0,0 +1,20 @@
module Collection::Publishable
extend ActiveSupport::Concern
included do
has_one :publication, class_name: "Collection::Publication", dependent: :destroy
scope :published, ->{ joins(:publication) }
end
def published?
publication.present?
end
def publish
create_publication! unless published?
end
def unpublish
publication&.destroy
end
end
@@ -0,0 +1,10 @@
class CreateCollectionPublications < ActiveRecord::Migration[8.1]
def change
create_table :collection_publications do |t|
t.references :collection, null: false, foreign_key: true, index: true
t.string :key, index: { unique: true }
t.timestamps
end
end
end
Generated
+11 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2025_06_04_120033) do
ActiveRecord::Schema[8.1].define(version: 2025_06_09_102553) do
create_table "accesses", force: :cascade do |t|
t.integer "collection_id", null: false
t.datetime "created_at", null: false
@@ -146,6 +146,15 @@ ActiveRecord::Schema[8.1].define(version: 2025_06_04_120033) do
t.index ["user_id"], name: "index_closures_on_user_id"
end
create_table "collection_publications", force: :cascade do |t|
t.integer "collection_id", null: false
t.datetime "created_at", null: false
t.string "key"
t.datetime "updated_at", null: false
t.index ["collection_id"], name: "index_collection_publications_on_collection_id"
t.index ["key"], name: "index_collection_publications_on_key", unique: true
end
create_table "collections", force: :cascade do |t|
t.boolean "all_access", default: false, null: false
t.datetime "created_at", null: false
@@ -361,6 +370,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_06_04_120033) do
add_foreign_key "cards", "workflow_stages", column: "stage_id"
add_foreign_key "closures", "cards"
add_foreign_key "closures", "users"
add_foreign_key "collection_publications", "collections"
add_foreign_key "collections", "workflows"
add_foreign_key "commands", "commands", column: "parent_id"
add_foreign_key "commands", "users"
+51 -1
View File
@@ -481,6 +481,21 @@ columns:
default_function:
collation:
comment:
collection_publications:
- *23
- *5
- *6
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
name: key
cast_type: *7
sql_type_metadata: *8
'null': true
default:
default_function:
collation:
comment:
- *9
collections:
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
@@ -1032,6 +1047,7 @@ primary_keys:
cards: id
closure_reasons: id
closures: id
collection_publications: id
collections: id
collections_filters:
commands: id
@@ -1072,6 +1088,7 @@ data_sources:
cards: true
closure_reasons: true
closures: true
collection_publications: true
collections: true
collections_filters: true
commands: true
@@ -1506,6 +1523,39 @@ indexes:
nulls_not_distinct:
comment:
valid: true
collection_publications:
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: collection_publications
name: index_collection_publications_on_collection_id
unique: false
columns:
- collection_id
lengths: {}
orders: {}
opclasses: {}
where:
type:
using:
include:
nulls_not_distinct:
comment:
valid: true
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: collection_publications
name: index_collection_publications_on_key
unique: true
columns:
- key
lengths: {}
orders: {}
opclasses: {}
where:
type:
using:
include:
nulls_not_distinct:
comment:
valid: true
collections:
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: collections
@@ -2235,4 +2285,4 @@ indexes:
comment:
valid: true
workflows: []
version: 20250604120033
version: 20250609102553