func Configure(ctx *middleware.Context, form models.BoardRequest) { status, err := models.ConfigureBoard(ctx.User, ctx.Provider, &form) if err != nil { ctx.JSON(status, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{}) }
// CreateMilestone creates a new board milestone. func CreateMilestone(ctx *middleware.Context, form models.MilestoneRequest) { milestone, code, err := ctx.DataSource.CreateMilestone(&form) if err != nil { ctx.JSON(code, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: milestone, }) }
// ListBoards gets a list of board accessible by the authenticated user. func ListBoards(ctx *middleware.Context) { boards, err := models.ListBoards(ctx.User, ctx.Provider) if err != nil { ctx.JSON(http.StatusUnauthorized, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: boards, }) }
// CreateComment creates new kanban comment func CreateComment(ctx *middleware.Context, form models.CommentRequest) { com, code, err := models.CreateComment(ctx.User, ctx.Provider, &form) if err != nil { ctx.JSON(code, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: com, }) }
// SignUp sing ups with data func SignUp(ctx *middleware.Context, form auth.SignUp) { u, err := models.UserSignUp(form.Uname, form.Email, form.Pass, form.Token, ctx.Provider) if err != nil { ctx.JSON(http.StatusBadRequest, models.ResponseError{ Success: false, Message: err.Error(), }) return } tokens, _ := u.SignedString() ctx.JSON(http.StatusOK, auth.ResponseAuth{ Success: true, Token: tokens, }) }
// MoveToCard updates an existing board card. func MoveToCard(ctx *middleware.Context, form models.CardRequest) { card, code, err := ctx.DataSource.UpdateCard(&form) if err != nil { ctx.JSON(code, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: card, }) ctx.Broadcast(card.RoutingKey(), &models.Response{ Data: card, Event: "card.move", }) source := models.ParseLabelToStage(form.Stage["source"]) dest := models.ParseLabelToStage(form.Stage["dest"]) if source.Name != dest.Name { com := models.CommentRequest{ CardId: form.CardId, ProjectId: form.ProjectId, Body: fmt.Sprintf("moved issue from **%s** to **%s**", source.Name, dest.Name), } go func() { ctx.DataSource.CreateComment(&com) }() } }
// ListComments gets a list of comment on board and card // accessible by the authenticated user. func ListComments(ctx *middleware.Context) { boards, err := models.ListComments(ctx.User, ctx.Provider, ctx.Query("project_id"), ctx.Query("issue_id")) if err != nil { ctx.JSON(http.StatusUnauthorized, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: boards, }) }
// ListMembers gets a list of member on board accessible by the authenticated user. func ListMembers(ctx *middleware.Context) { members, err := ctx.DataSource.ListMembers(ctx.Query("project_id")) if err != nil { ctx.JSON(http.StatusUnauthorized, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, members) }
// ItemBoard gets a specific board, identified by project ID or // NAMESPACE/BOARD_NAME, which is owned by the authenticated user. func ItemBoard(ctx *middleware.Context) { board, err := models.ItemBoard(ctx.User, ctx.Provider, ctx.Query("project_id")) if err != nil { if err, ok := err.(models.ReceivedDataErr); ok { ctx.JSON(err.StatusCode, &models.ResponseError{ Success: false, Message: err.Error(), }) } ctx.JSON(http.StatusInternalServerError, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: board, }) }
// ListLabels gets a list of label on board accessible by the authenticated user. func ListLabels(ctx *middleware.Context) { labels, err := ctx.DataSource.ListLabels(ctx.Query("board_id")) if err != nil { ctx.JSON(http.StatusUnauthorized, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: labels, }) }
// DeleteCard closed an existing board card. func DeleteCard(ctx *middleware.Context, form models.CardRequest) { card, code, err := ctx.DataSource.DeleteCard(&form) if err != nil { ctx.JSON(code, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: card, }) ctx.Broadcast(card.RoutingKey(), &models.Response{ Data: card, Event: "card.delete", }) }
// UpdateCard updates an existing board card. func UpdateCard(ctx *middleware.Context, form models.CardRequest) { card, code, err := models.UpdateCard(ctx.User, ctx.Provider, &form) if err != nil { ctx.JSON(code, &models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, &models.Response{ Data: card, }) ctx.Broadcast(card.RoutingKey(), &models.Response{ Data: card, Event: "card.update", }) }
// OauthLogin logins with gitlab and get access token func OauthLogin(ctx *middleware.Context, form auth.Oauth2) { tok, err := models.Exchange(form.Provider, form.Code) if err != nil { log.Printf("%s", err.Error()) ctx.JSON(http.StatusBadRequest, models.ResponseError{ Success: false, Message: err.Error(), }) return } user, err := models.UserOauthSignIn(form.Provider, tok) if err != nil { log.Printf("%s", err.Error()) ctx.JSON(http.StatusBadRequest, models.ResponseError{ Success: false, Message: err.Error(), }) return } user, err = models.LoadByToken(user, ctx.Provider) if err != nil { log.Printf("%s", err.Error()) ctx.JSON(http.StatusBadRequest, models.ResponseError{ Success: false, Message: err.Error(), }) return } user.Username = fmt.Sprintf("%s_%s", user.Username, ctx.Provider) _, err = models.UpdateUser(user) // todo add validation by oauth provider if err != nil { user, err = models.CreateUser(user) } if err != nil { log.Printf("%s", err.Error()) ctx.JSON(http.StatusInternalServerError, models.ResponseError{ Success: false, Message: err.Error(), }) return } tokens, err := user.SignedString() if err != nil { log.Printf("%s", err.Error()) ctx.JSON(http.StatusBadRequest, models.ResponseError{ Success: false, Message: err.Error(), }) return } ctx.JSON(http.StatusOK, auth.ResponseAuth{ Success: true, Token: tokens, }) }
// OauthUrl redirects to url for authorisation func OauthUrl(ctx *middleware.Context) { ctx.Redirect(models.AuthCodeURL(ctx.Query("provider"))) }
// OauthHandler handles request from other services func OauthHandler(ctx *middleware.Context) { ctx.HTML(200, "templates/oauth") }