本文整理匯總了Golang中github.com/nerdzeu/nerdz-api/rest.IsGranted函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsGranted函數的具體用法?Golang IsGranted怎麽用?Golang IsGranted使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了IsGranted函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Pm
// Pm handles the request and returns the specified Private Message
func Pm() echo.HandlerFunc {
// swagger:route GET /me/pms/{other}/{pmid} user pms GetUserPm
//
// Update the speficied post on the specified user board
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: pms:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("pms:read", c) {
return rest.InvalidScopeResponse("pms:read", c)
}
pm := c.Get("pm").(*nerdz.Pm)
me := c.Get("me").(*nerdz.User)
return rest.SelectFields(pm.GetTO(me), c)
}
}
示例2: Whitelist
// Whitelist handles the request and returns the user whitelist
func Whitelist() echo.HandlerFunc {
// swagger:route GET /users/{id}/whitelist user whitelist GetWhitelist
//
// Show the whitelist of the specified user
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:read", c) {
return rest.InvalidScopeResponse("profile:read", c)
}
whitelist := c.Get("other").(*nerdz.User).Whitelist()
return rest.SelectFields(rest.GetUsersInfo(whitelist), c)
}
}
示例3: PostComment
// PostComment handles the request and returns the single comment required
func PostComment() echo.HandlerFunc {
// swagger:route GET /projects/{id}/posts/{pid}/comments/{cid} project post comment GetProjectPostComment
//
// Shows selected comment on specified post, filtered by some parameters.
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: project_comments:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_comments:read", c) {
return rest.InvalidScopeResponse("project_comments:read", c)
}
comment := c.Get("comment").(*nerdz.ProjectPostComment)
me := c.Get("me").(*nerdz.User)
return rest.SelectFields(comment.GetTO(me), c)
}
}
示例4: Followers
// Followers handles the request and returns the project followers
func Followers() echo.HandlerFunc {
// swagger:route GET /projects/{id}/followers project info followers getProjectFollowers
//
// Shows the followers informations for the specified project
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: projects:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("projects:read", c) {
return rest.InvalidScopeResponse("projects:read", c)
}
followers := c.Get("project").(*nerdz.Project).Followers()
return rest.SelectFields(rest.GetUsersInfo(followers), c)
}
}
示例5: Post
// Post handles the request and returns the single post required
func Post() echo.HandlerFunc {
// swagger:route GET /projects/{id}/posts/{pid} project post getProjectPost
//
// Shows selected posts with id pid on specified project board
//
// This will show the last comments on the post by default.
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: project_messages:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_messages:read", c) {
return rest.InvalidScopeResponse("project_messages:read", c)
}
me := c.Get("me").(*nerdz.User)
postTO := c.Get("post").(*nerdz.ProjectPost).GetTO(me)
return rest.SelectFields(postTO, c)
}
}
示例6: UserFollowing
// UserFollowing handles the request and returns the user following
func UserFollowing() echo.HandlerFunc {
// swagger:route GET /users/{id}/following/users user info following GetUserFollowing
//
// Shows the following informations for the specified user
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:read", c) {
return rest.InvalidScopeResponse("profile:read", c)
}
following := c.Get("other").(*nerdz.User).UserFollowing()
return rest.SelectFields(rest.GetUsersInfo(following), c)
}
}
示例7: Blacklisting
// Blacklisting handles the request and returns the user blacklisting
func Blacklisting() echo.HandlerFunc {
// swagger:route GET /users/{id}/blacklisting user blacklisting GetWhitelisting
//
// Show the user that placed the specified user in their blacklist
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:read", c) {
return rest.InvalidScopeResponse("profile:read", c)
}
blacklisting := c.Get("other").(*nerdz.User).Blacklisting()
return rest.SelectFields(rest.GetUsersInfo(blacklisting), c)
}
}
示例8: NewBlacklisted
// NewBlacklisted handles the request and creates and adds target user to current user whitelist
func NewBlacklisted() echo.HandlerFunc {
// swagger:route POST /me/whitelist/{target} user whitelist NewBlacklisted
//
// Adds target to the whitelist of the current user
//
// Produces:
// - application/json
//
// Consumes:
// - application/json
//
// Security:
// oauth: profile:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:write", c) {
return rest.InvalidScopeResponse("profile:write", c)
}
var target *nerdz.User
var err error
if target, err = rest.User("target", c); err != nil {
return err
}
// Read a rest.NewMessage from the body request.
message := rest.NewMessage{}
if err := c.Bind(&message); err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
me := c.Get("me").(*nerdz.User)
if err = me.BlacklistUser(target, message.Message); err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
// Return selected field from the followed User
return rest.SelectFields(target.GetTO(me), c)
}
}
示例9: NewPostCommentVote
// NewPostCommentVote handles the request and creates a new vote on the user comment post
func NewPostCommentVote() echo.HandlerFunc {
// swagger:route POST /projects/{id}/posts/{pid}/comments/{cid}votes project post comment vote NewProjectPostCommentVote
//
// Adds a new vote on the current project post comment
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: project_comments:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_comments:write", c) {
return rest.InvalidScopeResponse("project_comments:write", c)
}
// Read a rest.NewVote from the body request.
body := rest.NewVote{}
if err := c.Bind(&body); err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
// Send it
me := c.Get("me").(*nerdz.User)
comment := c.Get("comment").(*nerdz.ProjectPostComment)
vote, err := me.Vote(comment, body.Vote)
if err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
// Extract the TO from the new post and return
// selected fields.
return rest.SelectFields(vote.(*nerdz.ProjectPostCommentVote).GetTO(me), c)
}
}
示例10: DeletePostUserLock
// DeletePostUserLock handles the request and deletes the lock for the notification of the target user
// on the specified post
func DeletePostUserLock() echo.HandlerFunc {
// swagger:route DELETE /projects/{id}/posts/{pid}/locks/{target} project post vote DeleteProjectPostUserLock
//
// Deletes the lock for the notification of the target user on the specified post
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: project_messages:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_messages:write", c) {
return rest.InvalidScopeResponse("project_messages:write", c)
}
var target *nerdz.User
var err error
if target, err = rest.User("target", c); err != nil {
return err
}
me := c.Get("me").(*nerdz.User)
post := c.Get("post").(*nerdz.ProjectPost)
err = me.Unlock(post, target)
if err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
errstr := "Success"
c.JSON(http.StatusOK, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusOK,
Success: true,
})
return nil
}
}
示例11: DeleteConversation
// DeleteConversation handles the request and deletes the conversation
func DeleteConversation() echo.HandlerFunc {
// swagger:route DELETE /me/pms/{other} user pms DeleteUserPms
//
// Delete the conversation beteen the current user and other
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: pms:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("pms:write", c) {
return rest.InvalidScopeResponse("pms:write", c)
}
var other *nerdz.User
var err error
if other, err = rest.User("other", c); err != nil {
return err
}
me := c.Get("me").(*nerdz.User)
if err = me.DeleteConversation(other.ID()); err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
message := "Success"
c.JSON(http.StatusOK, &rest.Response{
Data: nil,
HumanMessage: message,
Message: message,
Status: http.StatusOK,
Success: true,
})
return nil
}
}
示例12: Posts
// Posts handles the request and returns the required posts written by the specified project
func Posts() echo.HandlerFunc {
// swagger:route GET /projects/{id}/posts project posts getProjectPosts
//
// List posts on project board, filtered by some parameters.
//
// This will show the last posts on the project board by default.
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: project_messages:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_messages:read", c) {
return rest.InvalidScopeResponse("project_messages:read", c)
}
project := c.Get("project").(*nerdz.Project)
options := c.Get("postlistOptions").(*nerdz.PostlistOptions)
options.Model = nerdz.ProjectPost{}
posts := project.Postlist(*options)
if posts == nil {
errstr := "Unable to fetch post list for the specified project"
c.JSON(http.StatusBadRequest, &rest.Response{
HumanMessage: errstr,
Message: "project.Postlist error",
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
me := c.Get("me").(*nerdz.User)
var postsAPI []*nerdz.PostTO
for _, p := range *posts {
// posts contains ExistingPost elements
// we need to convert back to a ProjectPost in order to get a correct PostTO
if projectPost := p.(*nerdz.ProjectPost); projectPost != nil {
postsAPI = append(postsAPI, projectPost.GetTO(me))
}
}
return rest.SelectFields(postsAPI, c)
}
}
示例13: Conversation
// Conversation handles the request and returns the user private conversation with the other user
func Conversation() echo.HandlerFunc {
// swagger:route GET /me/pms/{other} user post pms getUserConversation
//
// Returns the private conversation of the current user with the other user
//
// You can personalize the request via query string parameters
//
// Produces:
// - application/json
//
// Security:
// oauth: profile:read
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("pms:read", c) {
return rest.InvalidScopeResponse("pms:read", c)
}
var other *nerdz.User
var err error
if other, err = rest.User("other", c); err != nil {
return err
}
// fetch conversation between me and other
var conversation *[]nerdz.Pm
options := c.Get("pmsOptions").(*nerdz.PmsOptions)
me := c.Get("me").(*nerdz.User)
conversation, err = me.Pms(other.ID(), *options)
if err != nil {
errstr := "Unable to fetch conversation with the specified user"
c.JSON(http.StatusBadRequest, &rest.Response{
HumanMessage: errstr,
Message: "me.Conversation error",
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
var conversationTO []*nerdz.PmTO
for _, pm := range *conversation {
conversationTO = append(conversationTO, pm.GetTO(me))
}
return rest.SelectFields(conversationTO, c)
}
}
示例14: DeletePostLurk
// DeletePostLurk handles the request and deletes the lurk to the post
func DeletePostLurk() echo.HandlerFunc {
// swagger:route DELETE /projects/{id}/posts/{pid}/lurks project post vote DeleteProjectPostLurk
//
// Deletes the lurk on the current post
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// Security:
// oauth: project_messages:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("project_messages:write", c) {
return rest.InvalidScopeResponse("project_messages:write", c)
}
// Send it
me := c.Get("me").(*nerdz.User)
post := c.Get("post").(*nerdz.ProjectPost)
err := me.Unlurk(post)
if err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
errstr := "Success"
c.JSON(http.StatusOK, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusOK,
Success: true,
})
return nil
}
}
示例15: DeleteBlacklisted
// DeleteBlacklisted handles the request and deletes the target user from the current user whitelist
func DeleteBlacklisted() echo.HandlerFunc {
// swagger:route DELETE /me/following/users/{target} user blacklist DeleteBlacklisted
//
// Deletes target user from the current user blacklist
//
// Consumes:
// - application/json
//
// Security:
// oauth: profile:write
//
// Responses:
// default: apiResponse
return func(c echo.Context) error {
if !rest.IsGranted("profile:write", c) {
return rest.InvalidScopeResponse("profile:write", c)
}
var target *nerdz.User
var err error
if target, err = rest.User("target", c); err != nil {
return err
}
me := c.Get("me").(*nerdz.User)
if err = me.UnblacklistUser(target); err != nil {
errstr := err.Error()
c.JSON(http.StatusBadRequest, &rest.Response{
Data: nil,
HumanMessage: errstr,
Message: errstr,
Status: http.StatusBadRequest,
Success: false,
})
return errors.New(errstr)
}
message := "Success"
c.JSON(http.StatusOK, &rest.Response{
Data: nil,
HumanMessage: message,
Message: message,
Status: http.StatusOK,
Success: true,
})
return nil
}
}