Skip to content

Commit e6ff7c8

Browse files
committed
Allow resources to be owned by a space. Only show resources from the current space when browsing
1 parent 029df39 commit e6ff7c8

21 files changed

Lines changed: 136 additions & 14 deletions

app/controllers/collections_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def create
7676
authorize Collection
7777
@collection = Collection.new(collection_params)
7878
@collection.user = current_user
79+
@collection.space = current_space
7980

8081
respond_to do |format|
8182
if @collection.save

app/controllers/events_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def create
149149
authorize Event
150150
@event = Event.new(event_params)
151151
@event.user = current_user
152+
@event.space = current_space
152153

153154
respond_to do |format|
154155
if @event.save

app/controllers/learning_path_topics_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def create
3535
authorize LearningPathTopic
3636
@learning_path_topic = LearningPathTopic.new(topic_params)
3737
@learning_path_topic.user = current_user
38+
@learning_path_topic.space = current_space
3839

3940
respond_to do |format|
4041
if @learning_path_topic.save

app/controllers/learning_paths_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def create
4848
authorize LearningPath
4949
@learning_path = LearningPath.new(learning_path_params)
5050
@learning_path.user = current_user
51+
@learning_path.space = current_space
5152

5253
respond_to do |format|
5354
if @learning_path.save

app/controllers/materials_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def create
9494
authorize Material
9595
@material = Material.new(material_params)
9696
@material.user = current_user
97+
@material.space = current_space
9798

9899
respond_to do |format|
99100
if @material.save

app/controllers/workflows_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def create
5151
authorize Workflow
5252
@workflow = Workflow.new(workflow_params)
5353
@workflow.user = current_user
54+
@workflow.space = current_space
5455

5556
respond_to do |format|
5657
if @workflow.save

app/models/collection.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Collection < ApplicationRecord
55
include HasFriendlyId
66
include CurationQueue
77
include Collaboratable
8+
include InSpace
89

910
has_many :items, -> { order(:order) }, class_name: 'CollectionItem', inverse_of: :collection, dependent: :destroy
1011
has_many :material_items, -> { where(resource_type: 'Material').order(:order) }, class_name: 'CollectionItem',

app/models/concerns/in_space.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module InSpace
2+
extend ActiveSupport::Concern
3+
4+
included do
5+
belongs_to :space, optional: true
6+
7+
if TeSS::Config.solr_enabled
8+
searchable do
9+
integer :space_id
10+
end
11+
end
12+
end
13+
14+
def space= s
15+
return if s.default?
16+
super
17+
end
18+
end

app/models/default_space.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ def url
55
end
66
end
77

8+
def id
9+
nil
10+
end
11+
812
def title
913
TeSS::Config.site['title_short']
1014
end
@@ -20,4 +24,32 @@ def image?
2024
def image
2125
Image.new
2226
end
27+
28+
def materials
29+
Material.all
30+
end
31+
32+
def events
33+
Event.all
34+
end
35+
36+
def workflows
37+
Workflow.all
38+
end
39+
40+
def collections
41+
Collection.all
42+
end
43+
44+
def learning_paths
45+
LearningPath.all
46+
end
47+
48+
def learning_path_topics
49+
LearningPathTopic.all
50+
end
51+
52+
def default?
53+
true
54+
end
2355
end

app/models/event.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Event < ApplicationRecord
1919
include WithTimezone
2020
include HasEdamTerms
2121
include HasLanguage
22+
include InSpace
2223

2324
before_validation :fix_keywords, on: :create, if: :scraper_record
2425
before_validation :presence_default

0 commit comments

Comments
 (0)