mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-14 05:05:55 +08:00
39 lines
1.1 KiB
Ruby
39 lines
1.1 KiB
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module Navigator
|
||
|
class ProjectsController < BaseController
|
||
|
before_action :load_project
|
||
|
before_action :check_read_permissions, except: :index
|
||
|
|
||
|
def index
|
||
|
project_and_folders = project_level_branch(nil, params[:archived] == 'true')
|
||
|
render json: { items: project_and_folders }
|
||
|
end
|
||
|
|
||
|
def show
|
||
|
experiments = experiment_level_branch(@project, params[:archived] == 'true')
|
||
|
render json: { items: experiments }
|
||
|
end
|
||
|
|
||
|
def tree
|
||
|
experiments = experiment_level_branch(@project, params[:archived] == 'true')
|
||
|
tree = project_level_branch(@project.project_folder, params[:archived] == 'true')
|
||
|
tree.find { |i| i[:id] == @project.code }[:children] = experiments
|
||
|
|
||
|
tree = build_folder_tree(@project.project_folder, tree) if @project.project_folder
|
||
|
|
||
|
render json: { items: tree }
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def load_project
|
||
|
@project = current_team.projects.find_by(id: params[:id])
|
||
|
end
|
||
|
|
||
|
def check_read_permissions
|
||
|
render_403 and return unless can_read_project?(@project)
|
||
|
end
|
||
|
end
|
||
|
end
|