Skip to content

Commit

Permalink
remove new changes in api
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Sep 10, 2024
1 parent 3b61fc6 commit 56b489d
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 1,665 deletions.
13 changes: 5 additions & 8 deletions api/controller/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ import (
"github.com/moira-alert/moira/database"
)

var (
// errNotAllowedContactType means that this type of contact is not allowed to be created.
errNotAllowedContactType = errors.New("cannot create contact with not allowed contact type")
errNotPermittedStr = "you are not permitted"
)
// ErrNotAllowedContactType means that this type of contact is not allowed to be created.
var ErrNotAllowedContactType = errors.New("cannot create contact with not allowed contact type")

// GetAllContacts gets all moira contacts.
func GetAllContacts(database moira.Database) (*dto.ContactList, *api.ErrorResponse) {
Expand Down Expand Up @@ -61,7 +58,7 @@ func CreateContact(
teamID string,
) *api.ErrorResponse {
if !isAllowedToUseContactType(auth, userLogin, contact.Type) {
return api.ErrorInvalidRequest(errNotAllowedContactType)
return api.ErrorInvalidRequest(ErrNotAllowedContactType)
}

// Only admins are allowed to create contacts for other users
Expand Down Expand Up @@ -110,7 +107,7 @@ func UpdateContact(
contactData moira.ContactData,
) (dto.Contact, *api.ErrorResponse) {
if !isAllowedToUseContactType(auth, contactDTO.User, contactDTO.Type) {
return contactDTO, api.ErrorInvalidRequest(errNotAllowedContactType)
return contactDTO, api.ErrorInvalidRequest(ErrNotAllowedContactType)
}

contactData.Type = contactDTO.Type
Expand Down Expand Up @@ -247,7 +244,7 @@ func CheckUserPermissionsForContact(
return contactData, nil
}

return moira.ContactData{}, api.ErrorForbidden(errNotPermittedStr)
return moira.ContactData{}, api.ErrorForbidden("you are not permitted")
}

func isContactExists(dataBase moira.Database, contactID string) (bool, error) {
Expand Down
6 changes: 3 additions & 3 deletions api/controller/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestCreateContact(t *testing.T) {
Value: contactValue,
Type: notAllowedContactType,
}
expectedErr := api.ErrorInvalidRequest(errNotAllowedContactType)
expectedErr := api.ErrorInvalidRequest(ErrNotAllowedContactType)
err := CreateContact(dataBase, auth, contact, userLogin, "")
So(err, ShouldResemble, expectedErr)
})
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestCreateContact(t *testing.T) {
Value: contactValue,
Type: notAllowedContactType,
}
expectedErr := api.ErrorInvalidRequest(errNotAllowedContactType)
expectedErr := api.ErrorInvalidRequest(ErrNotAllowedContactType)
err := CreateContact(dataBase, auth, contact, "", teamID)
So(err, ShouldResemble, expectedErr)
})
Expand Down Expand Up @@ -524,7 +524,7 @@ func TestUpdateContact(t *testing.T) {
Value: contactValue,
Type: notAllowedContactType,
}
expectedErr := api.ErrorInvalidRequest(errNotAllowedContactType)
expectedErr := api.ErrorInvalidRequest(ErrNotAllowedContactType)
contactID := uuid.Must(uuid.NewV4()).String()
expectedContact, err := UpdateContact(dataBase, auth, contactDTO, moira.ContactData{ID: contactID, User: userLogin})
So(err, ShouldResemble, expectedErr)
Expand Down
115 changes: 0 additions & 115 deletions api/controller/emergency_contact.go

This file was deleted.

Loading

0 comments on commit 56b489d

Please sign in to comment.