Merge "Fix sql injection vulnerability"
[portal.git] / ecomp-portal-FE-common / client / app / views / users / new-user-dialogs / bulk-user.controller.js
index 8c9420d..ae3907b 100644 (file)
@@ -1,21 +1,39 @@
 /*-
- * ================================================================================
- * ECOMP Portal
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
  * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
+ *             http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * ================================================================================
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *             https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * 
  */
 /**
  * bulk user upload controller
@@ -23,7 +41,7 @@
 'use strict';
 (function () {
     class BulkUserModalCtrl {
-       constructor($scope, $log, $filter, $q, usersService, applicationsService, confirmBoxService, functionalMenuService, ngDialog) {
+       constructor($scope, $log, $filter, $q, usersService, applicationsService, confirmBoxService, functionalMenuService, ngDialog,$modal) {
                
                // Set to true for copious console output
                var debug = false;
@@ -47,6 +65,8 @@
 
                        // Flag that indicates background work is proceeding
                        $scope.isProcessing = true;
+                       
+                       $scope.isProcessedRecords = false;
 
                        // Load user's admin applications
                        applicationsService.getAdminApps().promise().then(apps => {
                         $scope.selectedApplication = $scope.adminApps[0];
                     }
                                $scope.isProcessing = false;
+                               $scope.isProcessedRecords = false;
                 }).catch(err => {
                     $log.error('BulkUserModalCtrl::init: getAdminApps threw', err);
                        $scope.isProcessing = false;
+                       $scope.isProcessedRecords = false;
                 });
                        
                }; // init
                
                // Caches the file name supplied by the event handler.
                $scope.fileChangeHandler = (event, files) => {
-                       this.fileSelected = true;
-                       this.fileToRead = files[0];
+                       var fileName = files[0].name;
+                   var validFormats = ['csv', 'txt'];
+                   //Get file extension
+                   var ext = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase(); 
+                   //Check for valid format
+                   if(validFormats.indexOf(ext) == -1){
+                       this.fileSelected = false;
+                   }else{
+                       this.fileSelected = true;
+                       this.fileToRead = files[0];
+                   }
                        if (debug)
                                $log.debug("BulkUserModalCtrl::fileChangeHandler: file is ", this.fileToRead);
                }; // file change handler
                 */
                $scope.readValidateFile = () => {
                        $scope.isProcessing = true;
+                       $scope.conformMsg = '';
+                       $scope.isProcessedRecords = true;
                        $scope.progressMsg = 'Reading upload file..';
                        var reader = new FileReader();
                        reader.onload = function(event) {
                                                                $log.debug('BulkUserModalCtrl::readValidateFile inner-then ends');
                                                        $scope.progressMsg = 'Done.';
                                                        $scope.isProcessing = false;
+                                                       $scope.isProcessedRecords = false;
                                },
                                function(error) {
                                        $log.error('BulkUserModalCtrl::readValidateFile: failed retrieving user-app roles');
                                                        $scope.isProcessing = false;
+                                                       $scope.isProcessedRecords = false;
                                }
                                ); // then of app promises
                        },
                        function(error) {
                                $log.error('BulkUserModalCtrl::readValidateFile: failed retrieving user info');
                                $scope.isProcessing = false;
+                               $scope.isProcessedRecords = false;
                        }
                        ); // then of user promises
                     },
                     function(error) {
                        $log.error('BulkUserModalCtrl::readValidateFile: failed retrieving app role info');
                        $scope.isProcessing = false;
+                       $scope.isProcessedRecords = false;
                     }
                     ); // then of role promise
            
                                if (prevRow == null || prevRow.orgUserId.toLowerCase() !== uploadRow.orgUserId.toLowerCase()) {
                                 if (debug)
                                         $log.debug('BulkUserModalCtrl::buildAppRoleChecks: create request for orgUserId ' + uploadRow.orgUserId);
-                                let appPromise = usersService.getUserAppRoles(appId, uploadRow.orgUserId,true).promise().then( (userAppRolesResult) => {
+                                let appPromise = usersService.getUserAppRoles(appId, uploadRow.orgUserId,true, false).promise().then( (userAppRolesResult) => {
                                         // Reply for unknown user has all defined roles with isApplied=false on each.  
                                         if (typeof userAppRolesResult[0] !== "undefined") {
                                                 if (debug)
                 */
                $scope.updateDB = () => {
                        $scope.isProcessing = true;
+                       $scope.conformMsg = '';
+                       $scope.isProcessedRecords = true;
                        $scope.progressMsg = 'Sending requests to application..';
                        if (debug)
                                $log.debug('BulkUserModalCtrl::updateDB: request length is ' + appUserRolesRequest.length);
                        
                 // Run all the promises
                 $q.all(promises).then(function(){
+                        $scope.conformMsg  = 'Processed ' + numberUsersSucceeded + ' users.';
                         $scope.isProcessing = false;
-                        confirmBoxService.showInformation('Processed ' + numberUsersSucceeded + ' users.').then(isConfirmed => {
-                                // Close the upload-confirm dialog
-                                ngDialog.close();
-                        });
+                        $scope.isProcessedRecords = true;
+                        $scope.uploadFile = [];
+                       
                 });
              }; // updateDb
              
                // Start the process
                $scope.readValidateFile();
                // Dialog shows progress
-               ngDialog.open({
-                       templateUrl: 'app/views/users/new-user-dialogs/bulk-user.confirm.html',
-                       scope: $scope
-               });
+               $modal.open({
+                       templateUrl: 'app/views/users/new-user-dialogs/bulk-user.confirm.html',
+                    controller: '',
+                    sizeClass: 'modal-medium', 
+                    resolve:'',
+                    scope: $scope
+                })
              };
 
              // Invoked by the Cancel button on the confirmation dialog.
              init();
        } // constructor
     } // class
-    BulkUserModalCtrl.$inject = ['$scope', '$log', '$filter', '$q', 'usersService', 'applicationsService', 'confirmBoxService', 'functionalMenuService', 'ngDialog'];    
+    BulkUserModalCtrl.$inject = ['$scope', '$log', '$filter', '$q', 'usersService', 'applicationsService', 'confirmBoxService', 'functionalMenuService', 'ngDialog','$modal'];    
     angular.module('ecompApp').controller('BulkUserModalCtrl', BulkUserModalCtrl);
 
     angular.module('ecompApp').directive('fileChange', ['$parse', function($parse){