Beispiel #1
0
// 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)
		}()
	}
}
Beispiel #2
0
// 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)
}
Beispiel #3
0
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{})
}
Beispiel #4
0
// ListLabels gets a list of label on board accessible by the authenticated user.
func ListLabels(ctx *middleware.Context) {
	labels, err := models.ListLabels(ctx.User, ctx.Provider, 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,
	})
}
Beispiel #5
0
// 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,
	})
}
Beispiel #6
0
// 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,
	})
}
Beispiel #7
0
// 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,
	})
}
Beispiel #8
0
// ListBoards gets a list of board accessible by the authenticated user.
func ListBoards(ctx *middleware.Context) {
	boards, err := ctx.DataSource.ListBoards()

	if err != nil {
		ctx.JSON(http.StatusUnauthorized, &models.ResponseError{
			Success: false,
			Message: err.Error(),
		})
		return
	}

	ctx.JSON(http.StatusOK, &models.Response{
		Data: boards,
	})
}
Beispiel #9
0
// 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,
	})
}
Beispiel #10
0
// 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",
	})
}
Beispiel #11
0
// 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",
	})
}
Beispiel #12
0
// 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,
	})
}
Beispiel #13
0
// 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,
	})
}