Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/appStore/InstalledAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,16 @@ func (handler *InstalledAppRestHandlerImpl) DeployBulk(w http.ResponseWriter, r
}
//RBAC block ends here

visited := make(map[string]bool)

for _, item := range request.ChartGroupInstallChartRequest {
if visited[item.AppName] {
handler.Logger.Errorw("service err, CreateInstalledApp", "err", err, "payload", request)
common.WriteJsonResp(w, errors.New("duplicate appName found"), nil, http.StatusBadRequest)
return
} else {
visited[item.AppName] = true
}
isChartRepoActive, err := handler.appStoreDeploymentService.IsChartRepoActive(item.AppStoreVersion)
if err != nil {
handler.Logger.Errorw("service err, CreateInstalledApp", "err", err, "payload", request)
Expand Down
10 changes: 7 additions & 3 deletions api/restHandler/ChartGroupRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ func (impl *ChartGroupRestHandlerImpl) CreateChartGroup(w http.ResponseWriter, r
res, err := impl.ChartGroupService.CreateChartGroup(&request)
if err != nil {
impl.Logger.Errorw("service err, CreateChartGroup", "err", err, "payload", request)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
statusCode := http.StatusInternalServerError
if service.AppNameAlreadyExistsError == err.Error() {
statusCode = http.StatusBadRequest
}
common.WriteJsonResp(w, err, nil, statusCode)
return
}
common.WriteJsonResp(w, err, res, http.StatusOK)
Expand Down Expand Up @@ -312,7 +316,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupListMin(w http.ResponseWrite
common.WriteJsonResp(w, err, res, http.StatusOK)
}

func(impl *ChartGroupRestHandlerImpl) DeleteChartGroup(w http.ResponseWriter, r *http.Request){
func (impl *ChartGroupRestHandlerImpl) DeleteChartGroup(w http.ResponseWriter, r *http.Request) {
userId, err := impl.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
Expand Down Expand Up @@ -350,4 +354,4 @@ func(impl *ChartGroupRestHandlerImpl) DeleteChartGroup(w http.ResponseWriter, r
return
}
common.WriteJsonResp(w, err, CHART_GROUP_DELETE_SUCCESS_RESP, http.StatusOK)
}
}
1 change: 1 addition & 0 deletions internal/sql/repository/app/AppRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (repo AppRepositoryImpl) CheckAppExists(appNames []string) ([]*App, error)
err := repo.dbConnection.
Model(&apps).
Where("app_name in (?)", pg.In(appNames)).
Where("active = ?", true).
Select()
return apps, err
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/appStore/deployment/repository/ChartGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type ChartGroupReposotory interface {
FindById(chartGroupId int) (*ChartGroup, error)
GetAll(max int) ([]*ChartGroup, error)
MarkChartGroupDeleted(chartGroupId int, tx *pg.Tx) error
FindByName(chartGroupName string) (bool, error)
}

func (impl *ChartGroupReposotoryImpl) Save(model *ChartGroup) (*ChartGroup, error) {
Expand Down Expand Up @@ -105,3 +106,12 @@ func (impl *ChartGroupReposotoryImpl) MarkChartGroupDeleted(chartGroupId int, tx
Update()
return err
}

func (impl *ChartGroupReposotoryImpl) FindByName(chartGroupName string) (bool, error) {
var ChartGroup ChartGroup
exists, err := impl.dbConnection.Model(&ChartGroup).Where("name = ?", chartGroupName).
Where("deleted = ?", false).
Exists()

return exists, err
}
16 changes: 15 additions & 1 deletion pkg/appStore/deployment/service/ChartGroupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package service

import (
"errors"
appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
"github.com/devtron-labs/devtron/pkg/appStore/deployment/repository"
appStoreValuesRepository "github.com/devtron-labs/devtron/pkg/appStore/values/repository"
Expand Down Expand Up @@ -69,7 +70,7 @@ type ChartGroupList struct {
Groups []*ChartGroupBean `json:"groups,omitempty"`
}
type ChartGroupBean struct {
Name string `json:"name,omitempty" validate:"name-component,max=200"`
Name string `json:"name,omitempty" validate:"name-component,max=200,min=5"`
Description string `json:"description,omitempty"`
Id int `json:"id,omitempty"`
ChartGroupEntries []*ChartGroupEntryBean `json:"chartGroupEntries,omitempty"`
Expand Down Expand Up @@ -108,8 +109,21 @@ type InstalledChart struct {
InstalledAppId int `json:"installedAppId,omitempty"`
}

const AppNameAlreadyExistsError = "A chart with this name already exist"

func (impl *ChartGroupServiceImpl) CreateChartGroup(req *ChartGroupBean) (*ChartGroupBean, error) {
impl.Logger.Debugw("chart group create request", "req", req)

exist, err := impl.chartGroupRepository.FindByName(req.Name)
if err != nil {
impl.Logger.Errorw("error in creating chart group", "req", req, "err", err)
return nil, err
}
if exist {
impl.Logger.Errorw("Chart with this name already exist", "req", req, "err", err)
return nil, errors.New(AppNameAlreadyExistsError)
}

chartGrouModel := &repository.ChartGroup{
Name: req.Name,
Description: req.Description,
Expand Down