mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 23:56:56 +00:00
GODT-1686: Add Label/Folder filtering to pmapi
This commit is contained in:
@ -24,6 +24,11 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/pmapi"
|
||||
)
|
||||
|
||||
const (
|
||||
route = "/labels"
|
||||
routeV4 = "/core/v4/labels"
|
||||
)
|
||||
|
||||
func (api *FakePMAPI) isLabelFolder(labelID string) bool {
|
||||
for _, label := range api.labels {
|
||||
if label.ID == labelID {
|
||||
@ -42,15 +47,51 @@ func (api *FakePMAPI) isLabelFolder(labelID string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) ListLabels(context.Context) ([]*pmapi.Label, error) {
|
||||
if err := api.checkAndRecordCall(GET, "/labels/1", nil); err != nil {
|
||||
func (api *FakePMAPI) ListLabels(ctx context.Context) ([]*pmapi.Label, error) {
|
||||
return api.listLabels(ctx, "1", route)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) CreateLabel(ctx context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||
return api.createLabel(ctx, label, route)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) UpdateLabel(ctx context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||
return api.updateLabel(ctx, label, route)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) DeleteLabel(ctx context.Context, labelID string) error {
|
||||
return api.deleteLabel(ctx, labelID, route)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) ListLabelsOnly(ctx context.Context) ([]*pmapi.Label, error) {
|
||||
return api.listLabels(ctx, "1", routeV4)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) ListFoldersOnly(ctx context.Context) ([]*pmapi.Label, error) {
|
||||
return api.listLabels(ctx, "3", routeV4)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) CreateLabelV4(ctx context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||
return api.createLabel(ctx, label, routeV4)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) UpdateLabelV4(ctx context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||
return api.updateLabel(ctx, label, routeV4)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) DeleteLabelV4(ctx context.Context, labelID string) error {
|
||||
return api.deleteLabel(ctx, labelID, routeV4)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) listLabels(_ context.Context, labeType string, route string) ([]*pmapi.Label, error) {
|
||||
if err := api.checkAndRecordCall(GET, route+"/"+labeType, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return api.labels, nil
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) CreateLabel(_ context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||
if err := api.checkAndRecordCall(POST, "/labels", &pmapi.LabelReq{Label: label}); err != nil {
|
||||
func (api *FakePMAPI) createLabel(_ context.Context, label *pmapi.Label, route string) (*pmapi.Label, error) {
|
||||
if err := api.checkAndRecordCall(POST, route, &pmapi.LabelReq{Label: label}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, existingLabel := range api.labels {
|
||||
@ -71,8 +112,8 @@ func (api *FakePMAPI) CreateLabel(_ context.Context, label *pmapi.Label) (*pmapi
|
||||
return label, nil
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) UpdateLabel(_ context.Context, label *pmapi.Label) (*pmapi.Label, error) {
|
||||
if err := api.checkAndRecordCall(PUT, "/labels", &pmapi.LabelReq{Label: label}); err != nil {
|
||||
func (api *FakePMAPI) updateLabel(_ context.Context, label *pmapi.Label, route string) (*pmapi.Label, error) {
|
||||
if err := api.checkAndRecordCall(PUT, route, &pmapi.LabelReq{Label: label}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for idx, existingLabel := range api.labels {
|
||||
@ -91,8 +132,8 @@ func (api *FakePMAPI) UpdateLabel(_ context.Context, label *pmapi.Label) (*pmapi
|
||||
return nil, fmt.Errorf("label %s does not exist", label.ID)
|
||||
}
|
||||
|
||||
func (api *FakePMAPI) DeleteLabel(_ context.Context, labelID string) error {
|
||||
if err := api.checkAndRecordCall(DELETE, "/labels/"+labelID, nil); err != nil {
|
||||
func (api *FakePMAPI) deleteLabel(_ context.Context, labelID string, route string) error {
|
||||
if err := api.checkAndRecordCall(DELETE, route+labelID, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
for idx, existingLabel := range api.labels {
|
||||
|
||||
@ -57,7 +57,7 @@ func thereIsUserWithMailbox(bddUserID, mailboxName string) error {
|
||||
}
|
||||
err := ctx.GetPMAPIController().AddUserLabel(account.Username(), &pmapi.Label{
|
||||
Name: mailboxName,
|
||||
Type: pmapi.LabelTypeMailbox,
|
||||
Type: pmapi.LabelTypeMailBox,
|
||||
})
|
||||
if err != nil {
|
||||
return internalError(err, "adding label %s for %s", mailboxName, account.Username())
|
||||
|
||||
Reference in New Issue
Block a user