2017-01-04 17:54:02 +08:00
|
|
|
class AtWhoController < ApplicationController
|
2019-05-08 23:38:24 +08:00
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2017-01-04 17:54:02 +08:00
|
|
|
before_action :load_vars
|
2017-01-05 17:52:00 +08:00
|
|
|
before_action :check_users_permissions
|
2017-01-04 17:54:02 +08:00
|
|
|
|
|
|
|
def users
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
2017-04-13 22:14:12 +08:00
|
|
|
users: generate_users_data,
|
2017-01-04 17:54:02 +08:00
|
|
|
status: :ok
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-09 18:33:28 +08:00
|
|
|
def menu_items
|
2017-01-24 23:57:14 +08:00
|
|
|
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,
|
|
|
|
sam: res.samples,
|
|
|
|
status: :ok
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-03 02:38:56 +08:00
|
|
|
def rep_items
|
|
|
|
repository = Repository.find_by_id(params[:repository_id])
|
2018-05-14 21:34:23 +08:00
|
|
|
items =
|
2019-07-17 22:00:49 +08:00
|
|
|
if repository && can_read_repository?(repository)
|
2018-05-14 21:34:23 +08:00
|
|
|
SmartAnnotation.new(current_user, current_team, @query)
|
|
|
|
.repository_rows(repository)
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
2017-01-05 17:52:00 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
2018-05-14 21:34:23 +08:00
|
|
|
res: items,
|
2018-04-03 02:38:56 +08:00
|
|
|
status: :ok
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def repositories
|
2019-07-26 21:41:23 +08:00
|
|
|
repositories = Repository.accessible_by_teams(@team)
|
2018-04-03 02:38:56 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
repositories: repositories.map do |r|
|
2019-05-08 23:38:24 +08:00
|
|
|
[r.id, escape_input(r.name.truncate(Constants::ATWHO_REP_NAME_LIMIT))]
|
2018-04-03 02:38:56 +08:00
|
|
|
end.to_h,
|
2017-01-05 20:29:21 +08:00
|
|
|
status: :ok
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def projects
|
2017-01-24 23:57:14 +08:00
|
|
|
res = SmartAnnotation.new(current_user, current_team, @query)
|
2017-01-05 20:29:21 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
res: res.projects,
|
|
|
|
status: :ok
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def experiments
|
2017-01-24 23:57:14 +08:00
|
|
|
res = SmartAnnotation.new(current_user, current_team, @query)
|
2017-01-05 20:29:21 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
res: res.experiments,
|
|
|
|
status: :ok
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def my_modules
|
2017-01-24 23:57:14 +08:00
|
|
|
res = SmartAnnotation.new(current_user, current_team, @query)
|
2017-01-05 20:29:21 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
res: res.my_modules,
|
2017-01-05 17:52:00 +08:00
|
|
|
status: :ok
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-04 17:54:02 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def load_vars
|
2017-01-25 00:06:51 +08:00
|
|
|
@team = Team.find_by_id(params[:id])
|
2017-01-04 17:54:02 +08:00
|
|
|
@query = params[:query]
|
2017-01-24 23:57:14 +08:00
|
|
|
render_404 unless @team
|
2017-01-04 17:54:02 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_users_permissions
|
2017-12-13 21:43:11 +08:00
|
|
|
render_403 unless can_read_team?(@team)
|
2017-01-04 17:54:02 +08:00
|
|
|
end
|
2017-04-13 22:14:12 +08:00
|
|
|
|
|
|
|
def generate_users_data
|
|
|
|
# Search users
|
|
|
|
res = @team.search_users(@query)
|
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
|
|
|
.pluck(:id, :full_name, :email)
|
|
|
|
|
|
|
|
# Add avatars, Base62, convert to JSON
|
|
|
|
data = []
|
|
|
|
res.each do |obj|
|
|
|
|
tmp = {}
|
|
|
|
tmp['id'] = obj[0].base62_encode
|
2019-05-08 23:38:24 +08:00
|
|
|
tmp['full_name'] = escape_input(obj[1].truncate(Constants::NAME_TRUNCATION_LENGTH_DROPDOWN))
|
|
|
|
tmp['email'] = escape_input(obj[2])
|
2017-04-14 17:13:58 +08:00
|
|
|
tmp['img_url'] = avatar_path(obj[0], :icon_small)
|
2017-04-13 22:14:12 +08:00
|
|
|
data << tmp
|
|
|
|
end
|
|
|
|
data
|
|
|
|
end
|
2017-01-04 17:54:02 +08:00
|
|
|
end
|