Add support for child users adding limits themself

This commit is contained in:
Jonas Lochmann
2020-08-03 02:00:00 +02:00
parent a73af1338e
commit 007b1f2ec9
11 changed files with 375 additions and 99 deletions
@@ -102,94 +102,99 @@ import { dispatchUpdateTimelimitRule } from './updatetimelimitrule'
import { dispatchUpdateUserFlagsAction } from './updateuserflags'
import { dispatchUpdateUserLimitLoginCategoryAction } from './updateuserlimitlogincategory'
export const dispatchParentAction = async ({ action, cache, parentUserId, sourceDeviceId }: {
export const dispatchParentAction = async ({ action, cache, parentUserId, sourceDeviceId, fromChildSelfLimitAddChildUserId }: {
action: ParentAction
cache: Cache
parentUserId: string
sourceDeviceId: string | null
fromChildSelfLimitAddChildUserId: string | null
}) => {
if (action instanceof AddCategoryAppsAction) {
await dispatchAddCategoryApps({ action, cache })
} else if (action instanceof AddUserAction) {
await dispatchAddUser({ action, cache })
} else if (action instanceof RemoveCategoryAppsAction) {
await dispatchRemoveCategoryApps({ action, cache })
return dispatchAddCategoryApps({ action, cache, fromChildSelfLimitAddChildUserId })
} else if (action instanceof CreateCategoryAction) {
await dispatchCreateCategory({ action, cache })
return dispatchCreateCategory({ action, cache, fromChildSelfLimitAddChildUserId })
} else if (action instanceof CreateTimeLimitRuleAction) {
await dispatchCreateTimeLimitRule({ action, cache })
} else if (action instanceof DeleteCategoryAction) {
await dispatchDeleteCategory({ action, cache })
} else if (action instanceof UpdateCategoryTitleAction) {
await dispatchUpdateCategoryTitle({ action, cache })
} else if (action instanceof SetCategoryExtraTimeAction) {
await dispatchSetCategoryExtraTime({ action, cache })
} else if (action instanceof SetCategoryForUnassignedAppsAction) {
await dispatchSetCategoryForUnassignedApps({ action, cache })
} else if (action instanceof SetChildPasswordAction) {
await dispatchSetChildPassword({ action, cache })
} else if (action instanceof SetConsiderRebootManipulationAction) {
await dispatchSetConsiderRebootManipulation({ action, cache })
} else if (action instanceof SetDeviceDefaultUserAction) {
await dispatchSetDeviceDefaultUser({ action, cache })
} else if (action instanceof SetDeviceDefaultUserTimeoutAction) {
await dispatchSetDeviceDefaultUserTimeout({ action, cache })
} else if (action instanceof SetDeviceUserAction) {
await dispatchSetDeviceUser({ action, cache })
} else if (action instanceof SetKeepSignedInAction) {
await dispatchSetKeepSignedIn({ action, cache, parentUserId })
} else if (action instanceof SetParentCategoryAction) {
await dispatchSetParentCategory({ action, cache })
} else if (action instanceof SetRelaxPrimaryDeviceAction) {
await dispatchSetRelaxPrimaryDevice({ action, cache })
} else if (action instanceof SetSendDeviceConnected) {
await dispatchSetSendDeviceConnected({ action, cache, sourceDeviceId })
} else if (action instanceof SetUserDisableLimitsUntilAction) {
await dispatchUserSetDisableLimitsUntil({ action, cache })
} else if (action instanceof SetUserTimezoneAction) {
await dispatchSetUserTimezone({ action, cache })
} else if (action instanceof UpdateCategoryBatteryLimitAction) {
await dispatchUpdateCategoryBatteryLimit({ action, cache })
return dispatchCreateTimeLimitRule({ action, cache, fromChildSelfLimitAddChildUserId })
} else if (action instanceof UpdateCategoryBlockAllNotificationsAction) {
await dispatchUpdateCategoryBlockAllNotifications({ action, cache })
} else if (action instanceof UpdateCategoryBlockedTimesAction) {
await dispatchUpdateCategoryBlockedTimes({ action, cache })
} else if (action instanceof UpdateCategorySortingAction) {
await dispatchUpdateCategorySorting({ action, cache })
} else if (action instanceof IncrementCategoryExtraTimeAction) {
await dispatchIncrementCategoryExtraTime({ action, cache })
return dispatchUpdateCategoryBlockAllNotifications({ action, cache, fromChildSelfLimitAddChildUserId })
} else if (action instanceof SetParentCategoryAction) {
return dispatchSetParentCategory({ action, cache, fromChildSelfLimitAddChildUserId })
} else if (action instanceof UpdateCategoryTemporarilyBlockedAction) {
await dispatchUpdateCategoryTemporarilyBlocked({ action, cache })
} else if (action instanceof DeleteTimeLimitRuleAction) {
await dispatchDeleteTimeLimitRule({ action, cache })
} else if (action instanceof UpdateDeviceNameAction) {
await dispatchUpdateDeviceName({ action, cache })
} else if (action instanceof UpdateEnableActivityLevelBlockingAction) {
await dispatchUpdateEnableActivityLevelBlocking({ action, cache })
} else if (action instanceof UpdateNetworkTimeVerificationAction) {
await dispatchUpdateNetworkTimeVerification({ action, cache })
} else if (action instanceof UpdateParentNotificationFlagsAction) {
await dispatchUpdateParentNotificationFlags({ action, cache })
} else if (action instanceof UpdateTimelimitRuleAction) {
await dispatchUpdateTimelimitRule({ action, cache })
} else if (action instanceof RemoveUserAction) {
await dispatchRemoveUser({ action, cache, parentUserId })
} else if (action instanceof RenameChildAction) {
await dispatchRenameChild({ action, cache })
} else if (action instanceof ChangeParentPasswordAction) {
await dispatchChangeParentPassword({ action, cache })
} else if (action instanceof IgnoreManipulationAction) {
await dispatchIgnoreManipulation({ action, cache })
} else if (action instanceof UpdateCategoryTimeWarningsAction) {
await dispatchUpdateCategoryTimeWarnings({ action, cache })
} else if (action instanceof ResetParentBlockedTimesAction) {
await dispatchResetParentBlockedTimes({ action, cache })
} else if (action instanceof UpdateParentBlockedTimesAction) {
await dispatchUpdateParentBlockedTimes({ action, cache, parentUserId })
} else if (action instanceof UpdateUserFlagsAction) {
await dispatchUpdateUserFlagsAction({ action, cache })
} else if (action instanceof UpdateUserLimitLoginCategory) {
await dispatchUpdateUserLimitLoginCategoryAction({ action, cache, parentUserId })
return dispatchUpdateCategoryTemporarilyBlocked({ action, cache, fromChildSelfLimitAddChildUserId })
}
if (fromChildSelfLimitAddChildUserId === null) {
if (action instanceof AddUserAction) {
return dispatchAddUser({ action, cache })
} else if (action instanceof RemoveCategoryAppsAction) {
return dispatchRemoveCategoryApps({ action, cache })
} else if (action instanceof DeleteCategoryAction) {
return dispatchDeleteCategory({ action, cache })
} else if (action instanceof UpdateCategoryTitleAction) {
return dispatchUpdateCategoryTitle({ action, cache })
} else if (action instanceof SetCategoryExtraTimeAction) {
return dispatchSetCategoryExtraTime({ action, cache })
} else if (action instanceof SetCategoryForUnassignedAppsAction) {
return dispatchSetCategoryForUnassignedApps({ action, cache })
} else if (action instanceof SetChildPasswordAction) {
return dispatchSetChildPassword({ action, cache })
} else if (action instanceof SetConsiderRebootManipulationAction) {
return dispatchSetConsiderRebootManipulation({ action, cache })
} else if (action instanceof SetDeviceDefaultUserAction) {
return dispatchSetDeviceDefaultUser({ action, cache })
} else if (action instanceof SetDeviceDefaultUserTimeoutAction) {
return dispatchSetDeviceDefaultUserTimeout({ action, cache })
} else if (action instanceof SetDeviceUserAction) {
return dispatchSetDeviceUser({ action, cache })
} else if (action instanceof SetKeepSignedInAction) {
return dispatchSetKeepSignedIn({ action, cache, parentUserId })
} else if (action instanceof SetRelaxPrimaryDeviceAction) {
return dispatchSetRelaxPrimaryDevice({ action, cache })
} else if (action instanceof SetSendDeviceConnected) {
return dispatchSetSendDeviceConnected({ action, cache, sourceDeviceId })
} else if (action instanceof SetUserDisableLimitsUntilAction) {
return dispatchUserSetDisableLimitsUntil({ action, cache })
} else if (action instanceof SetUserTimezoneAction) {
return dispatchSetUserTimezone({ action, cache })
} else if (action instanceof UpdateCategoryBatteryLimitAction) {
return dispatchUpdateCategoryBatteryLimit({ action, cache })
} else if (action instanceof UpdateCategoryBlockedTimesAction) {
return dispatchUpdateCategoryBlockedTimes({ action, cache })
} else if (action instanceof UpdateCategorySortingAction) {
return dispatchUpdateCategorySorting({ action, cache })
} else if (action instanceof IncrementCategoryExtraTimeAction) {
return dispatchIncrementCategoryExtraTime({ action, cache })
} else if (action instanceof DeleteTimeLimitRuleAction) {
return dispatchDeleteTimeLimitRule({ action, cache })
} else if (action instanceof UpdateDeviceNameAction) {
return dispatchUpdateDeviceName({ action, cache })
} else if (action instanceof UpdateEnableActivityLevelBlockingAction) {
return dispatchUpdateEnableActivityLevelBlocking({ action, cache })
} else if (action instanceof UpdateNetworkTimeVerificationAction) {
return dispatchUpdateNetworkTimeVerification({ action, cache })
} else if (action instanceof UpdateParentNotificationFlagsAction) {
return dispatchUpdateParentNotificationFlags({ action, cache })
} else if (action instanceof UpdateTimelimitRuleAction) {
return dispatchUpdateTimelimitRule({ action, cache })
} else if (action instanceof RemoveUserAction) {
return dispatchRemoveUser({ action, cache, parentUserId })
} else if (action instanceof RenameChildAction) {
return dispatchRenameChild({ action, cache })
} else if (action instanceof ChangeParentPasswordAction) {
return dispatchChangeParentPassword({ action, cache })
} else if (action instanceof IgnoreManipulationAction) {
return dispatchIgnoreManipulation({ action, cache })
} else if (action instanceof UpdateCategoryTimeWarningsAction) {
return dispatchUpdateCategoryTimeWarnings({ action, cache })
} else if (action instanceof ResetParentBlockedTimesAction) {
return dispatchResetParentBlockedTimes({ action, cache })
} else if (action instanceof UpdateParentBlockedTimesAction) {
return dispatchUpdateParentBlockedTimes({ action, cache, parentUserId })
} else if (action instanceof UpdateUserFlagsAction) {
return dispatchUpdateUserFlagsAction({ action, cache })
} else if (action instanceof UpdateUserLimitLoginCategory) {
return dispatchUpdateUserLimitLoginCategoryAction({ action, cache, parentUserId })
}
} else {
throw new Error('unsupported action type')
}