scinote-web/app/controllers/at_who_controller.rb

106 lines
3 KiB
Ruby
Raw Normal View History

class AtWhoController < ApplicationController
include InputSanitizeHelper
before_action :load_vars
2017-01-05 17:52:00 +08:00
before_action :check_users_permissions
def users
2020-09-11 19:00:13 +08:00
users = @team.search_users(@query).limit(Constants::ATWHO_SEARCH_LIMIT + 1)
render json: {
users: [render_to_string(partial: 'shared/smart_annotation/users', locals: { users: users }, formats: :html)]
}
end
2017-01-09 18:33:28 +08:00
def menu_items
res = SmartAnnotation.new(current_user, current_team, @query)
2017-01-09 18:33:28 +08:00
respond_to do |format|
format.json do
render json: {
prj: res.projects,
exp: res.experiments,
tsk: res.my_modules,
status: :ok
}
end
end
end
def rep_items
repository =
if params[:repository_id].present?
Repository.find_by(id: params[:repository_id])
else
Repository.active.accessible_by_teams(@team).first
end
if repository && can_read_repository?(repository)
items = SmartAnnotation.new(current_user, current_team, @query)
.repository_rows(repository, params[:assignable_my_module_id])
repository_id = repository.id
else
items = []
repository_id = nil
end
render json: {
res: [
render_to_string(partial: 'shared/smart_annotation/repository_items',
locals: { repository_rows: items, repository: repository },
formats: :html)
],
repository: repository_id,
team: current_team.id
}
end
2020-09-04 22:48:53 +08:00
def menu
repositories = Repository.active.accessible_by_teams(@team)
render json: {
html: render_to_string(partial: 'shared/smart_annotation/menu',
locals: { repositories: repositories },
formats: :html)
}
2017-01-05 20:29:21 +08:00
end
def projects
res = SmartAnnotation.new(current_user, current_team, @query)
render json: {
res: [render_to_string(partial: 'shared/smart_annotation/project_items',
locals: { projects: res.projects },
formats: :html)],
team: current_team.id
}
2017-01-05 20:29:21 +08:00
end
def experiments
res = SmartAnnotation.new(current_user, current_team, @query)
render json: {
res: [render_to_string(partial: 'shared/smart_annotation/experiment_items',
locals: { experiments: res.experiments },
formats: :html)],
team: current_team.id
}
2017-01-05 20:29:21 +08:00
end
def my_modules
res = SmartAnnotation.new(current_user, current_team, @query)
render json: {
res: [render_to_string(partial: 'shared/smart_annotation/my_module_items',
locals: { my_modules: res.my_modules },
formats: :html)],
team: current_team.id
}
2017-01-05 17:52:00 +08:00
end
private
def load_vars
@team = Team.find_by_id(params[:id])
@query = params[:query]
render_404 unless @team
end
def check_users_permissions
render_403 unless can_read_team?(@team)
end
end