Skip to content

Commit

Permalink
Merge pull request #6 from containerum/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MargoTuleninova authored Aug 17, 2018
2 parents 60e09f0 + 7af7a6f commit 9dc62b5
Show file tree
Hide file tree
Showing 30 changed files with 230 additions and 156 deletions.
2 changes: 1 addition & 1 deletion pkg/clients/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"time"

cherry "git.containerum.net/ch/user-manager/pkg/umErrors"
cherry "git.containerum.net/ch/user-manager/pkg/umerrors"
"github.com/json-iterator/go"
"gopkg.in/resty.v1"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/clients/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *httpPermissionsClient) GetUserAccess(ctx context.Context, user *db.User
func (c *httpPermissionsClient) DeleteUserNamespaces(ctx context.Context, user *db.User) error {
c.log.WithField("user_id", user.ID).Info("Deleting user namespaces")
headersMap := utils.RequestHeadersMap(ctx)
headersMap[headers.UserIDXHeader] = user.ID
headersMap["X-User-Id"] = user.ID
headersMap[headers.UserRoleXHeader] = user.Role
resp, err := c.rest.R().SetContext(ctx).
SetResult(authProto.ResourcesAccess{}).
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type DB interface {

GetGroup(ctx context.Context, groupID string) (*UserGroup, error)
GetGroupMembers(ctx context.Context, groupID string) ([]UserGroupMember, error)
GetUserGroupsIDsAccesses(ctx context.Context, userID string) (map[string]string, error)
GetUserGroupsIDsAccesses(ctx context.Context, userID string, isAdmin bool) (map[string]string, error)
GetGroupListLabelID(ctx context.Context, ids []string) ([]UserGroup, error)
GetGroupListByIDs(ctx context.Context, ids []string) ([]UserGroup, error)
CreateGroup(ctx context.Context, group *UserGroup) error
Expand Down
10 changes: 8 additions & 2 deletions pkg/db/postgres/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ func (pgdb *pgDB) GetGroupMembers(ctx context.Context, groupID string) ([]db.Use
return resp, err
}

func (pgdb *pgDB) GetUserGroupsIDsAccesses(ctx context.Context, userID string) (map[string]string, error) {
func (pgdb *pgDB) GetUserGroupsIDsAccesses(ctx context.Context, userID string, isAdmin bool) (map[string]string, error) {
pgdb.log.Infoln("Get users groups", userID)
resp := make(map[string]string)

rows, err := pgdb.qLog.QueryxContext(ctx, "SELECT group_id, default_access FROM groups_members WHERE user_id = $1", userID)
var rows *sqlx.Rows
var err error
if isAdmin {
rows, err = pgdb.qLog.QueryxContext(ctx, "SELECT group_id, default_access FROM groups_members")
} else {
rows, err = pgdb.qLog.QueryxContext(ctx, "SELECT group_id, default_access FROM groups_members WHERE user_id = $1", userID)
}
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/router/handlers/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"git.containerum.net/ch/user-manager/pkg/models"
m "git.containerum.net/ch/user-manager/pkg/router/middleware"
"git.containerum.net/ch/user-manager/pkg/server"
"git.containerum.net/ch/user-manager/pkg/umErrors"
"git.containerum.net/ch/user-manager/pkg/umerrors"
"git.containerum.net/ch/user-manager/pkg/validation"
"github.com/containerum/cherry"
"github.com/containerum/cherry/adaptors/gonic"
Expand Down Expand Up @@ -38,7 +38,7 @@ func GetBoundAccountsHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableGetUserInfo(), ctx)
gonic.Gonic(umerrors.ErrUnableGetUserInfo(), ctx)
}
return
}
Expand Down Expand Up @@ -68,12 +68,12 @@ func AddBoundAccountHandler(ctx *gin.Context) {

var request models.OAuthLoginRequest
if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

if errs := validation.ValidateOAuthLoginRequest(request); errs != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(errs...), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(errs...), ctx)
return
}

Expand All @@ -83,7 +83,7 @@ func AddBoundAccountHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableBindAccount(), ctx)
gonic.Gonic(umerrors.ErrUnableBindAccount(), ctx)
}
return
}
Expand Down Expand Up @@ -114,12 +114,12 @@ func DeleteBoundAccountHandler(ctx *gin.Context) {

var request models.BoundAccountDeleteRequest
if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

if errs := validation.ValidateResource(request); errs != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(errs...), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(errs...), ctx)
return
}

