Allow adding category network ids

This commit is contained in:
Jonas Lochmann
2020-08-24 02:00:00 +02:00
parent 9730d13b2e
commit eb6f668b43
34 changed files with 1257 additions and 62 deletions
+66
View File
@@ -0,0 +1,66 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { anonymizedNetworkIdLength } from '../database/categorynetworkid'
import { assertIsHexString } from '../util/hexstring'
import { assertIdWithinFamily } from '../util/token'
import { ParentAction } from './basetypes'
export class AddCategoryNetworkIdAction extends ParentAction {
readonly categoryId: string
readonly itemId: string
readonly hashedNetworkId: string
constructor ({ categoryId, itemId, hashedNetworkId }: {
categoryId: string
itemId: string
hashedNetworkId: string
}) {
super()
assertIdWithinFamily(categoryId)
assertIdWithinFamily(itemId)
assertIsHexString(hashedNetworkId)
if (hashedNetworkId.length !== anonymizedNetworkIdLength) throw new Error('wrong network id length')
this.categoryId = categoryId
this.itemId = itemId
this.hashedNetworkId = hashedNetworkId
}
serialize = (): SerializedAddCategoryNetworkIdAction => ({
type: 'ADD_CATEGORY_NETWORK_ID',
categoryId: this.categoryId,
itemId: this.itemId,
hashedNetworkId: this.hashedNetworkId
})
static parse = ({ categoryId, itemId, hashedNetworkId }: SerializedAddCategoryNetworkIdAction) => (
new AddCategoryNetworkIdAction({
categoryId,
itemId,
hashedNetworkId
})
)
}
export interface SerializedAddCategoryNetworkIdAction {
type: 'ADD_CATEGORY_NETWORK_ID'
categoryId: string
itemId: string
hashedNetworkId: string
}
+2
View File
@@ -18,6 +18,7 @@
export { AppLogicAction, ChildAction, ParentAction } from './basetypes'
export { AddCategoryAppsAction } from './addcategoryapps'
export { AddCategoryNetworkIdAction } from './addcategorynetworkid'
export { AddUserAction } from './adduser'
export { AddInstalledAppsAction } from './addinstalledapps'
export { AddUsedTimeAction } from './addusedtime'
@@ -34,6 +35,7 @@ export { IncrementCategoryExtraTimeAction } from './incrementcategoryextratime'
export { RemoveCategoryAppsAction } from './removecategoryapps'
export { RemoveInstalledAppsAction } from './removeinstalledapps'
export { RemoveUserAction } from './removeuser'
export { ResetCategoryNetworkIdsAction } from './resetcategorynetworkids'
export { RenameChildAction } from './renamechild'
export { ResetParentBlockedTimesAction } from './resetparentblockedtimes'
export { SetCategoryExtraTimeAction } from './setcategoryextratime'
+49
View File
@@ -0,0 +1,49 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { assertIdWithinFamily } from '../util/token'
import { ParentAction } from './basetypes'
export class ResetCategoryNetworkIdsAction extends ParentAction {
readonly categoryId: string
constructor ({ categoryId }: {
categoryId: string
}) {
super()
assertIdWithinFamily(categoryId)
this.categoryId = categoryId
}
serialize = (): SerializeResetCategoryNetworkIdsAction => ({
type: 'RESET_CATEGORY_NETWORK_IDS',
categoryId: this.categoryId
})
static parse = ({ categoryId }: SerializeResetCategoryNetworkIdsAction) => (
new ResetCategoryNetworkIdsAction({
categoryId
})
)
}
export interface SerializeResetCategoryNetworkIdsAction {
type: 'RESET_CATEGORY_NETWORK_IDS'
categoryId: string
}
+8
View File
@@ -16,6 +16,7 @@
*/
import { AddCategoryAppsAction, SerializedAddCategoryAppsAction } from '../addcategoryapps'
import { AddCategoryNetworkIdAction, SerializedAddCategoryNetworkIdAction } from '../addcategorynetworkid'
import { AddUserAction, SerializedAddUserAction } from '../adduser'
import { ParentAction } from '../basetypes'
import { ChangeParentPasswordAction, SerializedChangeParentPasswordAction } from '../changeparentpassword'
@@ -28,6 +29,7 @@ import { IncrementCategoryExtraTimeAction, SerializedIncrementCategoryExtraTimeA
import { RemoveCategoryAppsAction, SerializedRemoveCategoryAppsAction } from '../removecategoryapps'
import { RemoveUserAction, SerializedRemoveUserAction } from '../removeuser'
import { RenameChildAction, SerializedRenameChildAction } from '../renamechild'
import { ResetCategoryNetworkIdsAction, SerializeResetCategoryNetworkIdsAction } from '../resetcategorynetworkids'
import { ResetParentBlockedTimesAction, SerializedResetParentBlockedTimesAction } from '../resetparentblockedtimes'
import { SerializedSetCategoryExtraTimeAction, SetCategoryExtraTimeAction } from '../setcategoryextratime'
import { SerializedSetCategoryForUnassignedAppsAction, SetCategoryForUnassignedAppsAction } from '../setcategoryforunassignedapps'
@@ -60,6 +62,7 @@ import { SerializedUpdateUserLimitLoginCategory, UpdateUserLimitLoginCategory }
export type SerializedParentAction =
SerializedAddCategoryAppsAction |
SerializedAddCategoryNetworkIdAction |
SerializedAddUserAction |
SerializedChangeParentPasswordAction |
SerializedCreateCategoryAction |
@@ -71,6 +74,7 @@ export type SerializedParentAction =
SerializedRemoveCategoryAppsAction |
SerializedRemoveUserAction |
SerializedRenameChildAction |
SerializeResetCategoryNetworkIdsAction |
SerializedResetParentBlockedTimesAction |
SerializedSetCategoryForUnassignedAppsAction |
SerializedSetChildPasswordAction |
@@ -104,6 +108,8 @@ export type SerializedParentAction =
export const parseParentAction = (action: SerializedParentAction): ParentAction => {
if (action.type === 'ADD_CATEGORY_APPS') {
return AddCategoryAppsAction.parse(action)
} else if (action.type === 'ADD_CATEGORY_NETWORK_ID') {
return AddCategoryNetworkIdAction.parse(action)
} else if (action.type === 'ADD_USER') {
return AddUserAction.parse(action)
} else if (action.type === 'CHANGE_PARENT_PASSWORD') {
@@ -126,6 +132,8 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
return RemoveUserAction.parse(action)
} else if (action.type === 'RENAME_CHILD') {
return RenameChildAction.parse(action)
} else if (action.type === 'RESET_CATEGORY_NETWORK_IDS') {
return ResetCategoryNetworkIdsAction.parse(action)
} else if (action.type === 'RESET_PARENT_BLOCKED_TIMES') {
return ResetParentBlockedTimesAction.parse(action)
} else if (action.type === 'SET_CATEGORY_EXTRA_TIME') {