|
@@ -111,13 +111,8 @@ func inviteExistingUserToOrg(c *middleware.Context, user *m.User, inviteDto *dto
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func RevokeInvite(c *middleware.Context) Response {
|
|
func RevokeInvite(c *middleware.Context) Response {
|
|
|
- cmd := m.UpdateTempUserStatusCommand{
|
|
|
|
|
- Code: c.Params(":code"),
|
|
|
|
|
- Status: m.TmpUserRevoked,
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if err := bus.Dispatch(&cmd); err != nil {
|
|
|
|
|
- return ApiError(500, "Failed to update invite status", err)
|
|
|
|
|
|
|
+ if ok, rsp := updateTempUserStatus(c.Params(":code"), m.TmpUserRevoked); !ok {
|
|
|
|
|
+ return rsp
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return ApiSuccess("Invite revoked")
|
|
return ApiSuccess("Invite revoked")
|
|
@@ -169,36 +164,55 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
|
|
|
return ApiError(500, "failed to create user", err)
|
|
return ApiError(500, "failed to create user", err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- user := cmd.Result
|
|
|
|
|
|
|
+ user := &cmd.Result
|
|
|
|
|
|
|
|
bus.Publish(&events.SignUpCompleted{
|
|
bus.Publish(&events.SignUpCompleted{
|
|
|
Name: user.NameOrFallback(),
|
|
Name: user.NameOrFallback(),
|
|
|
Email: user.Email,
|
|
Email: user.Email,
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ if ok, rsp := applyUserInvite(user, invite, true); !ok {
|
|
|
|
|
+ return rsp
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ loginUserWithUser(user, c)
|
|
|
|
|
+
|
|
|
|
|
+ metrics.M_Api_User_SignUpCompleted.Inc(1)
|
|
|
|
|
+ metrics.M_Api_User_SignUpInvite.Inc(1)
|
|
|
|
|
+
|
|
|
|
|
+ return ApiSuccess("User created and logged in")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func updateTempUserStatus(code string, status m.TempUserStatus) (bool, Response) {
|
|
|
|
|
+ // update temp user status
|
|
|
|
|
+ updateTmpUserCmd := m.UpdateTempUserStatusCommand{Code: code, Status: status}
|
|
|
|
|
+ if err := bus.Dispatch(&updateTmpUserCmd); err != nil {
|
|
|
|
|
+ return false, ApiError(500, "Failed to update invite status", err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true, nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func applyUserInvite(user *m.User, invite *m.TempUserDTO, setActive bool) (bool, Response) {
|
|
|
// add to org
|
|
// add to org
|
|
|
addOrgUserCmd := m.AddOrgUserCommand{OrgId: invite.OrgId, UserId: user.Id, Role: invite.Role}
|
|
addOrgUserCmd := m.AddOrgUserCommand{OrgId: invite.OrgId, UserId: user.Id, Role: invite.Role}
|
|
|
if err := bus.Dispatch(&addOrgUserCmd); err != nil {
|
|
if err := bus.Dispatch(&addOrgUserCmd); err != nil {
|
|
|
if err != m.ErrOrgUserAlreadyAdded {
|
|
if err != m.ErrOrgUserAlreadyAdded {
|
|
|
- return ApiError(500, "Error while trying to create org user", err)
|
|
|
|
|
|
|
+ return false, ApiError(500, "Error while trying to create org user", err)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // set org to active
|
|
|
|
|
- if err := bus.Dispatch(&m.SetUsingOrgCommand{OrgId: invite.OrgId, UserId: user.Id}); err != nil {
|
|
|
|
|
- return ApiError(500, "Failed to set org as active", err)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// update temp user status
|
|
// update temp user status
|
|
|
- updateTmpUserCmd := m.UpdateTempUserStatusCommand{Code: invite.Code, Status: m.TmpUserCompleted}
|
|
|
|
|
- if err := bus.Dispatch(&updateTmpUserCmd); err != nil {
|
|
|
|
|
- return ApiError(500, "Failed to update invite status", err)
|
|
|
|
|
|
|
+ if ok, rsp := updateTempUserStatus(invite.Code, m.TmpUserCompleted); !ok {
|
|
|
|
|
+ return false, rsp
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- loginUserWithUser(&user, c)
|
|
|
|
|
-
|
|
|
|
|
- metrics.M_Api_User_SignUpCompleted.Inc(1)
|
|
|
|
|
- metrics.M_Api_User_SignUpInvite.Inc(1)
|
|
|
|
|
|
|
+ if setActive {
|
|
|
|
|
+ // set org to active
|
|
|
|
|
+ if err := bus.Dispatch(&m.SetUsingOrgCommand{OrgId: invite.OrgId, UserId: user.Id}); err != nil {
|
|
|
|
|
+ return false, ApiError(500, "Failed to set org as active", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return ApiSuccess("User created and logged in")
|
|
|
|
|
|
|
+ return true, nil
|
|
|
}
|
|
}
|