@@ -9,9 +9,7 @@
<%= icon icon_for(thing.class), thing.class.model_name.human %>
- <%- if thing.is_a?(User) %>
- <%= object.name %>
- <%- elsif object.local? %>
+ <%- if object.local? %>
<%= link_to thing.name, thing %>
<%- elsif object.profile_url %>
<%= link_to object.name, object.profile_url %>
diff --git a/app/views/activities/_update_actor.html.erb b/app/views/activities/_update_actor.html.erb
index a53ddae77..dc7438ad2 100644
--- a/app/views/activities/_update_actor.html.erb
+++ b/app/views/activities/_update_actor.html.erb
@@ -1,7 +1,7 @@
<%- subject = activity&.actor %>
<%- object = activity&.entity %>
<%- thing = object&.entity %>
-<% if thing && !thing.is_a?(User) %>
+<% if thing && !thing.is_a?(User) && (thing.grants_permission_to?(["view", "edit", "own"], current_user) || thing.grants_permission_to?(["view", "edit", "own"], current_user&.roles)) %>
diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb
index 0b0129f33..d897afc36 100644
--- a/app/views/application/_navbar.html.erb
+++ b/app/views/application/_navbar.html.erb
@@ -55,7 +55,7 @@
<% end %>
<%- if current_user %>
- <% if policy(Problem).index? && Problem.visible(current_user.problem_settings).count > 0 %>
+ <% if policy(Problem).index? && Problem.visible(problem_settings).count > 0 %>
<% severity = max_problem_severity %>
<%= nav_link problem_icon(severity),
diff --git a/app/views/application/_object_preview.html.erb b/app/views/application/_object_preview.html.erb
index 593a75c3b..ef7e18b82 100644
--- a/app/views/application/_object_preview.html.erb
+++ b/app/views/application/_object_preview.html.erb
@@ -5,14 +5,14 @@
data-worker-url="<%= javascript_path "offscreen_renderer.js" %>"
data-format="<%= file.extension %>"
data-y-up="<%= file.y_up %>"
- data-grid-size-x="<%= current_user.renderer_settings["grid_width"] %>"
- data-grid-size-z="<%= current_user.renderer_settings["grid_depth"] %>"
- data-show-grid="<%= current_user.renderer_settings["show_grid"] %>"
- data-enable-pan-zoom="<%= current_user.renderer_settings["enable_pan_zoom"] %>"
- data-background-colour="<%= current_user.renderer_settings["background_colour"] %>"
- data-object-colour="<%= current_user.renderer_settings["object_colour"] %>"
- data-render-style="<%= current_user.renderer_settings["render_style"] %>"
- data-auto-load="<%= ((file.size || 9_999_999.megabytes) < ((current_user.renderer_settings["auto_load_max_size"] || 9_999_999).megabytes)) ? "true" : "false" %>">
+ data-grid-size-x="<%= renderer_settings["grid_width"] %>"
+ data-grid-size-z="<%= renderer_settings["grid_depth"] %>"
+ data-show-grid="<%= renderer_settings["show_grid"] %>"
+ data-enable-pan-zoom="<%= renderer_settings["enable_pan_zoom"] %>"
+ data-background-colour="<%= renderer_settings["background_colour"] %>"
+ data-object-colour="<%= renderer_settings["object_colour"] %>"
+ data-render-style="<%= renderer_settings["render_style"] %>"
+ data-auto-load="<%= ((file.size || 9_999_999.megabytes) < ((renderer_settings["auto_load_max_size"] || 9_999_999).megabytes)) ? "true" : "false" %>">
diff --git a/app/views/application/_tag_list.html.erb b/app/views/application/_tag_list.html.erb
index 6788c5a03..b4f0e27dc 100644
--- a/app/views/application/_tag_list.html.erb
+++ b/app/views/application/_tag_list.html.erb
@@ -9,7 +9,7 @@
end %>
<% end %>
<%- tag_html_opts = {data: {bulk_item_tags: defined?(model_id) ? model_id&.to_s : nil}} %>
-<%- heatmap = defined?(show_count) ? heatmap : current_user.tag_cloud_settings["heatmap"] %>
+<%- heatmap = defined?(show_count) ? heatmap : tag_cloud_settings["heatmap"] %>
<%= safe_join(tags.map { |tag| render TagComponent.new(tag: tag, filters: @filters, html_options: tag_html_opts, show_count: heatmap) }, " ") if tags %>
<% if defined?(kv_tags) && kv_tags %>
diff --git a/app/views/collections/_collection.html.erb b/app/views/collections/_collection.html.erb
index ae8605cf5..d67b55890 100644
--- a/app/views/collections/_collection.html.erb
+++ b/app/views/collections/_collection.html.erb
@@ -1,4 +1,4 @@
-<% model = collection.models.first %>
+<% model = policy_scope(Model).where(collection: collection).first %>
@@ -34,7 +34,7 @@
- <%= link_to "#{collection.models.count} #{Model.model_name.human count: collection.models.count}", {controller: "models", collection: collection.id}, class: "btn btn-primary", "aria-label": translate(".models_button.label", name: collection.name) if policy(collection).show? %>
+ <%= link_to "#{policy_scope(Model).where(collection: collection).count} #{Model.model_name.human count: policy_scope(Model).where(collection: collection).count}", {controller: "models", collection: collection.id}, class: "btn btn-primary", "aria-label": translate(".models_button.label", name: collection.name) if policy(collection).show? %>
<%= link_to "#{collection.collections.count} #{Collection.model_name.human count: collection.collections.count}", (@filters || {}).merge(controller: "collections", collection: collection.id), class: "btn btn-primary", "aria-label": translate(".collections_button.label", name: collection.name) if collection.collections.count > 0 && policy(collection).show? %>
<%= link_to icon("pencil-fill", t(".edit_button.text")), edit_collection_path(collection), {class: "btn btn-outline-secondary", "aria-label": translate(".edit_button.label", name: collection.name)} if policy(collection).edit? %>
diff --git a/app/views/collections/_unassigned.html.erb b/app/views/collections/_unassigned.html.erb
index d6c08ffb7..813b1ac0f 100644
--- a/app/views/collections/_unassigned.html.erb
+++ b/app/views/collections/_unassigned.html.erb
@@ -4,7 +4,7 @@
<%= t(".name") %>
<%= t(".caption") %>
- <%= link_to "#{Model.where(collection: nil).count} #{Model.model_name.human count: Model.where(collection: nil).count}", models_path(collection: ""), {class: "btn btn-primary"} %>
+ <%= link_to "#{policy_scope(Model).where(collection: nil).count} #{Model.model_name.human count: policy_scope(Model).where(collection: nil).count}", models_path(collection: ""), {class: "btn btn-primary"} %>
diff --git a/app/views/collections/index.html.erb b/app/views/collections/index.html.erb
index 769918049..ca4d5d161 100644
--- a/app/views/collections/index.html.erb
+++ b/app/views/collections/index.html.erb
@@ -5,17 +5,17 @@
<% content_for :items do %>
<%= skip_link "sidebar", t(".skip_collections") %>
- <% if current_user.pagination_settings["collections"] %>
+ <% if pagination_settings["collections"] %>
<%= paginate @collections %>
<% end %>
- <%= render "unassigned" if (!current_user.pagination_settings["collections"] || @collections.first_page?) && !@filters[:collection] %>
+ <%= render "unassigned" if (!pagination_settings["collections"] || @collections.first_page?) && !@filters[:collection] %>
<% if @filters[:collection] && @collection %>
<%= render @collection %>
<% end %>
<%= render @collections %>
- <% if current_user.pagination_settings["collections"] %>
+ <% if pagination_settings["collections"] %>
<%= paginate @collections %>
<% end %>
diff --git a/app/views/collections/show.html.erb b/app/views/collections/show.html.erb
index 601c7d7e6..5d19056ae 100644
--- a/app/views/collections/show.html.erb
+++ b/app/views/collections/show.html.erb
@@ -13,13 +13,13 @@
- <% if current_user.pagination_settings["models"] %>
+ <% if pagination_settings["models"] %>
<%= paginate @models %>
<% end %>
<%= render partial: "model", collection: @models %>
- <% if current_user.pagination_settings["models"] %>
+ <% if pagination_settings["models"] %>
<%= paginate @models %>
<% end %>
diff --git a/app/views/creators/_creator.html.erb b/app/views/creators/_creator.html.erb
index ec0d87ff7..38c94964c 100644
--- a/app/views/creators/_creator.html.erb
+++ b/app/views/creators/_creator.html.erb
@@ -13,7 +13,7 @@
<%= link_to t("sites.%{site}" % {site: link.site}), link.url %>
<% end %>
- <%= link_to "#{creator.models.count} #{Model.model_name.human count: creator.models.count}", models_path(creator: creator.id), {class: "btn btn-primary", "aria-label": translate(".models_button.label", name: creator.name)} if policy(creator).show? %>
+ <%= link_to "#{policy_scope(Model).where(creator: creator).count} #{Model.model_name.human count: policy_scope(Model).where(creator: creator).count}", models_path(creator: creator.id), {class: "btn btn-primary", "aria-label": translate(".models_button.label", name: creator.name)} if policy(creator).show? %>
<%= link_to icon("pencil-fill", t(".edit_button.text")), edit_creator_path(creator), {class: "btn btn-outline-secondary", "aria-label": translate(".edit_button.label", name: creator.name)} if policy(creator).edit? %>
diff --git a/app/views/creators/_unassigned.html.erb b/app/views/creators/_unassigned.html.erb
index 7faebb138..b38516078 100644
--- a/app/views/creators/_unassigned.html.erb
+++ b/app/views/creators/_unassigned.html.erb
@@ -3,7 +3,7 @@
<%= t(".name") %>
<%= t(".caption") %>
- <%= link_to "#{Model.where(creator: nil).count} #{Model.model_name.human count: Model.where(creator: nil).count}", models_path(creator: ""), {class: "btn btn-primary"} %>
+ <%= link_to "#{policy_scope(Model).where(creator: nil).count} #{Model.model_name.human count: policy_scope(Model).where(creator: nil).count}", models_path(creator: ""), {class: "btn btn-primary"} %>
diff --git a/app/views/creators/index.html.erb b/app/views/creators/index.html.erb
index 15eaaf296..cc802edd5 100644
--- a/app/views/creators/index.html.erb
+++ b/app/views/creators/index.html.erb
@@ -5,14 +5,14 @@
<% content_for :items do %>
<%= skip_link "sidebar", t(".skip_creators") %>
- <% if current_user.pagination_settings["creators"] %>
+ <% if pagination_settings["creators"] %>
<%= paginate @creators %>
<% end %>
- <%= render "unassigned" if !current_user.pagination_settings["creators"] || @creators.first_page? %>
+ <%= render "unassigned" if !pagination_settings["creators"] || @creators.first_page? %>
<%= render @creators %>
- <% if current_user.pagination_settings["creators"] %>
+ <% if pagination_settings["creators"] %>
<%= paginate @creators %>
<% end %>
diff --git a/app/views/model_files/show.html.erb b/app/views/model_files/show.html.erb
index d62d78347..d5fc92960 100644
--- a/app/views/model_files/show.html.erb
+++ b/app/views/model_files/show.html.erb
@@ -59,11 +59,11 @@
<%= link_to safe_join([icon("trash", t("general.delete")), t("general.delete")], " "), model_model_file_path(@model, @file), {method: "delete", data: {confirm: translate("model_files.destroy.confirm")}, class: "btn btn-outline-danger"} if policy(@file).destroy? %>
<% end %>
- <%= render partial: "problem", collection: @file.problems.visible(current_user.problem_settings) %>
+ <%= render partial: "problem", collection: @file.problems.visible(problem_settings) %>
<%= card :secondary, t(".actions_heading") do %>
<%= link_to safe_join([icon("cloud-download", t("general.download")), t("general.download")], " "), model_model_file_path(@model, @file, @file.extension.to_sym), {class: "btn btn-secondary"} %>
- <% if policy(:model_file).create? && ["stl", "obj"].include?(@file.extension) %>
+ <% if policy(@file).edit? && ["stl", "obj"].include?(@file.extension) %>
<%= link_to safe_join([icon("arrow-left-right", t(".convert")), t(".convert")], " "), model_model_files_path(@model, convert: {id: @file.id, to: "threemf"}), method: :post, class: "btn btn-warning" %>
<% end %>
<% end %>
diff --git a/app/views/models/index.html.erb b/app/views/models/index.html.erb
index badff2bdc..e0a162d96 100644
--- a/app/views/models/index.html.erb
+++ b/app/views/models/index.html.erb
@@ -3,28 +3,37 @@
<% end %>
<% content_for :items do %>
-
- <%= skip_link "sidebar", t(".skip_models") %>
- <% if current_user.pagination_settings["models"] %>
- <%= paginate @models %>
- <% end %>
-
- <%= render ModelComponent.with_collection(@models, can_show: @can_show, can_edit: @can_edit, can_destroy: @can_destroy) %>
+ <% if @models.empty? %>
+
+ <%= icon "person-arms-up", "" %>
+ <%= t(".no_results_html") %>
- <% if current_user.pagination_settings["models"] %>
- <%= paginate @models %>
- <% end %>
-
+ <% else %>
+
+ <%= skip_link "sidebar", t(".skip_models") %>
+ <% if pagination_settings["models"] %>
+ <%= paginate @models %>
+ <% end %>
+
+ <%= render ModelComponent.with_collection(@models, can_edit: @can_edit, can_destroy: @can_destroy) %>
+
+ <% if pagination_settings["models"] %>
+ <%= paginate @models %>
+ <% end %>
+
+ <% end %>
<% end %>
<% content_for :sidebar do %>
<%= card :secondary, t(".actions_heading") do %>
<%= link_to t(".bulk_edit"), edit_models_path(@filters), class: "btn btn-secondary mb-3 me-3" if policy(:model).edit? %>
- <% if current_user.tag_cloud_settings["heatmap"] && Model.where("(select count(*) from taggings where taggings.taggable_id=models.id and taggings.context='tags')<1").count > 0 %>
- <%= link_to t(".untagged"), models_path(tag: [""]), class: "btn btn-secondary mb-3 me-3" %>
- <% end %>
- <% if Model.where("(select count(*) from links where linkable_id=models.id and linkable_type='Model')<1").count > 0 %>
- <%= link_to t(".missing_url"), models_path(link: ""), class: "btn btn-secondary mb-3 me-3" %>
+ <% if current_user %>
+ <% if tag_cloud_settings["heatmap"] && policy_scope(Model).where("(select count(*) from taggings where taggings.taggable_id=models.id and taggings.context='tags')<1").count > 0 %>
+ <%= link_to t(".untagged"), models_path(tag: [""]), class: "btn btn-secondary mb-3 me-3" %>
+ <% end %>
+ <% if policy_scope(Model).where("(select count(*) from links where linkable_id=models.id and linkable_type='Model')<1").count > 0 %>
+ <%= link_to t(".missing_url"), models_path(link: ""), class: "btn btn-secondary mb-3 me-3" %>
+ <% end %>
<% end %>
<% if @creator %>
<%= render FollowButtonComponent.new(follower: current_user, target: @creator, name: @creator.name) %>
diff --git a/app/views/models/show.html.erb b/app/views/models/show.html.erb
index 7d67379ea..a92fa37b9 100644
--- a/app/views/models/show.html.erb
+++ b/app/views/models/show.html.erb
@@ -60,7 +60,7 @@
<%= @model.path %>
<% unless @model.contains_other_models? %>
- <%= button_tag(t(".organize.button_text"), class: "btn btn-warning btn-sm float-end", "data-bs-toggle": "modal", "data-bs-target": "#confirm-move") if @model.needs_organizing? %>
+ <%= button_tag(t(".organize.button_text"), class: "btn btn-warning btn-sm float-end", "data-bs-toggle": "modal", "data-bs-target": "#confirm-move") if @model.needs_organizing? && policy(@model).edit? %>
<% end %>
|
@@ -86,7 +86,7 @@
<% end %>
<% end %>
- <%= render partial: "problem", collection: @model.problems.visible(current_user.problem_settings) %>
+ <%= render partial: "problem", collection: @model.problems.visible(problem_settings) %>
<%= card(:secondary, t(".notes_heading")) do %>
<%= sanitize @model.notes %>
diff --git a/app/views/problems/model_file/_inefficient.html.erb b/app/views/problems/model_file/_inefficient.html.erb
index a4ccae1ca..07b4595b4 100644
--- a/app/views/problems/model_file/_inefficient.html.erb
+++ b/app/views/problems/model_file/_inefficient.html.erb
@@ -2,7 +2,7 @@
<%= link_to problem.problematic.name, [problem.problematic.model, problem.problematic], class: "link-body-emphasis" %> |
<%= t ".title" %>: <%= problem.note %> |
- <% if policy(problem.problematic).show? && policy(:model_file).create? && ["stl", "obj"].include?(problem.problematic.extension) %>
+ <% if policy(problem.problematic).show? && policy(problem.problematic).create? && ["stl", "obj"].include?(problem.problematic.extension) %>
<%= link_to t("model_files.show.convert"), model_model_files_path(problem.problematic.model, convert: {id: problem.problematic.id, to: "threemf"}), method: :post, class: "btn btn-warning" %>
<% end %>
|
diff --git a/config/locales/models/en.yml b/config/locales/models/en.yml
index 8dc2e8755..c66c89ca3 100644
--- a/config/locales/models/en.yml
+++ b/config/locales/models/en.yml
@@ -40,6 +40,7 @@ en:
actions_heading: Actions
bulk_edit: Bulk Edit
missing_url: Missing URL
+ no_results_html: Sorry, we couldn't find anything to show you! Try changing your filters or search terms, or uploading some models.
skip_models: Skip model list
untagged: Untagged
merge:
diff --git a/spec/components/follow_button_component_spec.rb b/spec/components/follow_button_component_spec.rb
index 39dbe3c9b..bb8fb632c 100644
--- a/spec/components/follow_button_component_spec.rb
+++ b/spec/components/follow_button_component_spec.rb
@@ -3,13 +3,14 @@
require "rails_helper"
RSpec.describe FollowButtonComponent, type: :component do
+ let(:follower) { create(:user) }
+ let(:target) { create(:creator) }
+
before do
+ sign_in(follower)
allow(SiteSettings).to receive(:multiuser_enabled?).and_return(true)
end
- let(:follower) { create(:user) }
- let(:target) { create(:creator) }
-
context "when the follower is not following the target" do
let(:button) {
allow(follower).to receive(:following?).with(target).and_return false
diff --git a/spec/support/view_components.rb b/spec/support/view_components.rb
index c8b8b93f5..f38f20432 100644
--- a/spec/support/view_components.rb
+++ b/spec/support/view_components.rb
@@ -1,7 +1,15 @@
require "view_component/test_helpers"
require "view_component/system_test_helpers"
+# For devise in viewcomponents: https://github.com/ViewComponent/view_component/discussions/371
+module ManyfoldViewComponentTestHelpers
+ include ViewComponent::TestHelpers
+ def sign_in(user)
+ allow(vc_test_controller).to receive(:current_user).and_return(user)
+ end
+end
+
RSpec.configure do |config|
- config.include ViewComponent::TestHelpers, type: :component
+ config.include ManyfoldViewComponentTestHelpers, type: :component
config.include ViewComponent::SystemTestHelpers, type: :component
end