MSP-247 add role check to get_profile
This commit is contained in:
1 parent
23c6b16a7c
commit
e2549ebffe
1 file changed
+11
-2
+11
-2
@@ -1,11 +1,11 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/integration-system/isp-lib/v2/config"
|
"github.com/integration-system/isp-lib/v2/config"
|
||||||
"github.com/integration-system/isp-lib/v2/utils"
|
"github.com/integration-system/isp-lib/v2/utils"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
@@ -58,8 +58,17 @@ func GetProfile(metadata metadata.MD) (*structure.AdminUserShort, error) {
|
|||||||
|
|
||||||
user, err := model.GetUserById(userId)
|
user, err := model.GetUserById(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.WithMessagef(err, "get user by id %d", userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
role, err := model.RoleRep.GetRoleById(user.RoleId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessagef(err, "get role by id %d", user.RoleId)
|
||||||
|
}
|
||||||
|
if role == nil {
|
||||||
|
return nil, errors.Errorf("unexpected role id %d", user.RoleId)
|
||||||
|
}
|
||||||
|
|
||||||
return &structure.AdminUserShort{
|
return &structure.AdminUserShort{
|
||||||
Image: user.Image,
|
Image: user.Image,
|
||||||
FirstName: user.FirstName,
|
FirstName: user.FirstName,
|
||||||
|
|||||||
Reference in new issue
Block a user