Add endpoint for fetching label template tags [SCI-7053] (#4319)

This commit is contained in:
artoscinote 2022-08-10 11:35:38 +02:00 committed by GitHub
parent 6403e2256c
commit 4e768bec04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions

View file

@ -85,6 +85,10 @@ class LabelTemplatesController < ApplicationController
render json: { error: I18n.t('errors.general') }, status: :unprocessable_entity
end
def template_tags
render json: LabelTemplates::TagService.new(current_team).tags
end
private
def check_feature_enabled

View file

@ -0,0 +1,42 @@
# frozen_string_literal: true
module LabelTemplates
class TagService
DEFAULT_COLUMNS = [
{ key: :item_id, tag: '{{ITEM_ID}}' },
{ key: :added_by, tag: '{{ADDED_BY}}' },
{ key: :added_on, tag: '{{ADDED_ON}}' },
{ key: :name, tag: '{{NAME}}' }
].freeze
def initialize(team)
@team = team
end
def tags
{
default: DEFAULT_COLUMNS,
common: repository_tags.pluck(:tags).reduce(:&),
repository: repository_tags
}
end
private
def repository_tags
@repository_tags ||=
Repository.includes(:repository_columns).active.where(team: @team).map do |repository|
{
repository_id: repository.id,
repository_name: repository.name,
tags: repository.repository_columns.pluck(:name).map do |name|
{
key: name,
tag: "{{COLUMN_[#{name}]}}"
}
end
}
end
end
end
end

View file

@ -53,6 +53,7 @@ Rails.application.routes.draw do
post :duplicate
post :delete
get :datatable
get :template_tags
end
end