PermissionRequest.js.map 14 KB

1
  1. {"version":3,"sources":["../../../src/app/content/my-resources-page/PermissionRequest.tsx"],"names":["React","Button","Modal","Text","Badge","DataListItem","DataList","TextVariants","DataListItemRow","DataListItemCells","DataListCell","Chip","Split","SplitItem","UserCheckIcon","AccountServiceContext","Msg","ContentAlert","PermissionRequest","Component","constructor","props","context","shareRequest","index","handle","username","scopes","resource","shareRequests","splice","approve","id","_id","handleToggleDialog","permissionsRequest","doGet","permissions","data","foundPermission","find","p","userScopes","push","doPut","success","localize","onClose","e","console","error","setState","isOpen","state","render","name","replace","length","map","i","firstName","lastName","small","email","scope","j","handleApprove","handleDeny","row"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,KAAKA,KAAZ;AACA,SACIC,MADJ,EAEIC,KAFJ,EAGIC,IAHJ,EAIIC,KAJJ,EAKIC,YALJ,EAMIC,QANJ,EAOIC,YAPJ,EAQIC,eARJ,EASIC,iBATJ,EAUIC,YAVJ,EAWIC,IAXJ,EAYIC,KAZJ,EAaIC,SAbJ;AAeA,SAASC,aAAT;AAGA,SAASC,qBAAT;AACA,SAASC,GAAT;AACA,SAASC,YAAT;AAaA,OAAO,MAAMC,iBAAN,SAAgClB,KAAK,CAACmB,SAAtC,CAAgG;AAK5FC,EAAAA,WAAW,CAACC,KAAD,EAAgCC,OAAhC,EAA0F;AACxG,UAAMD,KAAN;;AADwG;;AAAA,2CASpF,OAAOE,YAAP,EAAiCC,KAAjC,KAAmD;AACvE,WAAKC,MAAL,CAAYF,YAAY,CAACG,QAAzB,EAAmCH,YAAY,CAACI,MAAhD,EAAmE,IAAnE;AACA,WAAKN,KAAL,CAAWO,QAAX,CAAoBC,aAApB,CAAkCC,MAAlC,CAAyCN,KAAzC,EAAgD,CAAhD;AACH,KAZ2G;;AAAA,wCAcvF,OAAOD,YAAP,EAAiCC,KAAjC,KAAmD;AACpE,WAAKC,MAAL,CAAY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C,CAAqC,CAACM,KAAD,EAAQC,CAAR,KAAc,oBAAC,IAAD;AAAM,QAAA,GAAG,EAAEA,CAAX;AAAc,QAAA,UAAU;AAAxB,SAA0BD,KAA1B,CAAnD,CADL,CAPW,EAUX,oBAAC,YAAD;AAAc,QAAA,GAAG,EAAG,UAASL,CAAE;AAA/B,SACI,oBAAC,KAAD;AAAO,QAAA,MAAM,EAAC;AAAd,SACI,oBAAC,SAAD,QACI,oBAAC,MAAD;AACI,QAAA,EAAE,EAAG,UAASA,CAAE,IAAG3B,EAAG,EAD1B;AAEI,QAAA,OAAO,EAAE,MAAM,KAAKkC,aAAL,CAAmB3C,YAAnB,EAAiCoC,CAAjC;AAFnB,kBADJ,CADJ,EASI,oBAAC,SAAD,QACI,oBAAC,MAAD;AACI,QAAA,EAAE,EAAG,QAAOA,CAAE,IAAG3B,EAAG,EADxB;AAEI,QAAA,OAAO,EAAC,QAFZ;AAGI,QAAA,OAAO,EAAE,MAAM,KAAKmC,UAAL,CAAgB5C,YAAhB,EAA8BoC,CAA9B;AAHnB,gBADJ,CATJ,CADJ,CAVW;AADnB,MADJ,CADJ,CADH,CAfL,CAZJ,CANJ,CADJ;AA8EH;;AAhIkG;;gBAA1FzC,iB,kBACuB;AAAEmB,EAAAA,WAAW,EAAE,EAAf;AAAmB+B,EAAAA,GAAG,EAAE;AAAxB,C;;gBADvBlD,iB,iBAEYH,qB","sourcesContent":["/*\n * Copyright 2019 Red Hat, Inc. and/or its affiliates.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as React from 'react';\nimport {\n Button,\n Modal,\n Text,\n Badge,\n DataListItem,\n DataList,\n TextVariants,\n DataListItemRow,\n DataListItemCells,\n DataListCell,\n Chip,\n Split,\n SplitItem\n} from '@patternfly/react-core';\nimport { UserCheckIcon } from '@patternfly/react-icons';\n\nimport { HttpResponse } from '../../account-service/account.service';\nimport { AccountServiceContext } from '../../account-service/AccountServiceContext';\nimport { Msg } from '../../widgets/Msg';\nimport { ContentAlert } from '../ContentAlert';\nimport { Resource, Scope, Permission } from './resource-model';\n\n\ninterface PermissionRequestProps {\n resource: Resource;\n onClose: () => void;\n}\n\ninterface PermissionRequestState {\n isOpen: boolean;\n}\n\nexport class PermissionRequest extends React.Component<PermissionRequestProps, PermissionRequestState> {\n protected static defaultProps = { permissions: [], row: 0 };\n static contextType = AccountServiceContext;\n context: React.ContextType<typeof AccountServiceContext>;\n\n public constructor(props: PermissionRequestProps, context: React.ContextType<typeof AccountServiceContext>) {\n super(props);\n this.context = context;\n \n this.state = {\n isOpen: false,\n };\n }\n\n private handleApprove = async (shareRequest: Permission, index: number) => {\n this.handle(shareRequest.username, shareRequest.scopes as Scope[], true);\n this.props.resource.shareRequests.splice(index, 1);\n };\n\n private handleDeny = async (shareRequest: Permission, index: number) => {\n this.handle(shareRequest.username, shareRequest.scopes as Scope[]);\n this.props.resource.shareRequests.splice(index, 1)\n };\n\n private handle = async (username: string, scopes: Scope[], approve: boolean = false) => {\n const id = this.props.resource._id\n this.handleToggleDialog();\n\n const permissionsRequest: HttpResponse<Permission[]> = await this.context!.doGet(`/resources/${id}/permissions`);\n const permissions = permissionsRequest.data || [];\n const foundPermission = permissions.find(p => p.username === username);\n const userScopes = foundPermission ? (foundPermission.scopes as Scope[]): [];\n if (approve) {\n userScopes.push(...scopes);\n }\n try {\n await this.context!.doPut(`/resources/${id}/permissions`, [{ username: username, scopes: userScopes }] )\n ContentAlert.success(Msg.localize('shareSuccess'));\n this.props.onClose();\n } catch (e) {\n console.error('Could not update permissions', e.error);\n }\n };\n\n private handleToggleDialog = () => {\n this.setState({ isOpen: !this.state.isOpen });\n };\n\n public render(): React.ReactNode {\n const id = `shareRequest-${this.props.resource.name.replace(/\\s/, '-')}`;\n return (\n <React.Fragment>\n <Button id={id} variant=\"link\" onClick={this.handleToggleDialog}>\n <UserCheckIcon size=\"lg\" />\n <Badge>{this.props.resource.shareRequests.length}</Badge>\n </Button>\n\n <Modal\n id={`modal-${id}`}\n title={Msg.localize('permissionRequests') + ' - ' + this.props.resource.name}\n isLarge={true}\n isOpen={this.state.isOpen}\n onClose={this.handleToggleDialog}\n actions={[\n <Button id={`close-${id}`} key=\"close\" variant=\"link\" onClick={this.handleToggleDialog}>\n <Msg msgKey=\"close\" />\n </Button>,\n ]}\n >\n <DataList aria-label={Msg.localize('permissionRequests')}>\n <DataListItemRow>\n <DataListItemCells\n dataListCells={[\n <DataListCell key='permissions-name-header' width={5}>\n <strong>Requestor</strong>\n </DataListCell>,\n <DataListCell key='permissions-requested-header' width={5}>\n <strong><Msg msgKey='permissionRequests' /></strong>\n </DataListCell>,\n <DataListCell key='permission-request-header' width={5}>\n </DataListCell>\n ]}\n />\n </DataListItemRow>\n {this.props.resource.shareRequests.map((shareRequest, i) =>\n <DataListItem key={i} aria-labelledby=\"requestor\">\n <DataListItemRow>\n <DataListItemCells\n dataListCells={[\n <DataListCell id={`requestor${i}`} key={`requestor${i}`}>\n <span>\n {shareRequest.firstName} {shareRequest.lastName} {shareRequest.lastName ? '' : shareRequest.username}\n </span><br />\n <Text component={TextVariants.small}>{shareRequest.email}</Text>\n </DataListCell>,\n <DataListCell id={`permissions${i}`} key={`permissions${i}`}>\n {(shareRequest.scopes as Scope[]).map((scope, j) => <Chip key={j} isReadOnly>{scope}</Chip>)}\n </DataListCell>,\n <DataListCell key={`actions${i}`}>\n <Split gutter=\"sm\">\n <SplitItem>\n <Button\n id={`accept-${i}-${id}`}\n onClick={() => this.handleApprove(shareRequest, i)}\n >\n Accept\n </Button>\n </SplitItem>\n <SplitItem>\n <Button\n id={`deny-${i}-${id}`}\n variant=\"danger\"\n onClick={() => this.handleDeny(shareRequest, i)}\n >\n Deny\n </Button>\n </SplitItem>\n </Split>\n </DataListCell>\n ]}\n />\n </DataListItemRow>\n </DataListItem>\n )}\n </DataList>\n </Modal>\n </React.Fragment>\n );\n }\n}"],"file":"PermissionRequest.js"}