Skip to content

Commit

Permalink
Only show the user the project directory levels that are visible to t…
Browse files Browse the repository at this point in the history
…hem (#952)

* Move access to project metadata to the project presenter instead of diging deep in the views

Moves all access to the metadata_model instead of some through the model and some through the hash

* Only showing the user the project directory visible to them
fixes #941
  • Loading branch information
carolyncole authored Sep 25, 2024
1 parent 4a1fe82 commit 4010954
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 16 deletions.
8 changes: 8 additions & 0 deletions app/models/mediaflux/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,13 @@ def self.root_namespace
Rails.configuration.mediaflux["api_root_ns"]
end
end

def self.hidden_root
if Flipflop.alternate_mediaflux?
Rails.configuration.mediaflux["api_alternate_hidden_root"]
else
Rails.configuration.mediaflux["api_hidden_root"]
end
end
end
end
11 changes: 9 additions & 2 deletions app/presenters/project_show_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# frozen_string_literal: true
class ProjectShowPresenter
delegate "id", "in_mediaflux?", "mediaflux_id", "metadata", "metadata_model", "pending?", "project_directory", "status", "title", to: :project
delegate "id", "in_mediaflux?", "mediaflux_id", "pending?", "status", "title", to: :project
delegate "description", "project_id", "storage_capacity", "storage_performance_expectations", "project_purpose", to: :project_metadata

attr_reader :project
attr_reader :project, :project_metadata

def initialize(project)
@project = project
@project_metadata = @project.metadata_model
end

# used to hide the project root that is not visible to the end user
def project_directory
project.project_directory.gsub(Mediaflux::Connection.hidden_root, "")
end
end
8 changes: 4 additions & 4 deletions app/views/projects/_pending_details.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h2>Automatic Settings </h2>
<dl>
<dt>Project ID</dt> <dd id="project_id"><%= @project.metadata[:project_id] %></dd>
<dt>Storage Capacity (Requested)</dt> <dd><%= "#{@project.metadata_model.storage_capacity[:size][:requested]} #{@project.metadata_model.storage_capacity[:unit][:requested]}" %></dd>
<dt>Storage Performance Expectations (Requested)</dt> <dd><%= @project.metadata_model.storage_performance_expectations[:requested] %></dd>
<dt>Project Purpose</dt> <dd><%= @project.metadata_model.project_purpose %></dd>
<dt>Project ID</dt> <dd id="project_id"><%= @project.project_id %></dd>
<dt>Storage Capacity (Requested)</dt> <dd><%= "#{@project.storage_capacity[:size][:requested]} #{@project.storage_capacity[:unit][:requested]}" %></dd>
<dt>Storage Performance Expectations (Requested)</dt> <dd><%= @project.storage_performance_expectations[:requested] %></dd>
<dt>Project Purpose</dt> <dd><%= @project.project_purpose %></dd>
</dl>
<% if @project.in_mediaflux? && (current_user.superuser? || current_user.eligible_sysadmin?) %>
<dl>
Expand Down
4 changes: 2 additions & 2 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ Project Details:
<dt>Project Directory</dt>
<dd><%= @project.project_directory %></dd>
<dt>Title</dt>
<dd><%= @project.metadata[:title] %></dd>
<dt>Description:<dt/> <dd><%= @project.metadata[:description] %></dd>
<dd><%= @project.title %></dd>
<dt>Description:<dt/> <dd><%= @project.description %></dd>
</dl>
</div>

Expand Down
10 changes: 10 additions & 0 deletions config/mediaflux.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
production:
api_hidden_root: <%= ENV["MEDIAFLUX_HIDDEN_ROOT"] || '/princeton' %>
api_root_ns: <%= ENV["MEDIAFLUX_ROOT_NS"] || '/princeton/tigerdataNS' %>
api_root_collection: <%= ENV["MEDIAFLUX_ROOT_COLLECTION"] || 'path=/princeton/tigerdata' %>
api_root_collection_name: <%= ENV["MEDIAFLUX_ROOT_COLLECTION"] || 'tigerdata' %>
Expand All @@ -9,6 +10,7 @@ production:
api_port: <%= ENV["MEDIAFLUX_PORT"] || 443 %>

# Alternate to production is real production
api_alternate_hidden_root: <%= ENV["MEDIAFLUX_ALTERNATE_HIDDEN_ROOT"] || '/td-prod-001' %>
api_alternate_root_ns: <%= ENV["MEDIAFLUX_ALTERNATE_ROOT_NS"] || '/td-prod-001/tigerdataNS' %>
api_alternate_root_collection: <%= ENV["MEDIAFLUX_ALTERNATE_ROOT_COLLECTION"] || 'path=/td-prod-001/tigerdata' %>
api_alternate_root_collection_name: <%= ENV["MEDIAFLUX_ALTERNATE_ROOT_COLLECTION"] || 'tigerdata' %>
Expand All @@ -22,6 +24,7 @@ production:
api_password: <%= ENV["MEDIAFLUX_PASSWORD"] %>
shared_files_location: <%= ENV["SHARED_FILES_MOUNT"] || '/mnt/nfs/tigerdata' %>
qa:
api_hidden_root: '/td-qa-001'
api_root_to_clean: '/td-qa-001/qa'
api_root_ns: <%= ENV["MEDIAFLUX_ROOT_NS"] || '/td-qa-001/qa/tigerdataNS' %>
api_root_collection_name: 'tigerdata'
Expand All @@ -32,6 +35,7 @@ qa:
api_port: <%= ENV["MEDIAFLUX_PORT"] || 443 %>

# Alternate to qa is staging
api_alternate_hidden_root: '/td-staging-001'
api_alternate_root_ns: '/td-staging-001/tigerdataNS'
api_alternate_root_collection: 'path=/td-staging-001/tigerdata'
api_alternate_root_collection_name: 'tigerdata'
Expand All @@ -45,6 +49,7 @@ qa:
api_password: <%= ENV["MEDIAFLUX_PASSWORD"] %>
shared_files_location: <%= ENV["SHARED_FILES_MOUNT"] || '/mnt/nfs/tigerdata' %>
staging:
api_hidden_root: '/td-staging-001'
api_root_ns: <%= ENV["MEDIAFLUX_ROOT_NS"] || '/td-staging-001/tigerdataNS' %>
api_root_to_clean: '/td-staging-001/'
api_root_collection_name: 'tigerdata'
Expand All @@ -55,6 +60,7 @@ staging:
api_port: <%= ENV["MEDIAFLUX_PORT"] || 443 %>

# Alternate to staging is qa
api_alternate_hidden_root: '/td-qa-001'
api_alternate_root_ns: '/td-qa-001/tigerdataNS'
api_alternate_root_collection: 'path=/td-qa-001/tigerdata'
api_alternate_root_collection_name: 'tigerdata'
Expand All @@ -68,6 +74,7 @@ staging:
api_password: <%= ENV["MEDIAFLUX_PASSWORD"] %>
shared_files_location: <%= ENV["SHARED_FILES_MOUNT"] || '/mnt/nfs/tigerdata' %>
development:
api_hidden_root: '/td-demo-001'
api_root_to_clean: '/td-demo-001/dev/'
api_root_ns: <%= ENV["MEDIAFLUX_ROOT_NS"] || '/td-demo-001/dev/tigerdataNS' %>
api_root_collection_name: 'tigerdata'
Expand All @@ -78,6 +85,7 @@ development:
api_port: <%= ENV["MEDIAFLUX_PORT"] || '8888' %>

# Alternate to development is an alternate location in docker
api_alternate_hidden_root: '/td-alternate-001'
api_alternate_root_ns: '/td-alternate-001/tigerdataNS'
api_alternate_root_collection: 'path=/td-alternate-001/tigerdata'
api_alternate_root_collection_name: 'tigerdata-alternate'
Expand All @@ -92,6 +100,7 @@ development:
api_password: <%= ENV["MEDIAFLUX_PASSWORD"] || 'change_me' %>
shared_files_location: <%= ENV["SHARED_FILES_MOUNT"] || './public/' %>
test:
api_hidden_root: '/td-test-001'
api_root_to_clean: '/td-test-001/test/'
api_root_ns: '/td-test-001/test/tigerdataNS'
api_root_collection_name: 'tigerdata'
Expand All @@ -102,6 +111,7 @@ test:
api_port: "<%= ENV['MFLUX_CI'] ? '80' : '8888' %>"

# Alternate to test is still a test location
api_alternate_hidden_root: '/td-test-002'
api_alternate_root_ns: '/td-test-002/tigerdataNS'
api_alternate_root_collection: 'path=/td-test-002/tigerdata-alt'
api_alternate_root_collection_name: 'tigerdata-alt'
Expand Down
40 changes: 32 additions & 8 deletions spec/models/project_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
let(:project) { FactoryBot.create :project }
subject(:presenter) { ProjectShowPresenter.new(project) }

describe "#description" do
it "delegates to project metdata_model" do
expect(presenter.description).to eq(project.metadata_model.description)
end
end

describe "#id" do
it "delegates to project" do
expect(presenter.id).to eq(project.id)
Expand All @@ -23,21 +29,27 @@
end
end

describe "#metadata" do
it "delegates to project" do
expect(presenter.metadata).to eq(project.metadata)
end
end

describe "#pending?" do
it "delegates to project" do
expect(presenter.pending?).to eq(project.pending?)
end
end

describe "#project_directory" do
it "delegates to project" do
expect(presenter.project_directory).to eq(project.project_directory)
it "hides the root project" do
expect(presenter.project_directory).to eq("/test/tigerdataNS/big-data")
end
end

describe "#project_id" do
it "delegates to project metdata_model" do
expect(presenter.project_id).to eq(project.metadata_model.project_id)
end
end

describe "#project_purpose" do
it "delegates to project metdata_model" do
expect(presenter.project_purpose).to eq(project.metadata_model.project_purpose)
end
end

Expand All @@ -47,6 +59,18 @@
end
end

describe "#storage_capacity" do
it "delegates to project metadata_model" do
expect(presenter.storage_capacity).to eq(project.metadata_model.storage_capacity)
end
end

describe "#storage_performance_expectations" do
it "delegates to project metadata_model" do
expect(presenter.storage_performance_expectations).to eq(project.metadata_model.storage_performance_expectations)
end
end

describe "#title" do
it "delegates to project" do
expect(presenter.title).to eq(project.title)
Expand Down
10 changes: 10 additions & 0 deletions spec/system/project_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
visit "/projects/#{project_in_mediaflux.id}"

expect(page).to have_content(project_in_mediaflux.title)

# shows the project directory without the hidden root
expect(page).to have_content(project_in_mediaflux.project_directory.gsub("/td-test-001", ""))
expect(page).not_to have_content(project_in_mediaflux.project_directory)

expect(page).not_to have_content(pending_text)
expect(page).to have_css ".alert-success"
expect(page).to have_selector(:link_or_button, "Edit") # button next to role and description heading
Expand Down Expand Up @@ -210,6 +215,11 @@
it "shows the sysadmin buttons for an approved project" do
sign_in sysadmin_user
visit "/projects/#{project_in_mediaflux.id}"

# shows the project directory without the hidden root
expect(page).to have_content(project_in_mediaflux.project_directory.gsub("/td-test-001", ""))
expect(page).not_to have_content(project_in_mediaflux.project_directory)

expect(page).to have_content "project 123"
expect(page).to have_content "1234"
expect(page).not_to have_content "This project has not been saved to Mediaflux"
Expand Down

0 comments on commit 4010954

Please sign in to comment.