├── website-creator ├── web-site-manifest.json ├── index.js ├── website-helper.js ├── css │ └── style.css ├── userhierarchy.html └── js │ └── userhierarchy.js ├── CODE_OF_CONDUCT.md ├── README.md ├── LICENSE ├── CONTRIBUTING.md └── template.yaml /website-creator/web-site-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "./userhierarchy.html", 4 | "./css/style.css", 5 | "./js/aws-sdk-uh.js", 6 | "./js/userhierarchy.js" 7 | ] 8 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Amazon Connect user hirerachies API's demo 3 | 4 | This demo shows how you can leverage [Amazon Connect](https://aws.amazon.com/connect/) api's to manage user hirerachies. 5 | 6 | ## Usage 7 | Use `sam` to build, invoke and deploy the function. 8 | 9 | ##### SAM Build: 10 | Ensure you are in the root folder 11 | 12 | `sam build --use-container` 13 | 14 | ##### SAM Deploy: 15 | `sam deploy template.yaml --s3-bucket REPLACE_ME --stack-name REPLACE_ME --parameter-overrides ParameterKey=CFS3BucketForWebSite,ParameterValue=REPLACE_ME --capabilities CAPABILITY_IAM` 16 | 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | -------------------------------------------------------------------------------- /website-creator/index.js: -------------------------------------------------------------------------------- 1 | const AWS = require('aws-sdk'); 2 | const https = require('https'); 3 | const url = require('url'); 4 | const WebsiteHelper = require('./website-helper.js'); 5 | 6 | exports.handler = (event, context, callback) => { 7 | console.log('Received event:', JSON.stringify(event, null, 2)); 8 | 9 | let responseStatus = 'FAILED'; 10 | let responseData = {}; 11 | 12 | if (event.RequestType === 'Delete') { 13 | sendResponse(event, callback, context.logStreamName, 'SUCCESS'); 14 | } 15 | 16 | if (event.RequestType === 'Create') { 17 | if (event.ResourceProperties.customAction === 'configureWebsite') { 18 | console.log('Starting to copy the files'); 19 | let _websiteHelper = new WebsiteHelper(); 20 | 21 | _websiteHelper.copyWebSiteAssets(event.ResourceProperties, 22 | function(err, data) { 23 | if (err) { 24 | responseData = { 25 | Error: 'Copy of website assets failed' 26 | }; 27 | console.log([responseData.Error, ':\n', err].join('')); 28 | } else { 29 | responseStatus = 'SUCCESS'; 30 | responseData = {}; 31 | } 32 | 33 | sendResponse(event, callback, context.logStreamName, responseStatus, responseData); 34 | }); 35 | 36 | } 37 | //sendResponse(event, callback, context.logStreamName, 'SUCCESS'); 38 | } 39 | 40 | 41 | }; 42 | 43 | /** 44 | * Sends a response to the pre-signed S3 URL 45 | */ 46 | 47 | let sendResponse = function(event, callback, logStreamName, responseStatus, responseData) { 48 | const responseBody = JSON.stringify({ 49 | Status: responseStatus, 50 | Reason: `See the details in CloudWatch Log Stream: ${logStreamName}`, 51 | PhysicalResourceId: logStreamName, 52 | StackId: event.StackId, 53 | RequestId: event.RequestId, 54 | LogicalResourceId: event.LogicalResourceId, 55 | Data: responseData, 56 | }); 57 | 58 | console.log('RESPONSE BODY:\n', responseBody); 59 | const parsedUrl = url.parse(event.ResponseURL); 60 | const options = { 61 | hostname: parsedUrl.hostname, 62 | port: 443, 63 | path: parsedUrl.path, 64 | method: 'PUT', 65 | headers: { 66 | 'Content-Type': '', 67 | 'Content-Length': responseBody.length, 68 | } 69 | }; 70 | 71 | const req = https.request(options, (res) => { 72 | console.log('STATUS:', res.statusCode); 73 | console.log('HEADERS:', JSON.stringify(res.headers)); 74 | callback(null, 'Successfully sent stack response!'); 75 | }); 76 | 77 | req.on('error', (err) => { 78 | console.log('sendResponse Error:\n', err); 79 | callback(err); 80 | }); 81 | 82 | req.write(responseBody); 83 | req.end(); 84 | }; -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | -------------------------------------------------------------------------------- /website-creator/website-helper.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let AWS = require('aws-sdk'); 4 | let s3 = new AWS.S3(); 5 | const fs = require('fs'); 6 | const _downloadLocation = './web-site-manifest.json'; 7 | 8 | /** 9 | * Helper function to interact with s3 hosted website for cfn custom resource. 10 | * 11 | * @class websiteHelper 12 | */ 13 | let websiteHelper = (function() { 14 | 15 | /** 16 | * @class websiteHelper 17 | * @constructor 18 | */ 19 | let websiteHelper = function() {}; 20 | 21 | websiteHelper.prototype.copyWebSiteAssets = function(resourceProperties, cb) { 22 | var destS3Bucket = resourceProperties.destS3Bucket; 23 | var destS3KeyPrefix = resourceProperties.destS3KeyPrefix; 24 | var region = resourceProperties.Region; 25 | 26 | console.log("Copying UI web site"); 27 | console.log(['destination bucket:', destS3Bucket].join(' ')); 28 | console.log(['destination s3 key prefix:', destS3KeyPrefix].join(' ')); 29 | console.log(['region:', region].join(' ')); 30 | 31 | fs.readFile(_downloadLocation, 'utf8', function(err, data) { 32 | if (err) { 33 | console.log(err); 34 | return cb(err, null); 35 | } 36 | 37 | console.log(data); 38 | let _manifest = validateJSON(data); 39 | 40 | if (!_manifest) { 41 | return cb('Unable to validate downloaded manifest file JSON', null); 42 | } else { 43 | uploadToS3(_manifest.files, 0, destS3Bucket, destS3KeyPrefix, 44 | function(err, result) { 45 | if (err) { 46 | return cb(err, null); 47 | } 48 | console.log(result); 49 | return cb(null, result); 50 | }); 51 | } 52 | 53 | }); 54 | }; 55 | 56 | 57 | /** 58 | * Helper function to validate the JSON structure of contents of an import manifest file. 59 | * @param {string} body - JSON object stringify-ed. 60 | * @returns {JSON} - The JSON parsed string or null if string parsing failed 61 | */ 62 | let validateJSON = function(body) { 63 | try { 64 | let data = JSON.parse(body); 65 | console.log(data); 66 | return data; 67 | } catch (e) { 68 | // failed to parse 69 | console.log('Manifest file contains invalid JSON.'); 70 | return null; 71 | } 72 | }; 73 | 74 | async function uploadToS3(filelist, index, destS3Bucket, destS3KeyPrefix, cb) { 75 | if (filelist.length > index) { 76 | 77 | const response = fs.readFileSync(filelist[index], 'utf8'); 78 | var fileDetails = filelist[index] 79 | fileDetails = fileDetails.substring(2, fileDetails.length); 80 | 81 | let params2 = { 82 | Bucket: destS3Bucket, 83 | Key: destS3KeyPrefix + '/' + fileDetails, 84 | Body: response 85 | }; 86 | if (filelist[index].endsWith('.htm') || filelist[index].endsWith('.html')) { 87 | params2.ContentType = "text/html"; 88 | } else if (filelist[index].endsWith('.css')) { 89 | params2.ContentType = "text/css"; 90 | } else if (filelist[index].endsWith('.js')) { 91 | params2.ContentType = "application/javascript"; 92 | } else if (filelist[index].endsWith('.png')) { 93 | params2.ContentType = "image/png"; 94 | } else if (filelist[index].endsWith('.jpg') || filelist[index].endsWith('.jpeg')) { 95 | params2.ContentType = "image/jpeg"; 96 | } else if (filelist[index].endsWith('.pdf')) { 97 | params2.ContentType = "application/pdf"; 98 | } else if (filelist[index].endsWith('.gif')) { 99 | params2.ContentType = "image/gif"; 100 | } else if (filelist[index].endsWith('.svg')) { 101 | params2.ContentType = "image/svg+xml"; 102 | }; 103 | 104 | s3.putObject(params2, function(err, data) { 105 | if (err) { 106 | console.log(err); 107 | return cb(['error copying ', [filelist[index]].join('/'), '\n', err] 108 | .join( 109 | ''), 110 | null); 111 | } 112 | 113 | console.log([ 114 | [filelist[index]].join('/'), 'uploaded successfully' 115 | ].join(' ')); 116 | let _next = index + 1; 117 | uploadToS3(filelist, _next, destS3Bucket, destS3KeyPrefix, function(err, resp) { 118 | if (err) { 119 | return cb(err, null); 120 | } 121 | 122 | cb(null, resp); 123 | }); 124 | }); 125 | } else { 126 | cb(null, [index, 'files copied'].join(' ')); 127 | } 128 | } 129 | return websiteHelper; 130 | 131 | })(); 132 | 133 | module.exports = websiteHelper; -------------------------------------------------------------------------------- /template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Description: > 3 | Amazon Connect user hierarchy APIs demo 4 | 5 | Mappings: 6 | FunctionMap: 7 | Configuration: 8 | S3Bucket: "amazon-connect-blogs2" 9 | S3Key: "2020/userhierarchyapis/" 10 | 11 | Parameters: 12 | CFS3BucketForWebSite: 13 | Default: "userhierarchyapi-website" 14 | Type: String 15 | AllowedPattern: '(?=^.{3,63}$)(?!^(\d+\.)+\d+$)(^(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$)' 16 | ConstraintDescription: 'Invalid S3 Bucket name' 17 | Description: Enter the (globally unique) name you would like to use for the Amazon S3 bucket where we will store the website assets and the sample user hierarchy. This template will fail to deploy if the bucket name you chose is currently in use. 18 | 19 | 20 | Metadata: 21 | 'AWS::CloudFormation::Interface': 22 | ParameterGroups: 23 | - Label: 24 | default: Amazon S3 Configuration 25 | Parameters: 26 | - CFS3BucketForWebSite 27 | 28 | Outputs: 29 | CloudfrontEndpoint: 30 | Description: Endpoint for Cloudfront distribution 31 | Value: !Join 32 | - '' 33 | - - 'https://' 34 | - !GetAtt [CFCloudFrontDistribution, DomainName] 35 | - '/userhierarchy.html' 36 | 37 | Resources: 38 | 39 | createWebSiteS3Bucket: 40 | Type: 'AWS::S3::Bucket' 41 | Properties: 42 | VersioningConfiguration: 43 | Status: Enabled 44 | BucketName: !Ref CFS3BucketForWebSite 45 | VersioningConfiguration: 46 | Status : Enabled 47 | BucketEncryption: 48 | ServerSideEncryptionConfiguration: 49 | - ServerSideEncryptionByDefault: 50 | SSEAlgorithm: AES256 51 | PublicAccessBlockConfiguration: 52 | BlockPublicAcls: True 53 | BlockPublicPolicy: True 54 | IgnorePublicAcls: True 55 | RestrictPublicBuckets: True 56 | WebsiteConfiguration: 57 | IndexDocument: userhierarchy.html 58 | ErrorDocument: error.html 59 | 60 | 61 | CFS3BucketPolicy: 62 | Type: AWS::S3::BucketPolicy 63 | DependsOn: 64 | - CFCloudFrontDistributionAccessIdentity 65 | Properties: 66 | Bucket: !Ref createWebSiteS3Bucket 67 | PolicyDocument: 68 | Statement: 69 | - 70 | Action: 71 | - "s3:GetObject" 72 | Effect: "Allow" 73 | Principal: 74 | CanonicalUser: 75 | Fn::GetAtt: [ CFCloudFrontDistributionAccessIdentity , S3CanonicalUserId ] 76 | Resource: 77 | !Sub ${createWebSiteS3Bucket.Arn}/userhierarchysite/* 78 | 79 | CFCloudFrontDistributionAccessIdentity: 80 | Type: AWS::CloudFront::CloudFrontOriginAccessIdentity 81 | Properties: 82 | CloudFrontOriginAccessIdentityConfig: 83 | Comment: 'CloudFront endpoint for user hierarchys s3' 84 | 85 | CFCloudFrontDistribution: 86 | Type: AWS::CloudFront::Distribution 87 | Properties: 88 | DistributionConfig: 89 | Origins: 90 | - DomainName: 91 | !Join 92 | - '' 93 | - - !Ref CFS3BucketForWebSite 94 | - .s3.amazonaws.com 95 | Id: !Ref CFS3BucketForWebSite 96 | OriginPath: '/userhierarchysite' 97 | S3OriginConfig: 98 | OriginAccessIdentity: 99 | !Join 100 | - '' 101 | - - 'origin-access-identity/cloudfront/' 102 | - !Ref CFCloudFrontDistributionAccessIdentity 103 | Enabled: 'true' 104 | Logging: 105 | Bucket: !GetAtt createWebSiteS3Bucket.DomainName 106 | Prefix: 'logs/' 107 | IncludeCookies: 'true' 108 | Comment: CloudFront for user hierarchy apis 109 | DefaultRootObject: userhierarchy.html 110 | DefaultCacheBehavior: 111 | AllowedMethods: 112 | - DELETE 113 | - GET 114 | - HEAD 115 | - OPTIONS 116 | - PATCH 117 | - POST 118 | - PUT 119 | TargetOriginId: !Ref CFS3BucketForWebSite 120 | ForwardedValues: 121 | QueryString: true 122 | Cookies: 123 | Forward: all 124 | ViewerProtocolPolicy: redirect-to-https 125 | Restrictions: 126 | GeoRestriction: 127 | RestrictionType: whitelist 128 | Locations: 129 | - US 130 | 131 | CFWebsiteCreatorRole: 132 | Type: "AWS::IAM::Role" 133 | Properties: 134 | AssumeRolePolicyDocument: 135 | Version: "2012-10-17" 136 | Statement: 137 | - 138 | Effect: "Allow" 139 | Principal: 140 | Service: 141 | - "lambda.amazonaws.com" 142 | Action: 143 | - "sts:AssumeRole" 144 | Path: "/" 145 | Policies: 146 | - 147 | PolicyName: !Sub ${AWS::StackName}-user-hierarchy-creator-policy 148 | PolicyDocument: 149 | Version: "2012-10-17" 150 | Statement: 151 | - 152 | Effect: "Allow" 153 | Action: 154 | - 'logs:CreateLogGroup' 155 | - 'logs:CreateLogStream' 156 | - 'logs:PutLogEvents' 157 | Resource: 158 | - !Sub "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*" 159 | - 160 | Effect: "Allow" 161 | Action: 162 | - "s3:PutObject" 163 | - "s3:GetObject" 164 | - "s3:PutObjectAcl" 165 | Resource: 166 | - !Join 167 | - '' 168 | - - 'arn:' 169 | - !Ref 'AWS::Partition' 170 | - ':s3:::' 171 | - !Ref CFS3BucketForWebSite 172 | - '/*' 173 | - 174 | Effect: "Allow" 175 | Action: 176 | - "s3:PutBucketPublicAccessBlock" 177 | Resource: 178 | - !Join 179 | - '' 180 | - - 'arn:' 181 | - !Ref 'AWS::Partition' 182 | - ':s3:::' 183 | - !Ref CFS3BucketForWebSite 184 | - 185 | Effect: "Allow" 186 | Action: 187 | - "s3:GetObject" 188 | Resource: 189 | - !Join 190 | - '' 191 | - - 'arn:' 192 | - !Ref 'AWS::Partition' 193 | - ':s3:::' 194 | - 'amazon-connect-blogs2' 195 | - '/*' 196 | 197 | webSiteCreator: 198 | Type: "AWS::Lambda::Function" 199 | Properties: 200 | Description: > 201 | AWS Lambda Function that will create the website and upload it to the S3 bucket 202 | Handler: "index.handler" 203 | Role: !GetAtt CFWebsiteCreatorRole.Arn 204 | Runtime: "nodejs12.x" 205 | MemorySize: 256 206 | Timeout: 120 207 | Code: ./website-creator/ 208 | 209 | invokeWebSiteCreator: 210 | Type: Custom::CreateWebSite 211 | DependsOn: createWebSiteS3Bucket 212 | Properties: 213 | ServiceToken: !GetAtt webSiteCreator.Arn 214 | customAction: configureWebsite 215 | Region: !Ref AWS::Region 216 | destS3Bucket: !Ref CFS3BucketForWebSite 217 | destS3KeyPrefix: userhierarchysite 218 | -------------------------------------------------------------------------------- /website-creator/css/style.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | border: 0; 4 | margin: 0; 5 | padding: 0; 6 | } 7 | 8 | body { 9 | font: 100% "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; 10 | min-width: 100%; 11 | min-height: 101%; 12 | color: #666; 13 | background: #eee; 14 | } 15 | 16 | p, 17 | label, 18 | legend { 19 | font: 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; 20 | } 21 | 22 | h1 { 23 | margin: 10px 0 10px; 24 | font-size: 20px; 25 | color: #333333; 26 | } 27 | 28 | hr { 29 | color: inherit; 30 | height: 0; 31 | margin: 6px 0 6px 0; 32 | padding: 0; 33 | border: 1px solid #d9d9d9; 34 | border-style: none none solid; 35 | } 36 | 37 | section { 38 | display: block; 39 | width: 800px; 40 | margin: 10px auto; 41 | padding: 35px; 42 | border: 1px solid #cbcbcb; 43 | background-color: #FFF; 44 | -webkit-border-radius: 5px; 45 | -moz-border-radius: 5px; 46 | border-radius: 5px; 47 | box-shadow: 0 2px 5px rgba(50, 50, 50, 0.1); 48 | -webkit-box-shadow: 0 2px 5px rgba(50, 50, 50, 0.1); 49 | -moz-box-shadow: 0 2px 5px rgba(50, 50, 50, 0.1); 50 | } 51 | 52 | 53 | /* Special CSS for Call Controls Section */ 54 | 55 | fieldset.salesOrder { 56 | padding: 7px; 57 | } 58 | 59 | fieldset.callControls { 60 | padding: 3px; 61 | margin: 4px; 62 | -webkit-transition: margin-left 1s ease-in-out; 63 | z-index: 1; 64 | } 65 | 66 | .callControls { 67 | margin: 2px 2px; 68 | display: inline-block; 69 | border: 1px solid #bfbfbf; 70 | border-radius: 5px 5px 5px 5px; 71 | -webkit-border-radius: 5px 5px 5px 5px; 72 | -moz-border-radius: 5px 5px 5px 5px; 73 | font: 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; 74 | width: auto; 75 | height: auto; 76 | font-size: 16px; 77 | box-shadow: inset 0 1px 0 0 #fff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2, 0 2px 4px 0 #f2f2f2; 78 | -moz-box-shadow: inset 0 1px 0 0 #fff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2, 0 2px 4px 0 #f2f2f2; 79 | -webkit-box-shadow: inset 0 1px 0 0 #fff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2, 0 2px 4px 0 #f2f2f2; 80 | text-shadow: 0 1px 0 #fff; 81 | background-image: linear-gradient(to top, #f2f2f2, #f2f2f2); 82 | background-color: #f2f2f2; 83 | } 84 | 85 | .callControls:hover, 86 | .callControls:active { 87 | border: 1px solid #8c8c8c; 88 | color: #8c8c8c; 89 | box-shadow: inset 0 1px 0 0 #ffffff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2; 90 | -moz-box-shadow: inset 0 1px 0 0 #ffffff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2; 91 | -webkit-box-shadow: inset 0 1px 0 0 #ffffff, inset 0 -1px 0 0 #d9d9d9, inset 0 0 0 1px #f2f2f2; 92 | background-color: #f2f2f2; 93 | } 94 | 95 | 96 | /* Form style */ 97 | 98 | mark.validate { 99 | display: inline-block; 100 | margin: 12px 0 0 10px; 101 | width: 16px; 102 | height: 16px; 103 | background: transparent none; 104 | } 105 | 106 | mark.valid { 107 | background: url(images/success.gif) no-repeat top left; 108 | } 109 | 110 | mark.error { 111 | background: url(images/error.gif) no-repeat top left; 112 | } 113 | 114 | form label, 115 | section label { 116 | display: inline-block; 117 | float: left; 118 | height: 1em; 119 | line-height: 1em; 120 | padding: 6px 0 0; 121 | width: 135px; 122 | font-size: 1em; 123 | margin: 5px 0; 124 | clear: both; 125 | } 126 | 127 | form label small, 128 | section label small { 129 | font-size: 0.75em; 130 | color: #ccc; 131 | } 132 | 133 | form label.verify { 134 | padding: 0; 135 | margin: 2px 10px 2px 0; 136 | width: 145px; 137 | text-align: right; 138 | } 139 | 140 | form label.verify img { 141 | padding: 1px; 142 | border: 1px solid #cccccc; 143 | -webkit-border-radius: 3px; 144 | -moz-border-radius: 3px; 145 | border-radius: 3px; 146 | } 147 | 148 | form button { 149 | width: 120px; 150 | padding: 4px; 151 | color: #666; 152 | background: #f5f5f5; 153 | border: 1px solid #ccc; 154 | margin: 5px 0; 155 | font: 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; 156 | -webkit-border-radius: 5px; 157 | -moz-border-radius: 5px; 158 | border-radius: 5px; 159 | vertical-align: top; 160 | transition: all 0.25s ease-in-out; 161 | -webkit-transition: all 0.25s ease-in-out; 162 | -moz-transition: all 0.25s ease-in-out; 163 | box-shadow: 0 0 5px rgba(81, 203, 238, 0); 164 | -webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 0); 165 | -moz-box-shadow: 0 0 5px rgba(81, 203, 238, 0); 166 | } 167 | 168 | form input, 169 | form textarea, 170 | form select, 171 | section select, 172 | section input, 173 | section textarea { 174 | width: 220px; 175 | padding: 5px; 176 | color: #666; 177 | background: #f5f5f5; 178 | border: 1px solid #ccc; 179 | margin: 5px 0; 180 | font: 1em "Lucida Grande", "Lucida Sans Unicode", Arial, sans-serif; 181 | -webkit-border-radius: 5px; 182 | -moz-border-radius: 5px; 183 | border-radius: 5px; 184 | vertical-align: top; 185 | transition: all 0.25s ease-in-out; 186 | -webkit-transition: all 0.25s ease-in-out; 187 | -moz-transition: all 0.25s ease-in-out; 188 | box-shadow: 0 0 5px rgba(81, 203, 238, 0); 189 | -webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 0); 190 | -moz-box-shadow: 0 0 5px rgba(81, 203, 238, 0); 191 | } 192 | 193 | form select { 194 | width: 232px; 195 | margin: 8px 0; 196 | } 197 | 198 | form input#verify { 199 | width: 55px; 200 | } 201 | 202 | form textarea, 203 | section textarea { 204 | width: 414px; 205 | } 206 | 207 | form input:focus, 208 | form textarea:focus, 209 | form select:focus, 210 | form button:focus, 211 | section input:focus, 212 | section textarea:focus, 213 | section select:focus { 214 | border: 1px solid #ddd; 215 | background-color: #fff; 216 | color: #333; 217 | outline: none; 218 | position: relative; 219 | z-index: 5; 220 | box-shadow: 0 0 5px rgba(81, 203, 238, 1); 221 | -webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 1); 222 | -moz-box-shadow: 0 0 5px rgba(81, 203, 238, 1); 223 | -webkit-transform: scale(1.05); 224 | -moz-transform: scale(1.05); 225 | transition: all 0.25s ease-in-out; 226 | -webkit-transition: all 0.25s ease-in-out; 227 | -moz-transition: all 0.25s ease-in-out; 228 | } 229 | 230 | form input.error, 231 | form textarea.error, 232 | form select.error { 233 | box-shadow: 0 0 5px rgba(204, 0, 0, 0.5); 234 | -webkit-box-shadow: 0 0 5px rgba(204, 0, 0, 0.5); 235 | -moz-box-shadow: 0 0 5px rgba(204, 0, 0, 0.5); 236 | border: 1px solid #faabab; 237 | background: #fef3f3 238 | } 239 | 240 | form input.submit { 241 | width: auto; 242 | cursor: pointer; 243 | position: relative; 244 | border: 1px solid #282828; 245 | color: #fff; 246 | padding: 6px 16px; 247 | text-decoration: none; 248 | font-size: 1.1em; 249 | background: #555; 250 | background: -webkit-gradient( linear, left bottom, left top, color-stop(0.12, rgb(60, 60, 60)), color-stop(1, rgb(85, 85, 85))); 251 | background: -moz-linear-gradient( center bottom, rgb(60, 60, 60) 12%, rgb(85, 85, 85) 100%); 252 | box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25); 253 | -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); 254 | -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); 255 | text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25); 256 | } 257 | 258 | form input.submit:hover { 259 | background: #282828 !important; 260 | transition: none; 261 | -webkit-transition: none; 262 | -moz-transition: none; 263 | } 264 | 265 | form input.submit:active, 266 | form input.submit:focus { 267 | top: 1px; 268 | } 269 | 270 | form button.delete-comment { 271 | width: auto; 272 | cursor: pointer; 273 | position: relative; 274 | border: 1px solid #282828; 275 | color: #fff; 276 | border-radius: 5px; 277 | padding: 6px 16px; 278 | text-decoration: none; 279 | font-size: 1.1em; 280 | background: #555; 281 | background: -webkit-gradient( linear, left bottom, left top, color-stop(0.12, rgb(60, 60, 60)), color-stop(1, rgb(85, 85, 85))); 282 | background: -moz-linear-gradient( center bottom, rgb(60, 60, 60) 12%, rgb(85, 85, 85) 100%); 283 | box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25); 284 | -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); 285 | -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); 286 | text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25); 287 | } 288 | 289 | .copy { 290 | width: 30px; 291 | height: 29px; 292 | padding: 5px; 293 | color: #666; 294 | background: #f5f5f5; 295 | border: 1px solid #ccc; 296 | margin: 5px 0; 297 | } 298 | 299 | form button.delete-comment:hover { 300 | background: #282828 !important; 301 | transition: none; 302 | -webkit-transition: none; 303 | -moz-transition: none; 304 | } 305 | 306 | form button.delete-comment:active, 307 | form button.delet-comment:focus { 308 | top: 1px; 309 | } 310 | 311 | form button:hover { 312 | background: #eeeeee; 313 | transition: none; 314 | -webkit-transition: none; 315 | -moz-transition: none; 316 | } 317 | 318 | form input[type="submit"][disabled] { 319 | background: #888; 320 | } 321 | 322 | form fieldset { 323 | padding: 7px; 324 | border: 1px solid #eee; 325 | -webkit-border-radius: 5px; 326 | -moz-border-radius: 5px; 327 | margin: 0 0 20px; 328 | } 329 | 330 | form legend { 331 | padding: 7px 10px; 332 | font-weight: bold; 333 | color: #000; 334 | border: 1px solid #eee; 335 | -webkit-border-radius: 5px; 336 | -moz-border-radius: 5px; 337 | margin-bottom: 0 !important; 338 | margin-bottom: 20px; 339 | } 340 | 341 | form span.required { 342 | font-size: 13px; 343 | color: #ff0000; 344 | } 345 | 346 | section span.required { 347 | font-size: 13px; 348 | color: #ff0000; 349 | } 350 | 351 | fieldset { 352 | padding: 20px; 353 | border: 1px solid #eee; 354 | -webkit-border-radius: 5px; 355 | -moz-border-radius: 5px; 356 | margin: 0 0 20px; 357 | } 358 | 359 | legend { 360 | padding: 7px 10px; 361 | font-weight: bold; 362 | color: #000; 363 | border: 1px solid #eee; 364 | -webkit-border-radius: 5px; 365 | -moz-border-radius: 5px; 366 | margin-bottom: 0 !important; 367 | margin-bottom: 20px; 368 | } 369 | 370 | #message { 371 | margin: 1em 0; 372 | padding: 0; 373 | display: block; 374 | background: transparent none; 375 | } 376 | 377 | acronym { 378 | border-bottom: 1px dotted #ccc; 379 | } -------------------------------------------------------------------------------- /website-creator/userhierarchy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Amazon Connect - User Hierarchy API's 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 |
87 |
88 | Amazon Connect User Hierarchy APIs 89 |
90 | 91 | 92 | 93 | 94 | 95 |
96 |
97 |
98 |
99 |
100 | 101 |
102 |
103 |
104 | 105 |
106 |
107 | 108 |
109 | JSON Output 110 |
111 |
112 | 113 |
114 | Waiting for server to respond 115 |
116 |
117 | 118 |
119 | 120 | 121 |
122 |
123 |
124 | User Hierarchy Configuration 125 |
126 | 127 | 128 | 129 | 132 | 135 | 136 | 137 | 140 | 143 | 144 | 145 | 148 | 151 | 152 | 153 | 156 | 159 | 160 | 161 | 164 | 167 | 168 | 169 | 170 |
130 | 131 | 133 | 134 |
138 | 139 | 141 | 142 |
146 | 147 | 149 | 150 |
154 | 155 | 157 | 158 |
162 | 163 | 165 | 166 |
171 |
172 |
173 | 174 |
175 |
176 | 177 | 178 | 179 |
180 |
181 |
182 | Enter AWS credentials for User Hierarchy Management 183 |
184 | 185 | 186 | 187 | 190 | 193 | 196 | 199 | 200 | 201 | 204 | 207 | 208 | 209 | 210 | 213 | 216 | 217 | 218 | 219 |
188 | 189 | 191 | 192 | 194 | 195 | 197 | 198 |
202 | 203 | 205 | 206 |
211 | 212 | 214 | 215 |
220 |
221 |
222 | 223 |
224 |
225 | 226 | 227 |
228 |

