From b845eaf91f3983011e145a5c6d3bfa5fbdf7997a Mon Sep 17 00:00:00 2001 From: cd-bitwarden <106776772+cd-bitwarden@users.noreply.github.com> Date: Fri, 30 Jun 2023 13:17:26 -0400 Subject: [PATCH] SM-716 - Write access for service accounts (#5622) * SM-716 * thomas suggested changes * removing unused code * 2 --- .../project-service-accounts.component.html | 1 + .../project-service-accounts.component.ts | 12 +++++++++++- .../service-account-projects.component.html | 1 + .../service-account-projects.component.ts | 16 +++++++++++++--- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-service-accounts.component.html b/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-service-accounts.component.html index fb6eab471b..2755377d2a 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-service-accounts.component.html +++ b/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-service-accounts.component.html @@ -11,6 +11,7 @@ [emptyMessage]="'projectEmptyServiceAccountAccessPolicies' | i18n" (onCreateAccessPolicies)="handleCreateAccessPolicies($event)" (onDeleteAccessPolicy)="handleDeleteAccessPolicy($event)" + (onUpdateAccessPolicy)="handleUpdateAccessPolicy($event)" > diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-service-accounts.component.ts b/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-service-accounts.component.ts index d64aec5f31..2cd2134dd4 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-service-accounts.component.ts +++ b/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-service-accounts.component.ts @@ -39,11 +39,21 @@ export class ProjectServiceAccountsComponent implements OnInit, OnDestroy { read: policy.read, write: policy.write, icon: AccessSelectorComponent.serviceAccountIcon, - static: true, + static: false, })) ) ); + protected async handleUpdateAccessPolicy(policy: AccessSelectorRowView) { + try { + return await this.accessPolicyService.updateAccessPolicy( + AccessSelectorComponent.getBaseAccessPolicyView(policy) + ); + } catch (e) { + this.validationService.showError(e); + } + } + protected handleCreateAccessPolicies(selected: SelectItemView[]) { const projectAccessPoliciesView = new ProjectAccessPoliciesView(); projectAccessPoliciesView.serviceAccountAccessPolicies = selected diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/projects/service-account-projects.component.html b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/projects/service-account-projects.component.html index 8ffc465e1b..368a62a933 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/projects/service-account-projects.component.html +++ b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/projects/service-account-projects.component.html @@ -11,6 +11,7 @@ [emptyMessage]="'serviceAccountEmptyProjectAccesspolicies' | i18n" (onCreateAccessPolicies)="handleCreateAccessPolicies($event)" (onDeleteAccessPolicy)="handleDeleteAccessPolicy($event)" + (onUpdateAccessPolicy)="handleUpdateAccessPolicy($event)" > diff --git a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/projects/service-account-projects.component.ts b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/projects/service-account-projects.component.ts index ecce07aef5..aed98a4235 100644 --- a/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/projects/service-account-projects.component.ts +++ b/bitwarden_license/bit-web/src/app/secrets-manager/service-accounts/projects/service-account-projects.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, OnDestroy, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { combineLatestWith, map, Observable, startWith, Subject, switchMap, takeUntil } from "rxjs"; @@ -16,7 +16,7 @@ import { selector: "sm-service-account-projects", templateUrl: "./service-account-projects.component.html", }) -export class ServiceAccountProjectsComponent { +export class ServiceAccountProjectsComponent implements OnInit, OnDestroy { private destroy$ = new Subject(); private serviceAccountId: string; private organizationId: string; @@ -38,7 +38,7 @@ export class ServiceAccountProjectsComponent { read: policy.read, write: policy.write, icon: AccessSelectorComponent.projectIcon, - static: true, + static: false, } as AccessSelectorRowView; }); }) @@ -63,6 +63,16 @@ export class ServiceAccountProjectsComponent { ); } + protected async handleUpdateAccessPolicy(policy: AccessSelectorRowView) { + try { + return await this.accessPolicyService.updateAccessPolicy( + AccessSelectorComponent.getBaseAccessPolicyView(policy) + ); + } catch (e) { + this.validationService.showError(e); + } + } + protected async handleDeleteAccessPolicy(policy: AccessSelectorRowView) { try { await this.accessPolicyService.deleteAccessPolicy(policy.accessPolicyId);