Expand All @@ -129,7 +129,7 @@ func DeleteBoundAccountHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableUnbindAccount(), ctx)
gonic.Gonic(umerrors.ErrUnableUnbindAccount(), ctx)
}
return
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/router/handlers/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"git.containerum.net/ch/user-manager/pkg/models"
m "git.containerum.net/ch/user-manager/pkg/router/middleware"
"git.containerum.net/ch/user-manager/pkg/server"
"git.containerum.net/ch/user-manager/pkg/umErrors"
"git.containerum.net/ch/user-manager/pkg/umerrors"
"git.containerum.net/ch/user-manager/pkg/validation"
"github.com/containerum/cherry"
"github.com/containerum/cherry/adaptors/gonic"
Expand Down Expand Up @@ -38,13 +38,13 @@ func AdminUserCreateHandler(ctx *gin.Context) {

var request models.UserLogin
if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

errs := validation.ValidateUserLogin(request)
if errs != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(errs...), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(errs...), ctx)
return
}

Expand All @@ -54,7 +54,7 @@ func AdminUserCreateHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableCreateUser(), ctx)
gonic.Gonic(umerrors.ErrUnableCreateUser(), ctx)
}
return
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func AdminUserActivateHandler(ctx *gin.Context) {

var request models.UserLogin
if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

Expand All @@ -93,7 +93,7 @@ func AdminUserActivateHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableDeleteUser(), ctx)
gonic.Gonic(umerrors.ErrUnableDeleteUser(), ctx)
}
return
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func AdminUserDeactivateHandler(ctx *gin.Context) {
var request models.UserLogin

if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

Expand All @@ -134,7 +134,7 @@ func AdminUserDeactivateHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableDeleteUser(), ctx)
gonic.Gonic(umerrors.ErrUnableDeleteUser(), ctx)
}
return
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func AdminSetAdminHandler(ctx *gin.Context) {
var request models.UserLogin

if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

Expand All @@ -175,7 +175,7 @@ func AdminSetAdminHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableDeleteUser(), ctx)
gonic.Gonic(umerrors.ErrUnableDeleteUser(), ctx)
}
return
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func AdminUnsetAdminHandler(ctx *gin.Context) {
var request models.UserLogin

if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

Expand All @@ -216,7 +216,7 @@ func AdminUnsetAdminHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableDeleteUser(), ctx)
gonic.Gonic(umerrors.ErrUnableDeleteUser(), ctx)
}
return
}
Expand Down Expand Up @@ -249,7 +249,7 @@ func AdminResetPasswordHandler(ctx *gin.Context) {
var request models.UserLogin

if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

Expand All @@ -259,7 +259,7 @@ func AdminResetPasswordHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableDeleteUser(), ctx)
gonic.Gonic(umerrors.ErrUnableDeleteUser(), ctx)
}
return
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/router/handlers/domain_blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"git.containerum.net/ch/user-manager/pkg/models"
m "git.containerum.net/ch/user-manager/pkg/router/middleware"
"git.containerum.net/ch/user-manager/pkg/server"
"git.containerum.net/ch/user-manager/pkg/umErrors"
"git.containerum.net/ch/user-manager/pkg/umerrors"
"git.containerum.net/ch/user-manager/pkg/validation"
"github.com/containerum/cherry"
"github.com/containerum/cherry/adaptors/gonic"
Expand Down Expand Up @@ -38,7 +38,7 @@ func BlacklistDomainsListGetHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableGetDomainBlacklist(), ctx)
gonic.Gonic(umerrors.ErrUnableGetDomainBlacklist(), ctx)
}
return
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func BlacklistDomainGetHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableGetDomainBlacklist(), ctx)
gonic.Gonic(umerrors.ErrUnableGetDomainBlacklist(), ctx)
}
return
}
Expand Down Expand Up @@ -104,13 +104,13 @@ func BlacklistDomainAddHandler(ctx *gin.Context) {

var request models.Domain
if err := ctx.ShouldBindWith(&request, binding.JSON); err != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(err), ctx)
return
}

errs := validation.ValidateDomain(request)
if errs != nil {
gonic.Gonic(umErrors.ErrRequestValidationFailed().AddDetailsErr(errs...), ctx)
gonic.Gonic(umerrors.ErrRequestValidationFailed().AddDetailsErr(errs...), ctx)
return
}

Expand All @@ -120,7 +120,7 @@ func BlacklistDomainAddHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableBlacklistDomain(), ctx)
gonic.Gonic(umerrors.ErrUnableBlacklistDomain(), ctx)
}
return
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func BlacklistDomainDeleteHandler(ctx *gin.Context) {
gonic.Gonic(cherr, ctx)
} else {
ctx.Error(err)
gonic.Gonic(umErrors.ErrUnableUnblacklistDomain(), ctx)
gonic.Gonic(umerrors.ErrUnableUnblacklistDomain(), ctx)
}
return
}
Expand Down
Loading

0 comments on commit 9dc62b5

Please sign in to comment.