Are you sure you want to delete?

229 |
230 | 231 |
232 |
233 |
234 | Enter the new name for the hierarchy 235 |
236 | 237 | 238 | 239 | 242 | 247 | 250 | 253 | 254 | 255 |
240 | 241 | 243 | 244 | 245 | 246 | 248 | 249 | 251 | 252 |
256 |
257 |
258 | 259 |
260 |
261 | 262 |
263 |
264 |
265 | Enter the new name for the hierarchy 266 |
267 | 268 | 269 | 270 | 274 | 277 | 278 | 279 |
271 | 272 | 273 | 275 | 276 |
280 |
281 |
282 | 283 |
284 |
285 | 286 | 287 | 288 | -------------------------------------------------------------------------------- /website-creator/js/userhierarchy.js: -------------------------------------------------------------------------------- 1 | 2 | var credentials; 3 | var secretKey; 4 | var accessKey; 5 | var sessionId; 6 | var connect; 7 | 8 | var uhListTable; 9 | var userHierarchyDetailsList; 10 | var uhLevelOne = []; 11 | var uhLevelTwo = []; 12 | var uhLevelThree = []; 13 | var uhLevelFour = []; 14 | var uhLevelFive = []; 15 | 16 | var rpList; 17 | var userHierarchyList; 18 | var userHierarchyStructure; 19 | var selectedGroupId; 20 | var dlgSourceAccessKey, dlgSourceSecretKey, dlgSourceRegion, dlgInstanceId; 21 | const GCREATE = 'CREATE'; 22 | const GMODIFY = 'MODIFY'; 23 | const GVOICE = 'VOICE'; 24 | const GCHAT = 'CHAT'; 25 | const GSTANDARD = 'STANDARD'; 26 | 27 | // allowed will be CREATE and MODIFY 28 | var currentOperation = GCREATE; 29 | 30 | $( document ).ready(function() { 31 | if (!checkCookie()) { 32 | setAWSConfig(dlgSourceAccessKey, dlgSourceSecretKey, dlgSourceRegion); 33 | setupAll(); 34 | } else { 35 | setupAll(); 36 | $( "#configDialog" ).dialog( "open" ); 37 | } 38 | }); 39 | 40 | function setupAll() { 41 | loadConnectAPIs(); 42 | 43 | 44 | $("#listUH").click(() => { 45 | getListUserHierarchies(); 46 | }); 47 | $("#listUH2").click(() => { 48 | getListUserHierarchyGroups(); 49 | }); 50 | $("#describeUHS").click(() => { 51 | getDescribeUserHierarchyStructure(); 52 | }); 53 | 54 | 55 | 56 | $("#btnRenameHierarchy").click(() => { 57 | changeUserHierarchyGroupName(); 58 | }); 59 | $("#btnAddHierarchy").click(() => { 60 | addUserHierarchyGroupName(); 61 | }); 62 | $("#btnSaveUHS").click(() => { 63 | saveUserHierarchyStructure(); 64 | }); 65 | 66 | 67 | $("#manageUHS").click(() => { 68 | setupUHStructure(); 69 | $( "#uhStructureDialog" ).dialog( "open" ); 70 | }); 71 | 72 | $("#awsConfiguration").click(() => { 73 | $( "#configDialog" ).dialog( "open" ); 74 | }); 75 | 76 | $("#btnConfiguration").click(() => { 77 | if (saveCookie()) { 78 | $( "#configDialog" ).dialog( "close" ); 79 | } else { 80 | $( "#configDialog" ).dialog( "open" ); 81 | } 82 | }); 83 | 84 | $("#dialog").dialog({ 85 | autoOpen: false, 86 | modal: true 87 | }); 88 | 89 | $("#resultDialog").dialog({ 90 | autoOpen: false, 91 | modal: true 92 | }); 93 | 94 | 95 | $('#configDialog').dialog({ 96 | autoOpen: false, 97 | width: 850, 98 | modal: true, 99 | resizable: false, 100 | height: "auto" 101 | }); 102 | 103 | $('#uhStructureDialog').dialog({ 104 | autoOpen: false, 105 | width: 850, 106 | modal: true, 107 | resizable: false, 108 | height: "auto" 109 | }); 110 | 111 | 112 | $('#addUHDialog').dialog({ 113 | autoOpen: false, 114 | modal: true, 115 | resizable: false, 116 | width: "auto", 117 | height: "auto", 118 | buttons: { 119 | "Yes": function() { 120 | $( this ).dialog( "close" ); 121 | addUserHierarchy(); 122 | }, 123 | Cancel: function() { 124 | $( this ).dialog( "close" ); 125 | } 126 | } 127 | }); 128 | 129 | 130 | $( "#confirmDialog" ).dialog({ 131 | autoOpen: false, 132 | resizable: false, 133 | height: "auto", 134 | width: 400, 135 | modal: true, 136 | buttons: { 137 | "Yes": function() { 138 | $( this ).dialog( "close" ); 139 | deleteUserHierarchy(); 140 | }, 141 | Cancel: function() { 142 | $( this ).dialog( "close" ); 143 | } 144 | } 145 | }); 146 | 147 | $('#renameDialog').dialog({ 148 | autoOpen: false, 149 | width: 800, 150 | height: "auto", 151 | modal: true 152 | }); 153 | 154 | $('#addDialog').dialog({ 155 | autoOpen: false, 156 | width: 800, 157 | height: "auto", 158 | modal: true 159 | }); 160 | 161 | uhListTable = $('#uhListTable').DataTable({ 162 | columnDefs: [ 163 | { 164 | targets: -1, 165 | className: 'dt-body-right' 166 | } 167 | ], 168 | columns: [{title: "Name"}], 169 | select: true, 170 | paging: false, 171 | info: false, 172 | searching: false 173 | }); 174 | 175 | getDescribeUserHierarchyStructure(); 176 | 177 | } 178 | 179 | function setupUHStructure(){ 180 | if(userHierarchyStructure.HierarchyStructure.LevelOne) 181 | $("#dlgUHSLevelOne").val(userHierarchyStructure.HierarchyStructure.LevelOne.Name); 182 | if(userHierarchyStructure.HierarchyStructure.LevelTwo) 183 | $("#dlgUHSLevelTwo").val(userHierarchyStructure.HierarchyStructure.LevelTwo.Name) ; 184 | if(userHierarchyStructure.HierarchyStructure.LevelThree) 185 | $("#dlgUHSLevelThree").val(userHierarchyStructure.HierarchyStructure.LevelThree.Name) ; 186 | if(userHierarchyStructure.HierarchyStructure.LevelFour) 187 | $("#dlgUHSLevelFour").val(userHierarchyStructure.HierarchyStructure.LevelFour.Name) ; 188 | if(userHierarchyStructure.HierarchyStructure.LevelFive) 189 | $("#dlgUHSLevelFive").val(userHierarchyStructure.HierarchyStructure.LevelFive.Name); 190 | 191 | } 192 | 193 | async function saveUserHierarchyStructure(){ 194 | try { 195 | handleWindow(true, ''); 196 | var structure = {}; 197 | if($('#dlgUHSLevelOne').val().length > 1) 198 | structure["LevelOne"] = {"Name" : $('#dlgUHSLevelOne').val()}; 199 | if($('#dlgUHSLevelTwo').val().length > 1) 200 | structure["LevelTwo"] = {"Name" : $('#dlgUHSLevelTwo').val()}; 201 | if($('#dlgUHSLevelThree').val().length > 1) 202 | structure["LevelThree"] = {"Name" : $('#dlgUHSLevelThree').val()}; 203 | if($('#dlgUHSLevelFour').val().length > 1) 204 | structure["LevelFour"] = {"Name" : $('#dlgUHSLevelFour').val()}; 205 | if($('#dlgUHSLevelFive').val().length > 1) 206 | structure["LevelFive"] = {"Name" : $('#dlgUHSLevelFive').val()}; 207 | var l = await updateUserHierarchyStructure(dlgInstanceId, structure); 208 | handleWindow(false, ''); 209 | } catch(e) { 210 | console.log(e); 211 | handleWindow(false, ''); 212 | showResults(e); 213 | } 214 | 215 | } 216 | 217 | 218 | async function getDescribeUserHierarchyStructure(){ 219 | try { 220 | handleWindow(true, ''); 221 | userHierarchyStructure = await describeUserHierarchyStructure(dlgInstanceId); 222 | console.log(userHierarchyStructure); 223 | var uhs='User hierarcy structure : '; 224 | if(userHierarchyStructure.HierarchyStructure.LevelOne) 225 | uhs= uhs + userHierarchyStructure.HierarchyStructure.LevelOne.Name ; 226 | if(userHierarchyStructure.HierarchyStructure.LevelTwo) 227 | uhs = uhs + "/" + userHierarchyStructure.HierarchyStructure.LevelTwo.Name; 228 | if(userHierarchyStructure.HierarchyStructure.LevelThree) 229 | uhs = uhs + "/" + userHierarchyStructure.HierarchyStructure.LevelThree.Name; 230 | if(userHierarchyStructure.HierarchyStructure.LevelFour) 231 | uhs = uhs + "/" + userHierarchyStructure.HierarchyStructure.LevelFour.Name; 232 | if(userHierarchyStructure.HierarchyStructure.LevelFive) 233 | uhs = uhs + "/" + userHierarchyStructure.HierarchyStructure.LevelFive.Name; 234 | 235 | $('#spnUHS').html(uhs); 236 | formatJSON(userHierarchyStructure, '#rpFormatted'); 237 | handleWindow(false, ''); 238 | } catch(e) { 239 | console.log(e); 240 | handleWindow(false, ''); 241 | showResults(e); 242 | } 243 | 244 | } 245 | 246 | async function getListUserHierarchies() { 247 | try { 248 | handleWindow(true, ''); 249 | userHierarchyList = await listUserHierarchyGroups(dlgInstanceId); 250 | console.log(userHierarchyList); 251 | formatJSON(userHierarchyList, '#rpFormatted'); 252 | handleWindow(false, ''); 253 | } catch(e) { 254 | console.log(e); 255 | handleWindow(false, ''); 256 | showResults(e); 257 | } 258 | 259 | } 260 | async function getListUserHierarchyGroups() { 261 | try { 262 | handleWindow(true, ''); 263 | userHierarchyList = await listUserHierarchyGroups(dlgInstanceId); 264 | console.log(userHierarchyList); 265 | formatJSON(userHierarchyList, '#rpFormatted'); 266 | var uhLevelOne = '
' + userHierarchyStructure.HierarchyStructure.LevelOne.Name + '
'; 267 | userHierarchyDetailsList = []; 268 | for (var i=0; i< userHierarchyList.UserHierarchyGroupSummaryList.length; i++) { 269 | var l = await describeUserHierarchyGroup(dlgInstanceId, userHierarchyList.UserHierarchyGroupSummaryList[i].Id) 270 | console.log(l); 271 | userHierarchyDetailsList.push(l); 272 | } 273 | loadHierarchy("1"); 274 | handleWindow(false, ''); 275 | } catch(e) { 276 | console.log(e); 277 | handleWindow(false, ''); 278 | showResults(e); 279 | } 280 | 281 | } 282 | 283 | function loadHierarchy(level, parentGroupId, parentName) { 284 | var uhLevel = ""; 285 | var uhStructure=""; 286 | var addNewGroup =""; 287 | var uhHierarchy = ""; 288 | var uhParentGroupDetails; 289 | var uhChildGroupId=""; 290 | var uhStructureName = ""; 291 | try{ 292 | if(parseInt(level)>5) 293 | return; 294 | for(var i=0; i < userHierarchyDetailsList.length; i++) { 295 | var l = userHierarchyDetailsList[i]; 296 | if(l.HierarchyGroup.LevelId === level) { 297 | var groupId = l.HierarchyGroup.Id; 298 | var pGroupId=""; 299 | if(level === "1") { 300 | pGroupId = l.HierarchyGroup.HierarchyPath.LevelOne.Id; 301 | uhChildGroupId = l.HierarchyGroup.HierarchyPath.LevelOne.Id; 302 | uhStructureName = l.HierarchyGroup.HierarchyPath.LevelOne.Name 303 | } 304 | if(level === "2") { 305 | pGroupId = l.HierarchyGroup.HierarchyPath.LevelOne.Id; 306 | uhChildGroupId = l.HierarchyGroup.HierarchyPath.LevelTwo.Id; 307 | uhStructureName = l.HierarchyGroup.HierarchyPath.LevelTwo.Name 308 | } 309 | 310 | if(level === "3") { 311 | pGroupId = l.HierarchyGroup.HierarchyPath.LevelTwo.Id; 312 | uhChildGroupId = l.HierarchyGroup.HierarchyPath.LevelThree.Id; 313 | uhStructureName = l.HierarchyGroup.HierarchyPath.LevelThree.Name 314 | } 315 | 316 | if(level === "4") { 317 | pGroupId = l.HierarchyGroup.HierarchyPath.LevelThree.Id; 318 | uhChildGroupId = l.HierarchyGroup.HierarchyPath.LevelFour.Id; 319 | uhStructureName = l.HierarchyGroup.HierarchyPath.LevelFour.Name 320 | } 321 | 322 | if(level === "5") { 323 | pGroupId = l.HierarchyGroup.HierarchyPath.LevelFour.Id; 324 | uhChildGroupId = l.HierarchyGroup.HierarchyPath.LevelFive.Id; 325 | uhStructureName = l.HierarchyGroup.HierarchyPath.LevelFive.Name 326 | } 327 | 328 | 329 | if(parentGroupId) { 330 | if(parentGroupId === pGroupId) { 331 | uhParentGroupDetails =l; 332 | var groupName = '' + l.HierarchyGroup.Name + ''; 333 | var renameLink = 'Rename / '; 334 | var deleteLink = 'Delete'; 335 | uhLevel += '
' + groupName + renameLink + deleteLink + '
'; 336 | } 337 | }else { 338 | uhParentGroupDetails =l; 339 | var groupName = '' + l.HierarchyGroup.Name + ''; 340 | var renameLink = 'Rename / '; 341 | var deleteLink = 'Delete'; 342 | uhLevel += '
' + groupName + renameLink + deleteLink + '
'; 343 | } 344 | } 345 | } 346 | if(uhParentGroupDetails) { 347 | 348 | if(level === "1") { 349 | uhStructure = '
' + userHierarchyStructure.HierarchyStructure.LevelOne.Name + '
'; 350 | addNewGroup = '
Add ' + userHierarchyStructure.HierarchyStructure.LevelOne.Name + '
'; 351 | uhHierarchy= '
-
'; 352 | } 353 | if(level === "2") { 354 | uhStructure = '
' + userHierarchyStructure.HierarchyStructure.LevelOne.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelTwo.Name + '
'; 355 | addNewGroup = '
Add ' + userHierarchyStructure.HierarchyStructure.LevelTwo.Name + '
'; 356 | uhHierarchy = '
- / '; 357 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelOne.Name + ' / '; 358 | uhHierarchy += '
'; 359 | } 360 | if(level === "3") { 361 | uhStructure = '
' + userHierarchyStructure.HierarchyStructure.LevelOne.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelTwo.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelThree.Name + '
'; 362 | addNewGroup = '
Add ' + userHierarchyStructure.HierarchyStructure.LevelThree.Name + '
'; 363 | uhHierarchy = '
- / '; 364 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelOne.Name + ' / '; 365 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelTwo.Name + ' / ' 366 | uhHierarchy += '
'; 367 | 368 | } 369 | if(level === "4") { 370 | uhStructure = '
' + userHierarchyStructure.HierarchyStructure.LevelOne.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelTwo.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelThree.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelFour.Name + '
'; 371 | addNewGroup = '
Add ' + userHierarchyStructure.HierarchyStructure.LevelFour.Name + '
'; 372 | uhHierarchy = '
- / '; 373 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelOne.Name + ' / '; 374 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelTwo.Name + ' / ' 375 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelThree.Name + ' / ' 376 | uhHierarchy += '
'; 377 | 378 | } 379 | if(level === "5") { 380 | uhStructure = '
' + userHierarchyStructure.HierarchyStructure.LevelOne.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelTwo.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelThree.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelFour.Name + '/' + userHierarchyStructure.HierarchyStructure.LevelFive.Name + '
'; 381 | addNewGroup = '
Add ' + userHierarchyStructure.HierarchyStructure.LevelFive.Name + '
'; 382 | uhHierarchy = '
- / '; 383 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelOne.Name + ' / '; 384 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelTwo.Name + ' / ' 385 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelThree.Name + ' / ' 386 | uhHierarchy += '' + uhParentGroupDetails.HierarchyGroup.HierarchyPath.LevelFour.Name + ' / ' 387 | uhHierarchy += '
'; 388 | 389 | } 390 | }else{ 391 | var l = parseInt(level); 392 | if( l === 1) 393 | uhStructure = userHierarchyStructure.HierarchyStructure.LevelOne.Name; 394 | else if( l === 2) 395 | uhStructure = userHierarchyStructure.HierarchyStructure.LevelTwo.Name; 396 | else if( l === 3) 397 | uhStructure = userHierarchyStructure.HierarchyStructure.LevelThree.Name; 398 | else if( l === 4) 399 | uhStructure = userHierarchyStructure.HierarchyStructure.LevelFour.Name; 400 | else if( l === 5) 401 | uhStructure = userHierarchyStructure.HierarchyStructure.LevelFive.Name; 402 | 403 | if(parentGroupId === undefined || !parentGroupId) { 404 | parentGroupId = ""; 405 | } 406 | if(parentName === undefined || !parentName) { 407 | parentName = ""; 408 | } 409 | 410 | addNewGroup = '
Add ' + uhStructure + '
'; 411 | uhStructure = '
' + $('.structure').text() + '/' + uhStructure + '
'; 412 | $('.hierarchy').append('' + parentName + ''); 413 | if($('.hierarchy').html() === undefined || $('.hierarchy').html() === "undefined") { 414 | uhHierarchy = '
-
'; 415 | } else { 416 | uhHierarchy = '
' + $('.hierarchy').html() + '
'; 417 | } 418 | 419 | } 420 | var uhAll = uhStructure + uhHierarchy + uhLevel + addNewGroup; 421 | if(uhAll.length > 1) 422 | $('#divContainer').html(uhAll); 423 | 424 | }catch(e){ 425 | console.log(e); 426 | } 427 | 428 | } 429 | 430 | function handleRenameWindow(groupId, oldName, level){ 431 | $('#dlgOldName').val(oldName); 432 | $('#dlgGroupId').val(groupId); 433 | $('#dlgGroupLevel').val(level); 434 | $( "#renameDialog" ).dialog( "open" ); 435 | } 436 | 437 | function addNewGroup(groupId){ 438 | $('#dlgGroupIdNew').val(groupId); 439 | $( "#addDialog" ).dialog( "open" ); 440 | } 441 | 442 | async function changeUserHierarchyGroupName(){ 443 | try{ 444 | handleWindow(true, ''); 445 | var groupId = $('#dlgGroupId').val(); 446 | var groupName = $('#dlgNewName').val(); 447 | var level = $('#dlgGroupLevel').val(); 448 | var l = await updateUserHierarchyGroupName(dlgInstanceId, groupId, groupName); 449 | console.log(l); 450 | for(var i=0; i < userHierarchyDetailsList.length; i++){ 451 | var uh = userHierarchyDetailsList[i]; 452 | if(userHierarchyDetailsList[i].HierarchyGroup.Id === groupId){ 453 | uh.HierarchyGroup.Name = groupName; 454 | if(level === "1") 455 | userHierarchyDetailsList[i].HierarchyGroup.HierarchyPath.LevelOne.Name = groupName; 456 | if(level === "2") 457 | userHierarchyDetailsList[i].HierarchyGroup.HierarchyPath.LevelTwo.Name = groupName; 458 | if(level === "3") 459 | userHierarchyDetailsList[i].HierarchyGroup.HierarchyPath.LevelThree.Name = groupName; 460 | if(level === "4") 461 | userHierarchyDetailsList[i].HierarchyGroup.HierarchyPath.LevelFour.Name = groupName; 462 | if(level === "5") 463 | userHierarchyDetailsList[i].HierarchyGroup.HierarchyPath.LevelFive.Name = groupName; 464 | }else{ 465 | if(uh.HierarchyGroup.HierarchyPath.LevelOne && uh.HierarchyGroup.HierarchyPath.LevelOne.Id === groupId){ 466 | uh.HierarchyGroup.HierarchyPath.LevelOne.Name = groupName; 467 | }else if(uh.HierarchyGroup.HierarchyPath.LevelTwo && uh.HierarchyGroup.HierarchyPath.LevelTwo.Id === groupId){ 468 | uh.HierarchyGroup.HierarchyPath.LevelTwo.Name = groupName; 469 | }else if(uh.HierarchyGroup.HierarchyPath.LevelThree && uh.HierarchyGroup.HierarchyPath.LevelThree.Id === groupId){ 470 | uh.HierarchyGroup.HierarchyPath.LevelThree.Name = groupName; 471 | }else if(uh.HierarchyGroup.HierarchyPath.LevelFour && uh.HierarchyGroup.HierarchyPath.LevelFour.Id === groupId){ 472 | uh.HierarchyGroup.HierarchyPath.LevelFour.Name = groupName; 473 | }else if(uh.HierarchyGroup.HierarchyPath.LevelFive && uh.HierarchyGroup.HierarchyPath.LevelFive.Id === groupId){ 474 | uh.HierarchyGroup.HierarchyPath.LevelFive.Name = groupName; 475 | } 476 | } 477 | } 478 | handleWindow(false, ''); 479 | $( "#renameDialog" ).dialog( "close" ); 480 | } catch(e) { 481 | console.log(e); 482 | handleWindow(false, ''); 483 | showResults(e); 484 | } 485 | } 486 | 487 | async function addUserHierarchyGroupName() { 488 | try{ 489 | handleWindow(true, ''); 490 | var groupId=$('#dlgGroupIdNew').val(); 491 | if(!groupId || groupId === undefined || groupId === "undefined") { 492 | groupId =""; 493 | } 494 | var l = await createUserHierarchyGroup(dlgInstanceId, $('#dlgAddName').val(), groupId); 495 | console.log(l); 496 | getListUserHierarchyGroups(); 497 | $( "#addDialog" ).dialog( "close" ); 498 | } catch(e) { 499 | console.log(e); 500 | handleWindow(false, ''); 501 | showResults(e); 502 | } 503 | } 504 | 505 | function deleteUserHierarchyConfirmation(groupId) { 506 | selectedGroupId = groupId; 507 | $( "#confirmDialog" ).dialog('open'); 508 | } 509 | 510 | async function deleteUserHierarchy(){ 511 | try{ 512 | handleWindow(true, ''); 513 | var l = await deleteUserHierarchyGroup(dlgInstanceId, selectedGroupId); 514 | console.log(l); 515 | getListUserHierarchyGroups(); 516 | } catch(e) { 517 | console.log(e); 518 | handleWindow(false, ''); 519 | showResults(e); 520 | } 521 | 522 | } 523 | 524 | const listUserHierarchyGroups = (instanceId) => { 525 | return new Promise((resolve,reject) => { 526 | var params = {InstanceId : instanceId}; 527 | console.log(params); 528 | connect.listUserHierarchyGroups(params, function (err, res) { 529 | if (err) 530 | reject(err); 531 | else 532 | resolve(res); 533 | }); 534 | }); 535 | } 536 | 537 | const createUserHierarchyGroup = (instanceId, name, parentGroupId) => { 538 | return new Promise((resolve,reject) => { 539 | var params = {InstanceId : instanceId, Name : name, ParentGroupId : parentGroupId}; 540 | console.log(params); 541 | connect.createUserHierarchyGroup(params, function (err, res) { 542 | if (err) 543 | reject(err); 544 | else 545 | resolve(res); 546 | }); 547 | }); 548 | } 549 | 550 | const updateUserHierarchyGroupName = (instanceId, hierarchyGroupId, name) => { 551 | return new Promise((resolve,reject) => { 552 | var params = {Name : name, HierarchyGroupId : hierarchyGroupId, InstanceId : instanceId}; 553 | console.log(params); 554 | connect.updateUserHierarchyGroupName(params, function (err, res) { 555 | if (err) 556 | reject(err); 557 | else 558 | resolve(res); 559 | }); 560 | }); 561 | } 562 | 563 | 564 | const deleteUserHierarchyGroup = (instanceId, hierarchyGroupId) => { 565 | return new Promise((resolve,reject) => { 566 | var params = {InstanceId : instanceId, HierarchyGroupId : hierarchyGroupId}; 567 | console.log(params); 568 | connect.deleteUserHierarchyGroup(params, function (err, res) { 569 | if (err) 570 | reject(err); 571 | else 572 | resolve(res); 573 | }); 574 | }); 575 | } 576 | 577 | //This provides the template for the hierarchies 578 | const describeUserHierarchyStructure = (instanceId) => { 579 | return new Promise((resolve,reject) => { 580 | var params = {InstanceId : instanceId}; 581 | console.log(params); 582 | connect.describeUserHierarchyStructure(params, function (err, res) { 583 | if (err) 584 | reject(err); 585 | else 586 | resolve(res); 587 | }); 588 | }); 589 | } 590 | 591 | const describeUserHierarchyGroup = (instanceId, hierarchyGroupId ) => { 592 | return new Promise((resolve,reject) => { 593 | var params = {InstanceId : instanceId, HierarchyGroupId : hierarchyGroupId }; 594 | console.log(params); 595 | connect.describeUserHierarchyGroup(params, function (err, res) { 596 | if (err) 597 | reject(err); 598 | else 599 | resolve(res); 600 | }); 601 | }); 602 | } 603 | 604 | const updateUserHierarchyStructure = (instanceId, hierarchyStructure ) => { 605 | return new Promise((resolve,reject) => { 606 | var params = {InstanceId : instanceId, HierarchyStructure : hierarchyStructure }; 607 | console.log(params); 608 | connect.updateUserHierarchyStructure(params, function (err, res) { 609 | if (err) 610 | reject(err); 611 | else 612 | resolve(res); 613 | }); 614 | }); 615 | } 616 | 617 | 618 | function showResults(message){ 619 | $('#resultSpan').text(message); 620 | $("#resultDialog").dialog("open"); 621 | } 622 | 623 | function loadConnectAPIs() { 624 | connect = new AWS.Connect({ region: dlgSourceRegion}); 625 | } 626 | 627 | 628 | function handleWindow(openClose, text) { 629 | if(openClose == true) { 630 | $( "#dialog" ).dialog( "open" ); 631 | } else { 632 | $( "#dialog" ).dialog( "close" ); 633 | } 634 | 635 | if(text.length>1) { 636 | $('#waitingSpan').text(text); 637 | } else { 638 | $('#waitingSpan').text(' Waiting for server to respond'); 639 | } 640 | } 641 | 642 | function setAWSConfig(accessKey, secretKey, rgn) { 643 | 644 | AWS.config.update({ 645 | accessKeyId: accessKey, secretAccessKey: secretKey, region: rgn, retryDelayOptions: {base: 600}, maxRetries : 3 646 | }); 647 | AWS.config.credentials.get(function (err) { 648 | if (err) 649 | console.log(err); 650 | else { 651 | credentials = AWS.config.credentials; 652 | getSessionToken(); 653 | } 654 | }); 655 | 656 | } 657 | 658 | function formatJSON(data, element) { 659 | $(element).html(prettyPrintJson.toHtml(data)); 660 | } 661 | 662 | 663 | function getSessionToken() { 664 | var sts = new AWS.STS(); 665 | sts.getSessionToken(function (err, data) { 666 | if (err) console.log("Error getting credentials"); 667 | else { 668 | secretKey = data.Credentials.SecretAccessKey; 669 | accessKey = data.Credentials.AccessKeyId; 670 | sessionId = data.Credentials.SessionToken; 671 | } 672 | }); 673 | } 674 | 675 | function clear_form_elements(ele) { 676 | $(':input',ele) 677 | .not(':button, :submit, :reset') 678 | .val('') 679 | .prop('checked', false) 680 | .prop('selected', false); 681 | } 682 | 683 | function saveCookie() { 684 | dlgSourceAccessKey=$("#dlgSourceAccessKey").val(); 685 | dlgSourceSecretKey=$("#dlgSourceSecretKey").val(); 686 | dlgSourceRegion=$("#dlgSourceRegion").val(); 687 | dlgInstanceId = $("#dlgInstanceId").val(); 688 | if(!checkAllMandatoryFields()) { 689 | setCookie("dlgSourceAccessKey", dlgSourceAccessKey,100); 690 | setCookie("dlgSourceSecretKey", dlgSourceSecretKey,100 ); 691 | setCookie("dlgSourceRegion", dlgSourceRegion,100); 692 | setCookie("dlgInstanceId", dlgInstanceId,100); 693 | $('#spnAWSMessage').text(''); 694 | setAWSConfig(dlgSourceAccessKey, dlgSourceSecretKey, dlgSourceRegion); 695 | return true; 696 | }else{ 697 | $('#spnAWSMessage').text('All fields are mandatory and cannot be whitespaces or null'); 698 | return false; 699 | } 700 | } 701 | 702 | function getCookie(c_name) 703 | { 704 | var i,x,y,ARRcookies=document.cookie.split(";"); 705 | for (i=0;i