fix(): Check Organization exists before User is added (#5302)

Commit adds a check whether Organization exists before User is added to
the organization.

Fixes #3151.
This commit is contained in:
Zdenek Styblik 2016-06-08 05:46:21 +02:00 committed by Torkel Ödegaard
parent 67ad903556
commit 5eceabf810
2 changed files with 8 additions and 1 deletions

View File

@ -219,7 +219,8 @@ func (a *ldapAuther) syncOrgRoles(user *m.User, ldapUser *ldapUserInfo) error {
// add role
cmd := m.AddOrgUserCommand{UserId: user.Id, Role: group.OrgRole, OrgId: group.OrgId}
if err := bus.Dispatch(&cmd); err != nil {
err := bus.Dispatch(&cmd)
if err != nil && err != m.ErrOrgNotFound {
return err
}

View File

@ -26,6 +26,12 @@ func AddOrgUser(cmd *m.AddOrgUserCommand) error {
return m.ErrOrgUserAlreadyAdded
}
if res, err := sess.Query("SELECT 1 from org WHERE id=?", cmd.OrgId); err != nil {
return err
} else if len(res) != 1 {
return m.ErrOrgNotFound
}
entity := m.OrgUser{
OrgId: cmd.OrgId,
UserId: cmd.UserId,