Skip to content

Commit

Permalink
Merge pull request #1013 from gobitfly/BEDS-841/Cannot_configure_lega…
Browse files Browse the repository at this point in the history
…cy_connected_devices

Changed device identifier to id
  • Loading branch information
Eisei24 authored Oct 22, 2024
2 parents 312c003 + 18aecaa commit cd7d7b8
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,10 @@ func (d *DummyService) UpdateNotificationSettingsGeneral(ctx context.Context, us
func (d *DummyService) UpdateNotificationSettingsNetworks(ctx context.Context, userId uint64, chainId uint64, settings t.NotificationSettingsNetwork) error {
return nil
}
func (d *DummyService) UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string, name string, IsNotificationsEnabled bool) error {
func (d *DummyService) UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64, name string, IsNotificationsEnabled bool) error {
return nil
}
func (d *DummyService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error {
func (d *DummyService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64) error {
return nil
}

Expand Down
30 changes: 15 additions & 15 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type NotificationsRepository interface {
GetNotificationSettingsDefaultValues(ctx context.Context) (*t.NotificationSettingsDefaultValues, error)
UpdateNotificationSettingsGeneral(ctx context.Context, userId uint64, settings t.NotificationSettingsGeneral) error
UpdateNotificationSettingsNetworks(ctx context.Context, userId uint64, chainId uint64, settings t.NotificationSettingsNetwork) error
UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string, name string, IsNotificationsEnabled bool) error
DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error
UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64, name string, IsNotificationsEnabled bool) error
DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64) error
UpdateNotificationSettingsClients(ctx context.Context, userId uint64, clientId uint64, IsSubscribed bool) (*t.NotificationSettingsClient, error)
GetNotificationSettingsDashboards(ctx context.Context, userId uint64, cursor string, colSort t.Sort[enums.NotificationSettingsDashboardColumn], search string, limit uint64) ([]t.NotificationSettingsDashboardsTableRow, *t.Paging, error)
UpdateNotificationSettingsValidatorDashboard(ctx context.Context, userId uint64, dashboardId t.VDBIdPrimary, groupId uint64, settings t.NotificationSettingsValidatorDashboard) error
Expand Down Expand Up @@ -1325,20 +1325,20 @@ func (d *DataAccessService) GetNotificationSettings(ctx context.Context, userId
// -------------------------------------
// Get the paired devices
pairedDevices := []struct {
DeviceIdentifier sql.NullString `db:"device_identifier"`
CreatedTs time.Time `db:"created_ts"`
DeviceName string `db:"device_name"`
NotifyEnabled bool `db:"notify_enabled"`
DeviceId uint64 `db:"id"`
CreatedTs time.Time `db:"created_ts"`
DeviceName string `db:"device_name"`
NotifyEnabled bool `db:"notify_enabled"`
}{}
wg.Go(func() error {
err := d.userReader.SelectContext(ctx, &pairedDevices, `
SELECT
device_identifier,
id,
created_ts,
device_name,
COALESCE(notify_enabled, false) AS notify_enabled
FROM users_devices
WHERE user_id = $1 AND device_identifier IS NOT NULL`, userId)
WHERE user_id = $1`, userId)
if err != nil {
return fmt.Errorf(`error retrieving data for notifications paired devices: %w`, err)
}
Expand Down Expand Up @@ -1429,7 +1429,7 @@ func (d *DataAccessService) GetNotificationSettings(ctx context.Context, userId

for _, device := range pairedDevices {
result.PairedDevices = append(result.PairedDevices, t.NotificationPairedDevice{
Id: device.DeviceIdentifier.String,
Id: device.DeviceId,
PairedTimestamp: device.CreatedTs.Unix(),
Name: device.DeviceName,
IsNotificationsEnabled: device.NotifyEnabled,
Expand Down Expand Up @@ -1642,13 +1642,13 @@ func (d *DataAccessService) UpdateNotificationSettingsNetworks(ctx context.Conte
}
return nil
}
func (d *DataAccessService) UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string, name string, IsNotificationsEnabled bool) error {
func (d *DataAccessService) UpdateNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64, name string, IsNotificationsEnabled bool) error {
result, err := d.userWriter.ExecContext(ctx, `
UPDATE users_devices
SET
device_name = $1,
notify_enabled = $2
WHERE user_id = $3 AND device_identifier = $4`,
WHERE user_id = $3 AND id = $4`,
name, IsNotificationsEnabled, userId, pairedDeviceId)
if err != nil {
return err
Expand All @@ -1660,14 +1660,14 @@ func (d *DataAccessService) UpdateNotificationSettingsPairedDevice(ctx context.C
return err
}
if rowsAffected == 0 {
return fmt.Errorf("device with id %s to update notification settings not found", pairedDeviceId)
return fmt.Errorf("device with id %v to update notification settings not found", pairedDeviceId)
}
return nil
}
func (d *DataAccessService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId string) error {
func (d *DataAccessService) DeleteNotificationSettingsPairedDevice(ctx context.Context, userId uint64, pairedDeviceId uint64) error {
result, err := d.userWriter.ExecContext(ctx, `
DELETE FROM users_devices
WHERE user_id = $1 AND device_identifier = $2`,
WHERE user_id = $1 AND id = $2`,
userId, pairedDeviceId)
if err != nil {
return err
Expand All @@ -1679,7 +1679,7 @@ func (d *DataAccessService) DeleteNotificationSettingsPairedDevice(ctx context.C
return err
}
if rowsAffected == 0 {
return fmt.Errorf("device with id %s to delete not found", pairedDeviceId)
return fmt.Errorf("device with id %v to delete not found", pairedDeviceId)
}
return nil
}
Expand Down
1 change: 0 additions & 1 deletion backend/pkg/api/handlers/input_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var (
reEthereumAddress = regexp.MustCompile(`^(0x)?[0-9a-fA-F]{40}$`)
reWithdrawalCredential = regexp.MustCompile(`^(0x0[01])?[0-9a-fA-F]{62}$`)
reEnsName = regexp.MustCompile(`^.+\.eth$`)
reNonEmpty = regexp.MustCompile(`^\s*\S.*$`)
reGraffiti = regexp.MustCompile(`^.{2,}$`) // at least 2 characters, so that queries won't time out
reCursor = regexp.MustCompile(`^[A-Za-z0-9-_]+$`) // has to be base64
reEmail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/api/handlers/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -2345,7 +2345,7 @@ func (h *HandlerService) PublicPutUserNotificationSettingsPairedDevices(w http.R
return
}
// TODO use a better way to validate the paired device id
pairedDeviceId := v.checkRegex(reNonEmpty, mux.Vars(r)["paired_device_id"], "paired_device_id")
pairedDeviceId := v.checkUint(mux.Vars(r)["paired_device_id"], "paired_device_id")
name := v.checkNameNotEmpty(req.Name)
if v.hasErrors() {
handleErr(w, r, v)
Expand Down Expand Up @@ -2386,7 +2386,7 @@ func (h *HandlerService) PublicDeleteUserNotificationSettingsPairedDevices(w htt
return
}
// TODO use a better way to validate the paired device id
pairedDeviceId := v.checkRegex(reNonEmpty, mux.Vars(r)["paired_device_id"], "paired_device_id")
pairedDeviceId := v.checkUint(mux.Vars(r)["paired_device_id"], "paired_device_id")
if v.hasErrors() {
handleErr(w, r, v)
return
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/api/types/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type NotificationNetwork struct {
type InternalPutUserNotificationSettingsNetworksResponse ApiDataResponse[NotificationNetwork]

type NotificationPairedDevice struct {
Id string `json:"id"`
Id uint64 `json:"id"`
PairedTimestamp int64 `json:"paired_timestamp"`
Name string `json:"name,omitempty"`
IsNotificationsEnabled bool `json:"is_notifications_enabled"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const props = defineProps<{
}>()
const emit = defineEmits<{
(e: 'remove-device', id: string): void,
(e: 'remove-device', id: number): void,
(e: 'toggle-notifications', {
id,
value,
}: {
id: string,
id: number,
value: boolean,
}): void,
}>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const handleToggleNotifications = ({
id,
value,
}: {
id: string,
id: number,
value: boolean,
}) => {
notificationsManagementStore.setNotificationForPairedDevice({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useNotificationsManagementStore = defineStore('notifications-manage
)
}

const removeDevice = async (id: string) => {
const removeDevice = async (id: number) => {
await fetch(
API_PATH.NOTIFICATIONS_MANAGEMENT_PAIRED_DEVICES_DELETE,
{},
Expand All @@ -61,7 +61,7 @@ export const useNotificationsManagementStore = defineStore('notifications-manage
id,
value,
}: {
id: string,
id: number,
value: boolean,
}) => {
await fetch<InternalPutUserNotificationSettingsPairedDevicesResponse>(
Expand Down
2 changes: 1 addition & 1 deletion frontend/types/api/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export interface NotificationNetwork {
}
export type InternalPutUserNotificationSettingsNetworksResponse = ApiDataResponse<NotificationNetwork>;
export interface NotificationPairedDevice {
id: string;
id: number /* uint64 */;
paired_timestamp: number /* int64 */;
name?: string;
is_notifications_enabled: boolean;
Expand Down

0 comments on commit cd7d7b8

Please sign in to comment.