-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3944 - add file browser to project show page.
- Loading branch information
1 parent
4f7a643
commit 4b67711
Showing
11 changed files
with
196 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Pathable | ||
extend ActiveSupport::Concern | ||
|
||
def normalized_path(path) | ||
Pathname.new("/#{path.to_s.chomp('/').delete_prefix('/')}") | ||
end | ||
|
||
def parse_path(path = nil, filesystem = nil) | ||
normal_path = normalized_path(path || resolved_path) | ||
filesystem ||= resolved_fs | ||
if filesystem == 'fs' | ||
@path = PosixFile.new(normal_path) | ||
@filesystem = 'fs' | ||
elsif ::Configuration.remote_files_enabled? && filesystem != 'fs' | ||
@path = RemoteFile.new(normal_path, filesystem) | ||
@filesystem = filesystem | ||
else | ||
@path = PosixFile.new(normal_path) | ||
@filesystem = filesystem | ||
raise StandardError, I18n.t('dashboard.files_remote_disabled') | ||
end | ||
end | ||
|
||
def validate_path! | ||
if posix_file? | ||
AllowlistPolicy.default.validate!(@path) | ||
elsif @path.remote_type.nil? | ||
raise StandardError, "Remote #{@path.remote} does not exist" | ||
elsif ::Configuration.allowlist_paths.present? && (@path.remote_type == 'local' || @path.remote_type == 'alias') | ||
# local and alias remotes would allow bypassing the AllowListPolicy | ||
# TODO: Attempt to evaluate the path of them and validate? | ||
raise StandardError, "Remotes of type #{@path.remote_type} are not allowed due to ALLOWLIST_PATH" | ||
end | ||
end | ||
|
||
def posix_file? | ||
@path.is_a?(PosixFile) | ||
end | ||
|
||
def resolved_path | ||
raise NoMethodError, "Must implement resolved_path in #{self.class.to_s} to use Pathable concern" | ||
end | ||
|
||
def resolved_fs | ||
raise NoMethodError, "Must implement resolved_fs in #{self.class.to_s} to use Pathable concern" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<%= turbo_frame_tag "project_files" do %> | ||
<table class="table table-striped table-condensed w-100"> | ||
<thead> | ||
<tr> | ||
<th> | ||
<input type="checkbox" id="select_all" title="Select All"></input> | ||
</th> | ||
<th>Type<span aria-hidden="true"></span></th> | ||
<th>Name<span aria-hidden="true"></span></th> | ||
<th><span class="sr-only">Actions</span></th> | ||
<th>Size<span aria-hidden="true"></span></th> | ||
<th>Modified at<span aria-hidden="true"></span></th> | ||
<th>Owner<span aria-hidden="true"></span></th> | ||
<th>Mode<span aria-hidden="true"></span></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= render partial: "files", locals: { project_id: project.id, path: path, files: files } %> | ||
</tbody> | ||
</table> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<tr> | ||
<td> | ||
<input type="checkbox" class="file-checkbox disabled" title="Select"></input> | ||
</td> | ||
<td> | ||
</td> | ||
<td> | ||
<%= link_to("..", project_files_path(project_id: project_id, filepath: sanitize("#{path}/..")), data: { turbo_frame: "project_files" }) %> | ||
</td> | ||
<td></td> | ||
<td></td> | ||
<td></td> | ||
<td></td> | ||
<td></td> | ||
</tr> | ||
<% files.each do |file| %> | ||
<tr> | ||
<td> | ||
<input type="checkbox" class="file-checkbox" data-file-id="<%= file[:id] %>" title="Select"></input> | ||
</td> | ||
<td> | ||
<%= file[:type] %> | ||
</td> | ||
<td> | ||
<%= link_to(file[:name], project_files_path(project_id: project_id, filepath: sanitize("#{path}/#{file[:name]}")), data: { turbo_frame: "project_files" }) %> | ||
</td> | ||
<td> | ||
<span class="sr-only">Actions</span> | ||
<div class="btn-group"> | ||
<button type="button" class="btn btn-outline-dark btn-sm" title="View file" data-file-id="<%= file[:id] %>"> | ||
<i class="fa fa-eye" aria-hidden="true"></i> | ||
</button> | ||
<button type="button" class="btn btn-outline-dark btn-sm" title="Download file" data-file-id="<%= file[:id] %>"> | ||
<i class="fa fa-download" aria-hidden="true"></i> | ||
</button> | ||
<button type="button" class="btn btn-outline-dark btn-sm" title="Delete file" data-file-id="<%= file[:id] %>"> | ||
<i class="fa fa-trash" aria-hidden="true"></i> | ||
</button> | ||
</div> | ||
</td> | ||
<td> | ||
<%= file[:size] %> | ||
</td> | ||
<td> | ||
<%= file[:modified_at] %> | ||
</td> | ||
<td> | ||
<%= file[:owner] %> | ||
</td> | ||
<td> | ||
<%= file[:mode] %> | ||
</td> | ||
</tr> | ||
<%- end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters