Exemplo n.º 1
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{})
}
Exemplo n.º 2
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,
	})
}
Exemplo n.º 3
0
// 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,
	})
}
Exemplo n.º 4
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,
	})
}
Exemplo n.º 5
0
Arquivo: auth.go Projeto: kesyn/kanban
// 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,
	})
}
Exemplo n.º 6
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)
		}()
	}
}
Exemplo n.º 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,
	})
}
Exemplo n.º 8
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)
}
Exemplo n.º 9
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,
	})
}
Exemplo n.º 10
0
// 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,
	})
}
Exemplo n.º 11
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",
	})
}
Exemplo n.º 12
0
Arquivo: card.go Projeto: kesyn/kanban
// 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",
	})
}
Exemplo n.º 13
0
Arquivo: auth.go Projeto: kesyn/kanban
// 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,
	})
}
Exemplo n.º 14
0
Arquivo: auth.go Projeto: kesyn/kanban
// OauthUrl redirects to url for authorisation
func OauthUrl(ctx *middleware.Context) {
	ctx.Redirect(models.AuthCodeURL(ctx.Query("provider")))
}
Exemplo n.º 15
0
Arquivo: auth.go Projeto: kesyn/kanban
// OauthHandler handles request from other services
func OauthHandler(ctx *middleware.Context) {
	ctx.HTML(200, "templates/oauth")
}