From 23264849c9088c42268704895d956e8218630047 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Mon, 1 Apr 2019 14:35:02 +0200 Subject: [PATCH] client and small changes in the serializer --- .../shared/models/motions/workflow-state.ts | 2 +- .../workflow-detail.component.html | 29 +++++++---- .../workflow-detail.component.ts | 50 ++++++++++++------- .../services/motion-filter-list.service.ts | 2 +- openslides/motions/access_permissions.py | 5 +- ...ction_1.py => 0024_state_restriction_1.py} | 4 +- ...ction_2.py => 0024_state_restriction_2.py} | 4 +- ...ction_3.py => 0024_state_restriction_3.py} | 2 +- openslides/motions/serializers.py | 20 +++++--- 9 files changed, 76 insertions(+), 42 deletions(-) rename openslides/motions/migrations/{0023_state_restriction_1.py => 0024_state_restriction_1.py} (90%) rename openslides/motions/migrations/{0023_state_restriction_2.py => 0024_state_restriction_2.py} (90%) rename openslides/motions/migrations/{0023_state_restriction_3.py => 0024_state_restriction_3.py} (77%) diff --git a/client/src/app/shared/models/motions/workflow-state.ts b/client/src/app/shared/models/motions/workflow-state.ts index 8c0040acc..8cb644f12 100644 --- a/client/src/app/shared/models/motions/workflow-state.ts +++ b/client/src/app/shared/models/motions/workflow-state.ts @@ -21,7 +21,7 @@ export class WorkflowState extends Deserializer { public name: string; public recommendation_label: string; public css_class: string; - public access_level: number; + public restriction: string[]; public allow_support: boolean; public allow_create_poll: boolean; public allow_submitter_edit: boolean; diff --git a/client/src/app/site/motions/modules/motion-workflow/components/workflow-detail/workflow-detail.component.html b/client/src/app/site/motions/modules/motion-workflow/components/workflow-detail/workflow-detail.component.html index 2bf76810f..8fbf43135 100644 --- a/client/src/app/site/motions/modules/motion-workflow/components/workflow-detail/workflow-detail.component.html +++ b/client/src/app/site/motions/modules/motion-workflow/components/workflow-detail/workflow-detail.component.html @@ -103,13 +103,24 @@
- {{ accessLevels[state.access_level].label | translate }} +
+ - +
+
+ + {{ getRestrictionLabel(restriction) | translate }} + +
@@ -179,12 +190,12 @@ - - + + - diff --git a/client/src/app/site/motions/modules/motion-workflow/components/workflow-detail/workflow-detail.component.ts b/client/src/app/site/motions/modules/motion-workflow/components/workflow-detail/workflow-detail.component.ts index c92ad6f05..6a46aa1cf 100644 --- a/client/src/app/site/motions/modules/motion-workflow/components/workflow-detail/workflow-detail.component.ts +++ b/client/src/app/site/motions/modules/motion-workflow/components/workflow-detail/workflow-detail.component.ts @@ -41,18 +41,18 @@ interface StatePerm { } /** - * Defines the structure of access levels + * Defines the structure of AmendmentIntoFinal */ -interface AccessLevel { - level: number; +interface AmendmentIntoFinal { + merge: MergeAmendment; label: string; } /** - * Defines the structure of access levels + * Defines the structre of restrictions */ -interface AmendmentIntoFinal { - merge: MergeAmendment; +interface Restriction { + key: string; label: string; } @@ -108,20 +108,20 @@ export class WorkflowDetailComponent extends BaseViewComponent implements OnInit type: 'check' }, { name: 'Show amendment in parent motoin', selector: 'merge_amendment_into_final', type: 'amendment' }, - { name: 'Access level', selector: 'access_level', type: 'accessLevel' }, + { name: 'Restrictions', selector: 'restriction', type: 'restriction' }, { name: 'Label color', selector: 'css_class', type: 'color' }, { name: 'Next states', selector: 'next_states_id', type: 'state' } ] as StatePerm[]; /** - * Determines possible access levels + * Determines possible restrictions */ - public accessLevels = [ - { level: 0, label: '0: All users' }, - { level: 1, label: '1: Submitters, authorized users and managers' }, - { level: 2, label: '2: Authorized users and managers for motions and metadata' }, - { level: 3, label: '3: Only managers for motions' } - ] as AccessLevel[]; + public restrictions = [ + { key: 'managers_only', label: 'Managers only' }, + { key: 'motions.can_see_internal', label: 'Can see internal (perm)' }, + { key: 'motions.can_manage_metadata', label: 'Can manage metadata (perm)' }, + { key: 'is_submitter', label: 'Is submitter' } + ] as Restriction[]; /** * Determines possible "Merge amendments into final" @@ -279,11 +279,27 @@ export class WorkflowDetailComponent extends BaseViewComponent implements OnInit /** * Sets an access level to the given workflow state * - * @param level The new access level + * @param restrictions The new restrictions * @param state the state to change */ - public onSetAccesLevel(level: number, state: WorkflowState): void { - this.workflowRepo.updateState({ access_level: level }, state).then(() => {}, this.raiseError); + public onSetRestriction(restriction: string, state: WorkflowState): void { + const restrictions = state.restriction.map(r => r); + const restrictionIndex = restrictions.findIndex(r => r === restriction); + + if (restrictionIndex < 0) { + restrictions.push(restriction); + } else { + restrictions.splice(restrictionIndex, 1); + } + this.workflowRepo.updateState({ restriction: restrictions }, state).then(() => {}, this.raiseError); + } + + /** + * @returns the restriction label for the given restriction + */ + public getRestrictionLabel(restriction: string): string { + const entry = this.restrictions.find(r => r.key === restriction); + return entry ? entry.label : ''; } /** diff --git a/client/src/app/site/motions/services/motion-filter-list.service.ts b/client/src/app/site/motions/services/motion-filter-list.service.ts index a992b9bf9..e6ce4543d 100644 --- a/client/src/app/site/motions/services/motion-filter-list.service.ts +++ b/client/src/app/site/motions/services/motion-filter-list.service.ts @@ -246,7 +246,7 @@ export class MotionFilterListService extends BaseFilterListService