Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: description for apps and jobs #3668

Merged
merged 47 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
859a528
cluster notes code refactoring
gireesh-devtron Jul 20, 2023
1d9d385
uncommit port change
gireesh-devtron Jul 20, 2023
801c596
code refactoring and cluster note struct changes
gireesh-devtron Jul 21, 2023
df0bc4e
Merge branch 'main' into app_job_description
gireesh-devtron Jul 24, 2023
33bddb6
revert description from appListing api
gireesh-devtron Jul 24, 2023
d813956
wip
gireesh-devtron Jul 24, 2023
2f96e57
query fix
gireesh-devtron Jul 24, 2023
89bb62a
fix test files
gireesh-devtron Jul 24, 2023
1905b8b
added all the db operations in transaction
gireesh-devtron Jul 24, 2023
1a7dfbf
non pointer payload in db request
gireesh-devtron Jul 24, 2023
2187cad
fixes
gireesh-devtron Jul 24, 2023
7e45ba5
rewire
gireesh-devtron Jul 24, 2023
ed3dce8
fix
gireesh-devtron Jul 24, 2023
fdd8483
error log added
gireesh-devtron Jul 24, 2023
d376b5e
pg table name fix and trasaction handling bug fix
gireesh-devtron Jul 24, 2023
1cbf69b
err handling
gireesh-devtron Jul 24, 2023
53a168d
added cascade delete constraint
gireesh-devtron Jul 24, 2023
85ab74d
updated down script
gireesh-devtron Jul 24, 2023
557d79a
added missing logs
gireesh-devtron Jul 25, 2023
7d82b01
renaming
gireesh-devtron Jul 25, 2023
d493df4
fix existing integration tests
gireesh-devtron Jul 25, 2023
872a123
remove logger
gireesh-devtron Jul 25, 2023
d384561
rewire
gireesh-devtron Jul 25, 2023
32e2180
rewire
gireesh-devtron Jul 25, 2023
01a73a4
refactor
gireesh-devtron Jul 25, 2023
c7285a2
moved history data handling from genericNoteService to genericNoteHis…
gireesh-devtron Jul 25, 2023
b3a09d2
generated mocks
gireesh-devtron Jul 25, 2023
25d96e0
added unit tests for save method
gireesh-devtron Jul 25, 2023
ae67b01
sql down's code fixed
ShashwatDadhich Jul 25, 2023
e555817
sql down's code fixed for ;
ShashwatDadhich Jul 25, 2023
fad7a21
identifier missing
gireesh-devtron Jul 25, 2023
3c2775c
identifier missing
gireesh-devtron Jul 25, 2023
18a1033
unit tests WIP
gireesh-devtron Jul 25, 2023
4e3ff51
unit tests added for save function
gireesh-devtron Jul 25, 2023
8a8f6ef
vars rename
gireesh-devtron Jul 25, 2023
7a36f04
remove commented code
gireesh-devtron Jul 25, 2023
a60fbfc
changed end point
gireesh-devtron Jul 26, 2023
2f852f3
Merge branch 'main' into app_job_description
gireesh-devtron Jul 26, 2023
8db2711
resolve review comments
gireesh-devtron Jul 26, 2023
9ed8cc2
refactor
gireesh-devtron Jul 26, 2023
b9c488d
fix
gireesh-devtron Jul 26, 2023
07c48eb
test script
gireesh-devtron Jul 26, 2023
a749184
cyclic dependency fix
gireesh-devtron Jul 27, 2023
c191ce1
query fix
gireesh-devtron Jul 27, 2023
babef63
added unit tests for update method
gireesh-devtron Jul 27, 2023
a6ce8e7
fix
gireesh-devtron Jul 27, 2023
4932825
merge main
gireesh-devtron Jul 27, 2023
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
16 changes: 12 additions & 4 deletions api/bean/AppView.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type AppContainer struct {
ProjectId int `json:"projectId"`
AppEnvironmentContainer []*AppEnvironmentContainer `json:"environments"`
DefaultEnv AppEnvironmentContainer `json:"-"`
Description GenericNoteResponseBean `json:"description"`
}

