implement rules checking for orgnz, addr and contact creation and update
This commit is contained in:
@@ -133,6 +133,15 @@ func (c *controller) handleParent(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
organization, err := c.svc.Organization.GetByUUID(orgUUID, authUser)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if !authorization.CanUpdateOrganization(authUser, organization){
|
||||
return routeutils.ResponseAPIAuthorizationError(ctx)
|
||||
}
|
||||
|
||||
resp, err := c.svc.Organization.SetParentOrganization(orgUUID, parent.UUID, authUser)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
@@ -158,6 +167,15 @@ func (c *controller) handleChild(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
organization, err := c.svc.Organization.GetByUUID(orgUUID, authUser)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if !authorization.CanUpdateOrganization(authUser, organization){
|
||||
return routeutils.ResponseAPIAuthorizationError(ctx)
|
||||
}
|
||||
|
||||
_, err = c.svc.Organization.SetParentOrganization(child.UUID, orgUUID, authUser)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
@@ -221,10 +239,6 @@ func (c *controller) handleRemoveAddress(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if !authorization.CanDeleteAddress(authUser, address) {
|
||||
return routeutils.ResponseAPIAuthorizationError(ctx)
|
||||
}
|
||||
|
||||
address.UpdatedUser.ID = authUser.ID
|
||||
|
||||
err = c.svc.Organization.InactivateOrganizationAddress(orgUUID, address, authUser)
|
||||
@@ -257,10 +271,17 @@ func (c *controller) handleAddAddress(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if !authorization.CanCreateAddress(authUser, address) {
|
||||
organization, err := c.svc.Organization.GetByUUID(orgUUID, authUser)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if !authorization.CanCreateAddress(authUser, organization) {
|
||||
return routeutils.ResponseAPIAuthorizationError(ctx)
|
||||
}
|
||||
|
||||
return routeutils.ResponseAPIAuthorizationError(ctx)
|
||||
|
||||
address.CreatedUser.ID = authUser.ID
|
||||
address.UpdatedUser.ID = authUser.ID
|
||||
|
||||
@@ -294,10 +315,6 @@ func (c *controller) handleRemoveContact(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if !authorization.CanDeleteContact(authUser, contact) {
|
||||
return routeutils.ResponseAPIAuthorizationError(ctx)
|
||||
}
|
||||
|
||||
contact.UpdatedUser.ID = authUser.ID
|
||||
|
||||
err = c.svc.Organization.InactivateOrganizationContact(orgUUID, contact, authUser)
|
||||
@@ -330,7 +347,12 @@ func (c *controller) handleAddContact(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if !authorization.CanCreateContact(authUser, contact) {
|
||||
organization, err := c.svc.Organization.GetByUUID(orgUUID, authUser)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if !authorization.CanCreateContact(authUser, organization) {
|
||||
return routeutils.ResponseAPIAuthorizationError(ctx)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user