This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**New Features**: - Project file management **Fixes**: - Form elements with inherited styling will correctly show up as invalid if an error occurs on the input element's attribute
- Loading branch information
Showing
47 changed files
with
2,356 additions
and
156 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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// CSS styles meant to apply to specific controllers | ||
|
||
@import 'errors'; | ||
@import 'files'; | ||
@import 'profiles'; | ||
@import 'static'; |
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,8 @@ | ||
// Styling for FilesController | ||
|
||
// Add spacing around each file entry on index page | ||
.file-wrapper { | ||
padding: 8px 0; | ||
h5 { margin: 4px 0; } | ||
p { margin: 4px 0; } | ||
} |
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,96 @@ | ||
# frozen_string_literal: true | ||
|
||
# Controller for project files | ||
class FilesController < ApplicationController | ||
before_action :authenticate_account!, except: %i[index show] | ||
before_action :set_project | ||
before_action :build_file, only: %i[new create] | ||
before_action :set_file, except: %i[index new create] | ||
before_action :authorize_action, except: %i[index show] | ||
|
||
def index | ||
# sort files in alphabetical order (case insensitive) but always put | ||
# Overview file first | ||
@files = @project | ||
.files | ||
.sort_by { |f| [f.name == 'Overview' ? 0 : 1, f.name.downcase] } | ||
@user_can_add_file = can? :new, @project.files.build, @project | ||
end | ||
|
||
def new; end | ||
|
||
def create | ||
if @file.update(file_params(%i[content name])) | ||
redirect_to [@project.owner, @project, @file], | ||
notice: 'File successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def show; end | ||
|
||
def edit_content; end | ||
|
||
def update_content | ||
if @file.update(file_params(:content)) | ||
redirect_to [@project.owner, @project, @file], | ||
notice: 'File successfully updated.' | ||
else | ||
render :edit_content | ||
end | ||
end | ||
|
||
def edit_name; end | ||
|
||
def update_name | ||
if @file.update(file_params(:name)) | ||
redirect_to [@project.owner, @project, @file], | ||
notice: 'File successfully updated.' | ||
else | ||
render :edit_name | ||
end | ||
end | ||
|
||
def delete; end | ||
|
||
def destroy | ||
@file.revision_author = current_user | ||
@file.revision_summary = params[:version_control_file][:revision_summary] | ||
if @file.destroy | ||
redirect_to profile_project_files_path(@project.owner, @project), | ||
notice: 'File successfully deleted.' | ||
else | ||
render :delete | ||
end | ||
end | ||
|
||
private | ||
|
||
rescue_from CanCan::AccessDenied do |exception| | ||
redirect_to [@project.owner, @project, @file], | ||
alert: exception.message | ||
end | ||
|
||
def authorize_action | ||
authorize! params[:action].to_sym, @file, @project | ||
end | ||
|
||
def set_project | ||
@project = Project.find(params[:profile_handle], params[:project_slug]) | ||
end | ||
|
||
def build_file | ||
@file = @project.files.build | ||
end | ||
|
||
def set_file | ||
@file = @project.files.find params[:name] | ||
end | ||
|
||
def file_params(permitted_attributes = []) | ||
params.require(:version_control_file) | ||
.permit(*permitted_attributes, :revision_summary) | ||
.merge(revision_author: current_user) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
# Define helpers needed in file files | ||
module FileHelper | ||
# rubocop:disable Metrics/MethodLength | ||
def authorized_actions_for_project_file(file, project) | ||
authorized_actions = [] | ||
if can? :edit_content, file, project | ||
authorized_actions.push( | ||
name: :edit, | ||
link: edit_profile_project_file_path(project.owner, project, file) | ||
) | ||
end | ||
if can? :edit_name, file, project | ||
authorized_actions.push( | ||
name: :rename, | ||
link: rename_profile_project_file_path(project.owner, project, file) | ||
) | ||
end | ||
if can? :delete, file, project | ||
authorized_actions.push( | ||
name: :delete, | ||
link: delete_profile_project_file_path(project.owner, project, file) | ||
) | ||
end | ||
authorized_actions | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
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
Oops, something went wrong.