Skip to content

Commit

Permalink
Added support to disable the project size feature
Browse files Browse the repository at this point in the history
  • Loading branch information
abujeda committed Apr 26, 2024
1 parent 1a35d7e commit 4f61056
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
5 changes: 4 additions & 1 deletion apps/dashboard/app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
<div class="row my-2">
<a id="new-dir-btn" class="btn btn-outline-dark" href="<%= files_path(fs: 'fs', filepath: @project.directory ) %>">
<i class="fas fa-folder-open" aria-hidden="true"></i>
<%= t('dashboard.project') %> <%= t('dashboard.directory') %> <span data-toggle="project" data-url="<%= project_path(@project.id) %>"></span>
<%= t('dashboard.project') %> <%= t('dashboard.directory') %>
<%- if Configuration.project_size_enabled -%>
<span data-toggle="project" data-url="<%= project_path(@project.id) %>"></span>
<%- end -%>
</a>
</div>

Expand Down
8 changes: 5 additions & 3 deletions apps/dashboard/app/views/projects/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ json.name @project.name
json.description @project.description
json.icon @project.icon
json.directory @project.directory
project_size = @project.size
json.size project_size
json.human_size number_to_human_size(project_size)
if Configuration.project_size_enabled
project_size = @project.size
json.size project_size
json.human_size number_to_human_size(project_size)
end
1 change: 1 addition & 0 deletions apps/dashboard/config/configuration_singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def boolean_configs
:motd_render_html => false,
:upload_enabled => true,
:download_enabled => true,
:project_size_enabled => true,
}.freeze
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ cancel_session_enabled: true
bc_clean_old_dirs: true
hide_app_version: true
motd_render_html: true
project_size_enabled: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
id: json_response
name: JsonResponseName
description: JsonResponseDescription
icon: fas://user
39 changes: 38 additions & 1 deletion apps/dashboard/test/integration/projects_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def setup
Rails.application.reload_routes!
end

test "should get index" do
test "should get index" do
get projects_path
assert_response :success
end
Expand Down Expand Up @@ -50,4 +50,41 @@ def setup
assert Dir.exist?("#{dir}/projects")
end
end

test "gets JSON reponse" do
project_dir = Rails.root.join('test/fixtures/projects/json_response')
OodAppkit.stubs(:dataroot).returns(project_dir)
Project.stubs(:lookup_table).returns({ 'json_response' => project_dir.to_s })
Project.any_instance.expects(:size).once.returns(2097152)

get project_path('json_response', format: :json)
assert_response :success
json = JSON.parse(@response.body)
assert_equal 'json_response', json['id']
assert_equal 'JsonResponseName', json['name']
assert_equal 'JsonResponseDescription', json['description']
assert_equal project_dir.to_s, json['directory']
assert_equal 'fas://user', json['icon']
assert_equal 2097152, json['size']
assert_equal '2 MB', json['human_size']
end

test "project size is not added to JSON reponse when Configuration.project_size_enabled is false" do
project_dir = Rails.root.join('test/fixtures/projects/json_response')
OodAppkit.stubs(:dataroot).returns(project_dir)
Configuration.stubs(:project_size_enabled).returns(false)
Project.stubs(:lookup_table).returns({ 'json_response' => project_dir.to_s })
Project.any_instance.expects(:size).never

get project_path('json_response', format: :json)
assert_response :success
json = JSON.parse(@response.body)
assert_equal 'json_response', json['id']
assert_equal 'JsonResponseName', json['name']
assert_equal 'JsonResponseDescription', json['description']
assert_equal project_dir.to_s, json['directory']
assert_equal 'fas://user', json['icon']
assert_equal false, json.has_key?('size')
assert_equal false, json.has_key?('human_size')
end
end

0 comments on commit 4f61056

Please sign in to comment.