NewContextWithAuthorization returns a context with user authorization info. This function should only be called when one need authorization information for api caller.
(c *gin.Context)
| 135 | // NewContextWithAuthorization returns a context with user authorization info. |
| 136 | // This function should only be called when one need authorization information for api caller. |
| 137 | func NewContextWithAuthorization(c *gin.Context) (*Context, error) { |
| 138 | logger := ginzap.WithContext(c).Sugar() |
| 139 | var resourceAuthInfo *user.AuthorizedResources |
| 140 | var err error |
| 141 | resp := NewContext(c) |
| 142 | // there is a case where the request does not have token (system call), in this case we will have admin access |
| 143 | resourceAuthInfo, err = user.New().GetUserAuthInfo(resp.UserID) |
| 144 | if err != nil { |
| 145 | logger.Errorf("failed to generate user authorization info, error: %s", err) |
| 146 | return resp, err |
| 147 | } |
| 148 | resp.Resources = resourceAuthInfo |
| 149 | return resp, nil |
| 150 | } |
| 151 | |
| 152 | func NewBackgroupContext() *Context { |
| 153 | return &Context{ |
nothing calls this directly
no test coverage detected