type AppContainerResponse struct {
Expand Down Expand Up @@ -58,11 +59,18 @@ type CiMaterialDTO struct {
SourceValue string `json:"value"`
}

type GenericNoteResponseBean struct {
Id int `json:"id" validate:"number"`
Description string `json:"description"`
UpdatedBy string `json:"updatedBy"`
UpdatedOn time.Time `json:"updatedOn"`
}

type JobContainer struct {
JobId int `json:"jobId"`
JobName string `json:"jobName""`
Description string `json:"description"`
JobCiPipelines []JobCIPipeline `json:"ciPipelines"'`
JobId int `json:"jobId"`
JobName string `json:"jobName""`
Description GenericNoteResponseBean `json:"description"`
JobCiPipelines []JobCIPipeline `json:"ciPipelines"'`
}

type JobCIPipeline struct {
Expand Down
45 changes: 12 additions & 33 deletions api/cluster/ClusterRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"context"
"encoding/json"
"errors"
"github.com/devtron-labs/devtron/pkg/genericNotes"
"github.com/devtron-labs/devtron/pkg/genericNotes/repository"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -59,7 +61,7 @@ type ClusterRestHandler interface {

type ClusterRestHandlerImpl struct {
clusterService cluster.ClusterService
clusterNoteService cluster.ClusterNoteService
clusterNoteService genericNotes.GenericNoteService
clusterDescriptionService cluster.ClusterDescriptionService
logger *zap.SugaredLogger
userService user.UserService
Expand All @@ -71,7 +73,7 @@ type ClusterRestHandlerImpl struct {
}

func NewClusterRestHandlerImpl(clusterService cluster.ClusterService,
clusterNoteService cluster.ClusterNoteService,
clusterNoteService genericNotes.GenericNoteService,
clusterDescriptionService cluster.ClusterDescriptionService,
logger *zap.SugaredLogger,
userService user.UserService,
Expand Down Expand Up @@ -349,13 +351,13 @@ func (impl ClusterRestHandlerImpl) FindById(w http.ResponseWriter, r *http.Reque
func (impl ClusterRestHandlerImpl) FindNoteByClusterId(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := vars["id"]
i, err := strconv.Atoi(id)
clusterId, err := strconv.Atoi(id)
if err != nil {
impl.logger.Errorw("request err, FindById", "error", err, "clusterId", id)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
bean, err := impl.clusterDescriptionService.FindByClusterIdWithClusterDetails(i)
bean, err := impl.clusterDescriptionService.FindByClusterIdWithClusterDetails(clusterId)
if err != nil {
if err == pg.ErrNoRows {
impl.logger.Errorw("cluster not found, FindById", "err", err, "clusterId", id)
Expand Down Expand Up @@ -452,7 +454,7 @@ func (impl ClusterRestHandlerImpl) UpdateClusterNote(w http.ResponseWriter, r *h
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
var bean cluster.ClusterNoteBean
var bean repository.GenericNote
err = decoder.Decode(&bean)
if err != nil {
impl.logger.Errorw("request err, Update", "error", err, "payload", bean)
Expand All @@ -466,9 +468,9 @@ func (impl ClusterRestHandlerImpl) UpdateClusterNote(w http.ResponseWriter, r *h
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
clusterDescription, err := impl.clusterDescriptionService.FindByClusterIdWithClusterDetails(bean.ClusterId)
clusterDescription, err := impl.clusterDescriptionService.FindByClusterIdWithClusterDetails(bean.Identifier)
if err != nil {
impl.logger.Errorw("service err, FindById", "err", err, "clusterId", bean.ClusterId)
impl.logger.Errorw("service err, FindById", "err", err, "clusterId", bean.Identifier)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
Expand All @@ -479,32 +481,9 @@ func (impl ClusterRestHandlerImpl) UpdateClusterNote(w http.ResponseWriter, r *h
}
// RBAC enforcer ends

_, err = impl.clusterNoteService.Update(&bean, userId)
if err == pg.ErrNoRows {
_, err = impl.clusterNoteService.Save(&bean, userId)
if err != nil {
impl.logger.Errorw("service err, Save", "error", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
}
if err != nil {
impl.logger.Errorw("service err, Update", "error", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
userInfo, err := impl.userService.GetById(bean.UpdatedBy)
if err != nil {
impl.logger.Errorw("user service err, FindById", "err", err, "userId", bean.UpdatedBy)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
clusterNoteResponseBean := &cluster.ClusterNoteResponseBean{
Id: bean.Id,
Description: bean.Description,
UpdatedOn: bean.UpdatedOn,
UpdatedBy: userInfo.EmailId,
}
bean.IdentifierType = repository.ClusterType
clusterNoteResponseBean, err := impl.clusterNoteService.Update(&bean, userId)

if err != nil {
impl.logger.Errorw("cluster note service err, Update", "error", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion api/cluster/ClusterRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (impl ClusterRouterImpl) InitClusterRouter(clusterRouter *mux.Router) {
Methods("PUT").
HandlerFunc(impl.clusterRestHandler.Update)

clusterRouter.Path("/description/note").
clusterRouter.Path("/description").
Methods("PUT").
HandlerFunc(impl.clusterRestHandler.UpdateClusterNote)

Expand Down
34 changes: 18 additions & 16 deletions api/cluster/wire_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cluster
import (
"github.com/devtron-labs/devtron/pkg/cluster"
"github.com/devtron-labs/devtron/pkg/cluster/repository"
"github.com/devtron-labs/devtron/pkg/genericNotes"
repository2 "github.com/devtron-labs/devtron/pkg/genericNotes/repository"
"github.com/google/wire"
)

Expand All @@ -16,14 +18,14 @@ var ClusterWireSet = wire.NewSet(

repository.NewClusterDescriptionRepositoryImpl,
wire.Bind(new(repository.ClusterDescriptionRepository), new(*repository.ClusterDescriptionRepositoryImpl)),
repository.NewClusterNoteHistoryRepositoryImpl,
wire.Bind(new(repository.ClusterNoteHistoryRepository), new(*repository.ClusterNoteHistoryRepositoryImpl)),
repository.NewClusterNoteRepositoryImpl,
wire.Bind(new(repository.ClusterNoteRepository), new(*repository.ClusterNoteRepositoryImpl)),
cluster.NewClusterNoteHistoryServiceImpl,
wire.Bind(new(cluster.ClusterNoteHistoryService), new(*cluster.ClusterNoteHistoryServiceImpl)),
cluster.NewClusterNoteServiceImpl,
wire.Bind(new(cluster.ClusterNoteService), new(*cluster.ClusterNoteServiceImpl)),
repository2.NewGenericNoteHistoryRepositoryImpl,
wire.Bind(new(repository2.GenericNoteHistoryRepository), new(*repository2.GenericNoteHistoryRepositoryImpl)),
repository2.NewGenericNoteRepositoryImpl,
wire.Bind(new(repository2.GenericNoteRepository), new(*repository2.GenericNoteRepositoryImpl)),
genericNotes.NewGenericNoteHistoryServiceImpl,
wire.Bind(new(genericNotes.GenericNoteHistoryService), new(*genericNotes.GenericNoteHistoryServiceImpl)),
genericNotes.NewGenericNoteServiceImpl,
wire.Bind(new(genericNotes.GenericNoteService), new(*genericNotes.GenericNoteServiceImpl)),
cluster.NewClusterDescriptionServiceImpl,
wire.Bind(new(cluster.ClusterDescriptionService), new(*cluster.ClusterDescriptionServiceImpl)),

Expand Down Expand Up @@ -51,14 +53,14 @@ var ClusterWireSetEa = wire.NewSet(

repository.NewClusterDescriptionRepositoryImpl,
wire.Bind(new(repository.ClusterDescriptionRepository), new(*repository.ClusterDescriptionRepositoryImpl)),
repository.NewClusterNoteHistoryRepositoryImpl,
wire.Bind(new(repository.ClusterNoteHistoryRepository), new(*repository.ClusterNoteHistoryRepositoryImpl)),
repository.NewClusterNoteRepositoryImpl,
wire.Bind(new(repository.ClusterNoteRepository), new(*repository.ClusterNoteRepositoryImpl)),
cluster.NewClusterNoteHistoryServiceImpl,
wire.Bind(new(cluster.ClusterNoteHistoryService), new(*cluster.ClusterNoteHistoryServiceImpl)),
cluster.NewClusterNoteServiceImpl,
wire.Bind(new(cluster.ClusterNoteService), new(*cluster.ClusterNoteServiceImpl)),
repository2.NewGenericNoteHistoryRepositoryImpl,
wire.Bind(new(repository2.GenericNoteHistoryRepository), new(*repository2.GenericNoteHistoryRepositoryImpl)),
repository2.NewGenericNoteRepositoryImpl,
wire.Bind(new(repository2.GenericNoteRepository), new(*repository2.GenericNoteRepositoryImpl)),
genericNotes.NewGenericNoteHistoryServiceImpl,
wire.Bind(new(genericNotes.GenericNoteHistoryService), new(*genericNotes.GenericNoteHistoryServiceImpl)),
genericNotes.NewGenericNoteServiceImpl,
wire.Bind(new(genericNotes.GenericNoteService), new(*genericNotes.GenericNoteServiceImpl)),
cluster.NewClusterDescriptionServiceImpl,
wire.Bind(new(cluster.ClusterDescriptionService), new(*cluster.ClusterDescriptionServiceImpl)),

Expand Down
4 changes: 4 additions & 0 deletions api/restHandler/AppListingRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
service1 "github.com/devtron-labs/devtron/pkg/appStore/deployment/service"
"github.com/devtron-labs/devtron/pkg/cluster"
"github.com/devtron-labs/devtron/pkg/deploymentGroup"
"github.com/devtron-labs/devtron/pkg/genericNotes"
"github.com/devtron-labs/devtron/pkg/k8s"
application3 "github.com/devtron-labs/devtron/pkg/k8s/application"
"github.com/devtron-labs/devtron/pkg/pipeline"
Expand Down Expand Up @@ -106,6 +107,7 @@ type AppListingRestHandlerImpl struct {
appStatusService appStatus.AppStatusService
installedAppRepository repository.InstalledAppRepository
environmentClusterMappingsService cluster.EnvironmentService
genericNoteService genericNotes.GenericNoteService
cfg *bean.Config
k8sApplicationService application3.K8sApplicationService
}
Expand Down Expand Up @@ -137,6 +139,7 @@ func NewAppListingRestHandlerImpl(application application.ServiceClient,
pipelineRepository pipelineConfig.PipelineRepository,
appStatusService appStatus.AppStatusService, installedAppRepository repository.InstalledAppRepository,
environmentClusterMappingsService cluster.EnvironmentService,
genericNoteService genericNotes.GenericNoteService,
k8sApplicationService application3.K8sApplicationService,
) *AppListingRestHandlerImpl {
cfg := &bean.Config{}
Expand Down Expand Up @@ -167,6 +170,7 @@ func NewAppListingRestHandlerImpl(application application.ServiceClient,
appStatusService: appStatusService,
installedAppRepository: installedAppRepository,
environmentClusterMappingsService: environmentClusterMappingsService,
genericNoteService: genericNoteService,
cfg: cfg,
k8sApplicationService: k8sApplicationService,
}
Expand Down
85 changes: 68 additions & 17 deletions api/restHandler/AppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/devtron-labs/devtron/api/restHandler/common"
"github.com/devtron-labs/devtron/pkg/app"
"github.com/devtron-labs/devtron/pkg/bean"
"github.com/devtron-labs/devtron/pkg/genericNotes"
"github.com/devtron-labs/devtron/pkg/genericNotes/repository"
"github.com/devtron-labs/devtron/pkg/user"
"github.com/devtron-labs/devtron/pkg/user/casbin"
"github.com/devtron-labs/devtron/util/rbac"
Expand All @@ -42,31 +44,35 @@ type AppRestHandler interface {
UpdateApp(w http.ResponseWriter, r *http.Request)
UpdateProjectForApps(w http.ResponseWriter, r *http.Request)
GetAppListByTeamIds(w http.ResponseWriter, r *http.Request)
UpdateAppDescription(w http.ResponseWriter, r *http.Request)
}

type AppRestHandlerImpl struct {
logger *zap.SugaredLogger
appService app.AppCrudOperationService
userAuthService user.UserService
validator *validator.Validate
enforcerUtil rbac.EnforcerUtil
enforcer casbin.Enforcer
helmAppService client.HelmAppService
enforcerUtilHelm rbac.EnforcerUtilHelm
logger *zap.SugaredLogger
appService app.AppCrudOperationService
userAuthService user.UserService
validator *validator.Validate
enforcerUtil rbac.EnforcerUtil
enforcer casbin.Enforcer
helmAppService client.HelmAppService
enforcerUtilHelm rbac.EnforcerUtilHelm
genericNoteService genericNotes.GenericNoteService
}

func NewAppRestHandlerImpl(logger *zap.SugaredLogger, appService app.AppCrudOperationService,
userAuthService user.UserService, validator *validator.Validate, enforcerUtil rbac.EnforcerUtil,
enforcer casbin.Enforcer, helmAppService client.HelmAppService, enforcerUtilHelm rbac.EnforcerUtilHelm) *AppRestHandlerImpl {
enforcer casbin.Enforcer, helmAppService client.HelmAppService, enforcerUtilHelm rbac.EnforcerUtilHelm,
genericNoteService genericNotes.GenericNoteService) *AppRestHandlerImpl {
handler := &AppRestHandlerImpl{
logger: logger,
appService: appService,
userAuthService: userAuthService,
validator: validator,
enforcerUtil: enforcerUtil,
enforcer: enforcer,
helmAppService: helmAppService,
enforcerUtilHelm: enforcerUtilHelm,
logger: logger,
appService: appService,
userAuthService: userAuthService,
validator: validator,
enforcerUtil: enforcerUtil,
enforcer: enforcer,
helmAppService: helmAppService,
enforcerUtilHelm: enforcerUtilHelm,
genericNoteService: genericNoteService,
}
return handler
}
Expand Down Expand Up @@ -337,3 +343,48 @@ func (handler AppRestHandlerImpl) GetAppListByTeamIds(w http.ResponseWriter, r *
// RBAC
common.WriteJsonResp(w, err, projectWiseApps, http.StatusOK)
}

func (handler AppRestHandlerImpl) UpdateAppDescription(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
decoder := json.NewDecoder(r.Body)
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
handler.logger.Errorw("service err, Update", "error", err, "userId", userId)
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
var bean repository.GenericNote
err = decoder.Decode(&bean)
if err != nil {
handler.logger.Errorw("request err, Update", "error", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
handler.logger.Debugw("request payload, Update", "payload", bean)
err = handler.validator.Struct(bean)
if err != nil {
handler.logger.Errorw("validate err, Update", "error", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
bean.IdentifierType = repository.AppType

//rbac implementation starts here

// check for existing project/app permission
object := handler.enforcerUtil.GetAppRBACNameByAppId(bean.Identifier)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, casbin.ActionUpdate, object); !ok {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusForbidden)
return
}

// RBAC enforcer ends

genericNoteResponseBean, err := handler.genericNoteService.Update(&bean, userId)
if err != nil {
handler.logger.Errorw("cluster note service err, Update", "error", err, "payload", bean)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, genericNoteResponseBean, http.StatusOK)
}
3 changes: 3 additions & 0 deletions api/router/AppRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ func (router AppRouterImpl) InitAppRouter(appRouter *mux.Router) {

appRouter.Path("/min").HandlerFunc(router.handler.GetAppListByTeamIds).Methods("GET")

appRouter.Path("/description").
Methods("PUT").
HandlerFunc(router.handler.UpdateAppDescription)
}
Loading