Skip to content

Commit

Permalink
opne issues route unprotected
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismail731404 committed Dec 13, 2023
1 parent 1f2073c commit 529e32e
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
73 changes: 73 additions & 0 deletions internals/handlers/issues_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,79 @@ func GetIssues(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, issueList)
}

// GetIssuesByStatesByPageUnProtected godoc
// @Summary Get issues by issues states (paginated)
// @Description Get issues by issues states (paginated)
// @Tags Issues
// @Produce json
// @Param states query string true "Issue states (comma separated) (Available: open, draft, closedfeedback, closednofeedback, closedtimeout)"
// @Param limit query string false "Result limit (default: 50)"
// @Param offset query string false "Result offset (default: 0)"
// @Param sort_by query string false "Result offset (example: 'sort_by=desc(last_modified),asc(id)')"
// @Security Bearer
// @Success 200 "Status OK"
// @Failure 500 "internal server error"
// @Router /engine/issues/unprotected [get]
func GetIssuesByStatesByPageUnProtected(w http.ResponseWriter, r *http.Request) {

var err error
var limit int
var offset int
var sortOptions = make([]models.SortOption, 0)

states := strings.Split(r.URL.Query().Get("states"), ",")

if rawSize := r.URL.Query().Get("limit"); rawSize != "" {
limit, err = ParseInt(rawSize)
if err != nil {
zap.L().Warn("Parse input limit", zap.Error(err), zap.String("rawNhit", rawSize))
render.Error(w, r, render.ErrAPIParsingInteger, err)
return
}
}

if rawOffset := r.URL.Query().Get("offset"); rawOffset != "" {
offset, err = ParseInt(rawOffset)
if err != nil {
zap.L().Warn("Parse input offset", zap.Error(err), zap.String("raw offset", rawOffset))
render.Error(w, r, render.ErrAPIParsingInteger, err)
return
}
}

if rawSortBy := r.URL.Query().Get("sort_by"); rawSortBy != "" {
sortOptions, err = ParseSortBy(rawSortBy, allowedSortByFields)
if err != nil {
zap.L().Warn("Parse input sort_by", zap.Error(err), zap.String("raw sort_by", rawSortBy))
render.Error(w, r, render.ErrAPIParsingSortBy, err)
return
}
}

searchOptions := models.SearchOptions{
Limit: limit,
Offset: offset,
SortBy: sortOptions,
}

var issuesSlice []models.Issue
var total int
issuesSlice, total, err = issues.R().GetByStateByPage(states, searchOptions)

if err != nil {
zap.L().Error("Error on getting issues", zap.Error(err))
render.Error(w, r, render.ErrAPIDBSelectFailed, err)
return
}

paginatedResource := models.PaginatedResource{
Total: total,
Items: issuesSlice,
}

render.JSON(w, r, paginatedResource)
}

// GetIssuesByStatesByPage godoc
// @Summary Get issues by issues states (paginated)
// @Description Get issues by issues states (paginated)
Expand Down
39 changes: 39 additions & 0 deletions internals/handlers/situations_linked_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,42 @@ func GetSituationTemplateInstances(w http.ResponseWriter, r *http.Request) {

render.JSON(w, r, instancesSlice)
}

// GetSituationTemplateInstancesUnprotected godoc
// @Summary Get the list of situation template instances
// @Description Get the list of situation template instances
// @Tags Situations
// @Produce json
// @Param id path string true "Situation ID"
// @Security Bearer
// @Success 200 {array} situation.TemplateInstance
// @Failure 400 "Status Bad Request"
// @Failure 401 "Status Unauthorized"
// @Router /engine/situations/{id}/instances/unprotected [get]
func GetSituationTemplateInstancesUnprotected(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "id")
idSituation, err := strconv.ParseInt(id, 10, 64)
if err != nil {
zap.L().Warn("Error on parsing situation id", zap.String("situationID", id), zap.Error(err))
render.Error(w, r, render.ErrAPIParsingInteger, err)
return
}

instances, err := situation.R().GetAllTemplateInstances(idSituation)
if err != nil {
zap.L().Error("Error on getting situation template instances", zap.String("situationID", id), zap.Error(err))
render.Error(w, r, render.ErrAPIDBSelectFailed, err)
return
}

instancesSlice := make([]situation.TemplateInstance, 0)
for _, instance := range instances {
instancesSlice = append(instancesSlice, instance)
}

sort.SliceStable(instancesSlice, func(i, j int) bool {
return instancesSlice[i].ID < instancesSlice[j].ID
})

render.JSON(w, r, instancesSlice)
}
6 changes: 6 additions & 0 deletions internals/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func buildRoutesV3Basic(config Config) (func(r chi.Router), error) {

rg.Post("/login", securityMiddleware.GetToken())
r.Get("/authmode", handlers.GetAuthenticationMode)
rg.Get("/engine/issues/unprotected", handlers.GetIssuesByStatesByPageUnProtected)
rg.Get("/engine/situations/{id}/instances/unprotected", handlers.GetSituationTemplateInstancesUnprotected)
})

// Protected routes
Expand Down Expand Up @@ -241,6 +243,8 @@ func buildRoutesV3SAML(config Config) (func(r chi.Router), error) {
rg.Handle("/saml/*", samlSPMiddleware)
rg.Handle("/logout", handlers.LogoutHandler(samlSPMiddleware.Deconnexion))
r.Get("/authmode", handlers.GetAuthenticationMode)
rg.Get("/engine/issues/unprotected", handlers.GetIssuesByStatesByPageUnProtected)
rg.Get("/engine/situations/{id}/instances/unprotected", handlers.GetSituationTemplateInstancesUnprotected)
})

// Protected routes
Expand Down Expand Up @@ -311,6 +315,8 @@ func buildRoutesV3OIDC(config Config) (func(r chi.Router), error) {
rg.Get("/auth/oidc", handlers.HandleOIDCRedirect)
rg.Get("/auth/oidc/callback", handlers.HandleOIDCCallback)
r.Get("/authmode", handlers.GetAuthenticationMode)
rg.Get("/engine/issues/unprotected", handlers.GetIssuesByStatesByPageUnProtected)
rg.Get("/engine/situations/{id}/instances/unprotected", handlers.GetSituationTemplateInstancesUnprotected)
})

// Protected routes
Expand Down
Binary file added plugin/myrtea-flashdef.plugin
Binary file not shown.

0 comments on commit 529e32e

Please sign in to comment.