From 37c021b530cb762f6791d72e888338c6037670c3 Mon Sep 17 00:00:00 2001 From: will Date: Wed, 18 Nov 2015 17:41:15 -0500 Subject: [PATCH 001/135] initial skeleton - partially working --- app/common/common-module.js | 1 + app/common/directives/collection-selector.js | 113 ++++++++++++++++++ app/post/directives/post-preview-directive.js | 86 +------------ package.json | 2 +- .../collection-selector.html | 29 +++++ server/www/templates/posts/detail.html | 33 ++--- 6 files changed, 153 insertions(+), 111 deletions(-) create mode 100644 app/common/directives/collection-selector.js create mode 100644 server/www/templates/collection-selector/collection-selector.html diff --git a/app/common/common-module.js b/app/common/common-module.js index 9d669bcf64..4df8397d11 100644 --- a/app/common/common-module.js +++ b/app/common/common-module.js @@ -36,6 +36,7 @@ angular.module('ushahidi.common', [ .controller('PageMetadata', require('./controllers/page-metadata.js')) .controller('notifier', require('./controllers/notifier.js')) +.directive('collectionSelector', require('./directives/collection-selector.js')) .directive('iconPicker', require('./directives/iconpicker.js')) .directive('firstTimeConfig', require('./directives/first-time-config.js')) diff --git a/app/common/directives/collection-selector.js b/app/common/directives/collection-selector.js new file mode 100644 index 0000000000..fabf41d107 --- /dev/null +++ b/app/common/directives/collection-selector.js @@ -0,0 +1,113 @@ +/** + * Ushahidi Angular Collection Selector directive + * Drop in directive for managing collections addition for posts + */ + +module.exports = [ +function ( +) { + var controller = [ + '$scope', + '$rootScope', + 'CollectionEndpoint', + function ( + $scope, + $rootScope, + CollectionEndpoint + ) { + $scope.showNewCollectionInput = false; + $scope.newCollection = ''; + + $scope.refreshCollections = function () { + $rootScope.$broadcast('event:collection:update'); + }; + + $scope.postInCollection = function (collection) { + return _.contains($scope.post.sets, String(collection.id)); + }; + + $scope.toggleCreateCollection = function () { + $scope.showNewCollectionInput = !$scope.showNewCollectionInput; + }; + + $scope.toggleCollection = function (selectedCollection) { + if (_.contains($scope.post.sets, String(selectedCollection.id))) { + $scope.removeFromCollection(selectedCollection); + } else { + $scope.addToCollection(selectedCollection); + } + }; + + $scope.addToCollection = function (selectedCollection) { + var collectionId = selectedCollection.id, collection = selectedCollection.name; + + CollectionEndpoint.addPost({'collectionId': collectionId, 'id': $scope.post.id}) + .$promise.then(function () { + $translate('notify.collection.add_to_collection', {collection: collection}) + .then(function (message) { + $scope.post.sets.push(String(collectionId)); + Notify.showNotificationSlider(message); + }); + }, function (errorResponse) { + Notify.showApiErrors(errorResponse); + }); + }; + + $scope.removeFromCollection = function (selectedCollection) { + var collectionId = selectedCollection.id, collection = selectedCollection.name; + + CollectionEndpoint.removePost({'collectionId': collectionId, 'id': $scope.post.id}) + .$promise + .then(function () { + $translate('notify.collection.removed_from_collection', {collection: collection}) + .then(function (message) { + $scope.post.sets = _.without($scope.post.sets, String(collectionId)); + Notify.showNotificationSlider(message); + }); + }, function (errorResponse) { + Notify.showApiErrors(errorResponse); + }); + }; + /* + scope.searchCollections = function (query) { + CollectionEndpoint.query(query) + .$promise + .then(function (result) { + }, function (errorResponse) { + Notify.showApiErrors(errorResponse); + }); + }; + + scope.clearSearch = function() { + scope.editableCollection = scope.editableCollectionCopy; + }; + */ + $scope.createNewCollection = function (collectionName) { + var collection = { + 'name': collectionName, + 'user_id': $rootScope.currentUser.userId + }; + CollectionEndpoint.save(collection) + .$promise + .then(function (collection) { + $scope.toggleCreateCollection(); + $scope.newCollection = ''; + $scope.refreshCollections(); + $scope.addToCollection(collection); + }, function (errorResponse) { + Notify.showApiErrors(errorResponse); + }); + }; + + }]; + + return { + restrict: 'E', + templateUrl: 'templates/collection-selector/collection-selector.html', + scope: { + post: '=', + editableCollections: '=' + }, + controller: controller + }; +}]; diff --git a/app/post/directives/post-preview-directive.js b/app/post/directives/post-preview-directive.js index 50514d12c1..0b87118ece 100644 --- a/app/post/directives/post-preview-directive.js +++ b/app/post/directives/post-preview-directive.js @@ -3,7 +3,6 @@ module.exports = [ '$q', '$filter', '$rootScope', - 'CollectionEndpoint', 'PostEndpoint', 'TagEndpoint', 'UserEndpoint', @@ -17,7 +16,6 @@ function ( $q, $filter, $rootScope, - CollectionEndpoint, PostEndpoint, TagEndpoint, UserEndpoint, @@ -69,8 +67,6 @@ function ( }, templateUrl: 'templates/posts/preview.html', link: function ($scope) { - $scope.showNewCollectionInput = false; - $scope.newCollection = ''; $scope.getRoleDisplayName = RoleHelper.getRole; $scope.availableRoles = RoleHelper.roles(); @@ -84,19 +80,16 @@ function ( return 'post.publish_for_everyone'; }; - // Ensure completes stages array is numeric + $scope.updateSelectedItems = function () { $rootScope.$broadcast('event:post:selection', $scope.post); }; + // Ensure completes stages array is numeric $scope.post.completed_stages = $scope.post.completed_stages.map(function (stageId) { return parseInt(stageId); }); - $scope.toggleCreateCollection = function () { - $scope.showNewCollectionInput = !$scope.showNewCollectionInput; - }; - // Replace tags with full tag object $scope.post.tags = $scope.post.tags.map(function (tag) { return TagEndpoint.get({id: tag.id, ignore403: true}); @@ -109,49 +102,6 @@ function ( }); } - // TODO all collection code should be moved into a separate standalone widget - $scope.postInCollection = function (collection) { - return _.contains($scope.post.sets, String(collection.id)); - }; - - $scope.toggleCollection = function (selectedCollection) { - if (_.contains($scope.post.sets, String(selectedCollection.id))) { - $scope.removeFromCollection(selectedCollection); - } else { - $scope.addToCollection(selectedCollection); - } - }; - - $scope.addToCollection = function (selectedCollection) { - var collectionId = selectedCollection.id, collection = selectedCollection.name; - - CollectionEndpoint.addPost({'collectionId': collectionId, 'id': $scope.post.id}) - .$promise.then(function () { - $translate('notify.collection.add_to_collection', {collection: collection}) - .then(function (message) { - $scope.post.sets.push(String(collectionId)); - Notify.showNotificationSlider(message); - }); - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - }; - - $scope.removeFromCollection = function (selectedCollection) { - var collectionId = selectedCollection.id, collection = selectedCollection.name; - - CollectionEndpoint.removePost({'collectionId': collectionId, 'id': $scope.post.id}) - .$promise - .then(function () { - $translate('notify.collection.removed_from_collection', {collection: collection}) - .then(function (message) { - $scope.post.sets = _.without($scope.post.sets, String(collectionId)); - Notify.showNotificationSlider(message); - }); - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - }; $scope.publishPostTo = function () { // first check if stages required have been marked complete @@ -208,38 +158,6 @@ function ( }; $scope.publishRole = $scope.postIsPublishedTo(); - /* - $scope.searchCollections = function (query) { - CollectionEndpoint.query(query) - .$promise - .then(function (result) { - $scope.editableCollectionsLocal = results; - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - }; - - $scope.clearSearch = function() { - $rootScope.$broadcast('event:collection:update'); - $scope.editableCollectionsLocal = $scope.editableCollections; - }; - */ - $scope.createNewCollection = function (collectionName) { - var collection = { - 'name': collectionName, - 'user_id': $rootScope.currentUser.userId - }; - CollectionEndpoint.save(collection) - .$promise - .then(function (collection) { - $scope.addToCollection(collection); - $rootScope.$broadcast('event:collection:update'); - $scope.newCollection = ''; - $scope.toggleCreateCollection(); - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - }; // determine which stage the post is at getCurrentStage($scope.post).then(function (currentStage) { diff --git a/package.json b/package.json index 1c368d5ee8..d19f016543 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ "ng-showdown": "rjmackay/ng-showdown#patch-1", "ngGeolocation": "rjmackay/ngGeolocation", "nvd3": "novus/nvd3#v1.7.1", - "platform-pattern-library": "ushahidi/platform-pattern-library#v3.1.0", + "platform-pattern-library": "ushahidi/platform-pattern-library#gh-pages", "selection-model": "jtrussell/angular-selection-model.git", "transifex": "^1.4.3", "underscore": "^1.7.0" diff --git a/server/www/templates/collection-selector/collection-selector.html b/server/www/templates/collection-selector/collection-selector.html new file mode 100644 index 0000000000..915093b536 --- /dev/null +++ b/server/www/templates/collection-selector/collection-selector.html @@ -0,0 +1,29 @@ +
+ + global_filter.collections.collections + + +
diff --git a/server/www/templates/posts/detail.html b/server/www/templates/posts/detail.html index bfddc6fcaa..bc44d91dfc 100644 --- a/server/www/templates/posts/detail.html +++ b/server/www/templates/posts/detail.html @@ -54,32 +54,13 @@

Share --> -
- - global_filter.collections.collections - - -
+ + From 8bac9ce87a513237a4babc39ca381c72622cd167 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 19 Nov 2015 11:27:47 -0500 Subject: [PATCH 002/135] added full collection-selector - next add tests --- app/common/directives/collection-selector.js | 30 +++++-- .../controllers/post-detail-controller.js | 82 +------------------ app/post/directives/post-preview-directive.js | 3 +- .../views/post-view-list-directive.js | 10 --- server/www/templates/posts/detail.html | 1 - server/www/templates/posts/preview.html | 33 ++------ server/www/templates/views/list.html | 1 - 7 files changed, 31 insertions(+), 129 deletions(-) diff --git a/app/common/directives/collection-selector.js b/app/common/directives/collection-selector.js index fabf41d107..bea47e0608 100644 --- a/app/common/directives/collection-selector.js +++ b/app/common/directives/collection-selector.js @@ -9,19 +9,31 @@ function ( var controller = [ '$scope', '$rootScope', + '$translate', + 'Notify', 'CollectionEndpoint', + '_', function ( $scope, $rootScope, - CollectionEndpoint + $translate, + Notify, + CollectionEndpoint, + _ ) { $scope.showNewCollectionInput = false; $scope.newCollection = ''; $scope.refreshCollections = function () { - $rootScope.$broadcast('event:collection:update'); + $scope.editableCollections = CollectionEndpoint.editableByMe(); }; + $scope.editableCollections = $scope.refreshCollections(); + + $scope.$on('event:collection-selector:update', function () { + $scope.refrehCollections(); + }); + $scope.postInCollection = function (collection) { return _.contains($scope.post.sets, String(collection.id)); }; @@ -92,21 +104,25 @@ function ( .then(function (collection) { $scope.toggleCreateCollection(); $scope.newCollection = ''; - $scope.refreshCollections(); $scope.addToCollection(collection); + + // Where collection selectors can appear multiple times + // it is necessary to force a collection refresh when an update occurs + // on anyone collection selector - to ensure that newly created collections + // are available in all lists on the page. + // TODO: add caching for collections to reduce requests. + $rootScope.$broadcast('event:collection:update'); }, function (errorResponse) { Notify.showApiErrors(errorResponse); }); }; - }]; - + }]; return { restrict: 'E', templateUrl: 'templates/collection-selector/collection-selector.html', scope: { - post: '=', - editableCollections: '=' + post: '=' }, controller: controller }; diff --git a/app/post/controllers/post-detail-controller.js b/app/post/controllers/post-detail-controller.js index 3b6480f141..96d73eaa5f 100644 --- a/app/post/controllers/post-detail-controller.js +++ b/app/post/controllers/post-detail-controller.js @@ -44,6 +44,7 @@ function ( $scope.post = post; $scope.mapDataLoaded = false; $scope.availableRoles = RoleHelper.roles(); + $scope.publishedFor = function () { if ($scope.post.status === 'draft') { return 'post.publish_for_you'; @@ -176,87 +177,6 @@ function ( }); }; - $scope.refreshCollections = function () { - $scope.editableCollections = CollectionEndpoint.editableByMe(); - }; - $scope.refreshCollections(); - $scope.postInCollection = function (collection) { - return _.contains($scope.post.sets, String(collection.id)); - }; - - $scope.toggleCreateCollection = function () { - $scope.showNewCollectionInput = !$scope.showNewCollectionInput; - }; - - $scope.toggleCollection = function (selectedCollection) { - if (_.contains($scope.post.sets, String(selectedCollection.id))) { - $scope.removeFromCollection(selectedCollection); - } else { - $scope.addToCollection(selectedCollection); - } - }; - - $scope.addToCollection = function (selectedCollection) { - var collectionId = selectedCollection.id, collection = selectedCollection.name; - - CollectionEndpoint.addPost({'collectionId': collectionId, 'id': $scope.post.id}) - .$promise.then(function () { - $translate('notify.collection.add_to_collection', {collection: collection}) - .then(function (message) { - $scope.post.sets.push(String(collectionId)); - Notify.showNotificationSlider(message); - }); - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - }; - - $scope.removeFromCollection = function (selectedCollection) { - var collectionId = selectedCollection.id, collection = selectedCollection.name; - - CollectionEndpoint.removePost({'collectionId': collectionId, 'id': $scope.post.id}) - .$promise - .then(function () { - $translate('notify.collection.removed_from_collection', {collection: collection}) - .then(function (message) { - $scope.post.sets = _.without($scope.post.sets, String(collectionId)); - Notify.showNotificationSlider(message); - }); - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - }; - /* - scope.searchCollections = function (query) { - CollectionEndpoint.query(query) - .$promise - .then(function (result) { - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - }; - - scope.clearSearch = function() { - scope.editableCollection = scope.editableCollectionCopy; - }; - */ - $scope.createNewCollection = function (collectionName) { - var collection = { - 'name': collectionName, - 'user_id': $rootScope.currentUser.userId - }; - CollectionEndpoint.save(collection) - .$promise - .then(function (collection) { - $scope.toggleCreateCollection(); - $scope.newCollection = ''; - $scope.refreshCollections(); - $scope.addToCollection(collection); - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - }; - $scope.publishPostTo = function () { // first check if stages required have been marked complete var requiredStages = _.where($scope.stages, {required: true}), diff --git a/app/post/directives/post-preview-directive.js b/app/post/directives/post-preview-directive.js index 0b87118ece..1900d1f1e2 100644 --- a/app/post/directives/post-preview-directive.js +++ b/app/post/directives/post-preview-directive.js @@ -62,8 +62,7 @@ function ( replace: true, scope: { post: '=', - canSelect: '=', - editableCollections: '=' + canSelect: '=' }, templateUrl: 'templates/posts/preview.html', link: function ($scope) { diff --git a/app/post/directives/views/post-view-list-directive.js b/app/post/directives/views/post-view-list-directive.js index dd0bdd0981..a0e43e5795 100644 --- a/app/post/directives/views/post-view-list-directive.js +++ b/app/post/directives/views/post-view-list-directive.js @@ -47,21 +47,11 @@ function ( } }); - var refreshCollections = function () { - $scope.editableCollections = CollectionEndpoint.editableByMe(); - }; - $scope.$on('event:post:selection', function (event, post) { (post.selected ? $scope.selectedItems++ : $scope.selectedItems--); (post.selected ? $scope.selectedPosts.push(post) : $scope.selectedPosts = _.without($scope.selectedPosts, _.findWhere($scope.selectedPosts, {id: post.id}))); }); - $scope.$on('event:collection:update', function () { - refreshCollections(); - }); - - refreshCollections(); - $scope.deleteSelectedPosts = function () { $translate('notify.post.destroy_confirm').then(function (message) { diff --git a/server/www/templates/posts/detail.html b/server/www/templates/posts/detail.html index bc44d91dfc..642f3ad5bc 100644 --- a/server/www/templates/posts/detail.html +++ b/server/www/templates/posts/detail.html @@ -56,7 +56,6 @@

--> diff --git a/server/www/templates/posts/preview.html b/server/www/templates/posts/preview.html index 8caea7ae92..29ef78e56d 100644 --- a/server/www/templates/posts/preview.html +++ b/server/www/templates/posts/preview.html @@ -77,33 +77,12 @@

Share --> -
- - global_filter.collections.collections - - - -
+ + diff --git a/server/www/templates/views/list.html b/server/www/templates/views/list.html index dffaffcf9d..af5417361a 100644 --- a/server/www/templates/views/list.html +++ b/server/www/templates/views/list.html @@ -34,7 +34,6 @@ From fbb982a591474fd4eb0f057b13da54bc77ea548d Mon Sep 17 00:00:00 2001 From: will Date: Thu, 3 Dec 2015 19:47:32 -0500 Subject: [PATCH 003/135] basic csv importer --- app/common/locales/en.json | 4 + .../setting-data-import-controller.js | 17 ++++ .../setting-data-import-directive.js | 37 +++++++++ app/setting/services/endpoints/data-import.js | 29 +++++++ app/setting/setting-routes.js | 4 + server/www/templates/partials/main-menu.html | 1 + .../www/templates/settings/data-import.html | 34 ++++++++ test/e2e/settings/csv-basic-spec.js | 77 +++++++++++++++++++ 8 files changed, 203 insertions(+) create mode 100644 app/setting/controllers/setting-data-import-controller.js create mode 100644 app/setting/directives/setting-data-import-directive.js create mode 100644 app/setting/services/endpoints/data-import.js create mode 100644 server/www/templates/settings/data-import.html create mode 100644 test/e2e/settings/csv-basic-spec.js diff --git a/app/common/locales/en.json b/app/common/locales/en.json index 74556404b6..ddc5553658 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -439,6 +439,10 @@ } } }, + "data-import" :{ + "import" : "Import", + "import_explanation" : "Import the data from a CSV spreadsheet into your deployment as posts belonging to a specific post type." + }, "user": { "add_user" : "Add User", "edit_user" : "Edit User", diff --git a/app/setting/controllers/setting-data-import-controller.js b/app/setting/controllers/setting-data-import-controller.js new file mode 100644 index 0000000000..eeee3e78b0 --- /dev/null +++ b/app/setting/controllers/setting-data-import-controller.js @@ -0,0 +1,17 @@ +module.exports = [ + '$scope', + '$translate', + 'FormEndpoint', + 'Notify', + '_', +function ( + $scope, + $translate, + FormEndpoint, + Notify, + _ +) { + FormEndpoint.query().then(function (results) { + $scope.form = results; + }); +}); diff --git a/app/setting/directives/setting-data-import-directive.js b/app/setting/directives/setting-data-import-directive.js new file mode 100644 index 0000000000..984e416748 --- /dev/null +++ b/app/setting/directives/setting-data-import-directive.js @@ -0,0 +1,37 @@ +module.exports = [ + '$q', + '$location', + '$translate', + 'FormEndpoint', + 'DataImportEndpoint', + '_', + 'Notify', +function ( + $q, + $location, + $translate, + FormEndpoint, + DataImportEndpoint, + _, + Notify +) { + return { + restrict: 'A', + link: function ($scope, $element, $attrs) { + $scope.formId; + $scope.file; + $scope.importCSV = function () { + DataImportEndpoint.save({ + 'form_id': $scope.formId, + 'file': $scope.file + }).$promise.then(function () { + $translate('notify.data-import.csv_upload', {$scope.file.name}).then( + function (message) + Notify.showNotificationSlider(message); + }); + }, function (errorResponse) { + Notify.showApiErrors(errorResponse); + }); + }; + }); +}); diff --git a/app/setting/services/endpoints/data-import.js b/app/setting/services/endpoints/data-import.js new file mode 100644 index 0000000000..bae7132351 --- /dev/null +++ b/app/setting/services/endpoints/data-import.js @@ -0,0 +1,29 @@ +module.exports = [ + '$resource', + '$rootScope', + 'Util', +function ( + $resource, + $rootScope, + Util +) { + + var DataImportEndpoint = $resource(Util.apiUrl('/csv/:id'), { + id: '@id' + }, { + query: { + method: 'GET', + isArray: true, + transformResponse: function (data /*, header*/) { + return Util.transformResponse(data).results; + } + }, + update: { + method: 'POST' + } + }); + + + return DataEndpoint; + +}]; diff --git a/app/setting/setting-routes.js b/app/setting/setting-routes.js index e88de5e5a4..51f68b6491 100644 --- a/app/setting/setting-routes.js +++ b/app/setting/setting-routes.js @@ -16,6 +16,10 @@ function ( controller: require('./controllers/setting-map-settings.js'), templateUrl: 'templates/settings/map-settings.html' }) + .when('/settings/data-import', { + controller: require('./controllers/setting-data-import-controller.js'), + templateUrl: 'templates/settings/data-import.html' + }) .when('/settings/plugins', { controller: require('./controllers/setting-plugins-controller.js'), templateUrl: 'templates/settings/todo.html' diff --git a/server/www/templates/partials/main-menu.html b/server/www/templates/partials/main-menu.html index 5c8b387e87..a97bcc451c 100644 --- a/server/www/templates/partials/main-menu.html +++ b/server/www/templates/partials/main-menu.html @@ -18,6 +18,7 @@
  • nav.posts_and_entities
  • nav.categories
  • nav.users
  • +
  • nav.data-import
  • diff --git a/server/www/templates/settings/data-import.html b/server/www/templates/settings/data-import.html new file mode 100644 index 0000000000..77ee27bc05 --- /dev/null +++ b/server/www/templates/settings/data-import.html @@ -0,0 +1,34 @@ +
    + +
    +
    +

    data-import.csv

    +

    translatedata-import.import_explanation_csv

    +
    +
    + +
    + +
    +
    +
    + + +
    +
    + +
    +
    +
    +
    diff --git a/test/e2e/settings/csv-basic-spec.js b/test/e2e/settings/csv-basic-spec.js new file mode 100644 index 0000000000..7b919be551 --- /dev/null +++ b/test/e2e/settings/csv-basic-spec.js @@ -0,0 +1,77 @@ +describe('Testing CSV UI interaction', functon () { + + describe('as a loggedin admin user', function () { + + beforeEach(function () { + browser.get('/login'); + element(by.model('email')).sendKeys('admin@ush.com'); + element(by.model('password')).sendKeys('admin'); + element(by.css('button[type="submit"]')).click(); + + + element(by.css('.settings-nav span.settings-nav-button')).click(); + element(by.css('.main-nav a[href="/settings/data-import"]')).click(); + + }); + + afterEach(function () { + // Clear localStorage to reset session + browser.executeScript('window.sessionStorage.clear();'); + browser.executeScript('window.localStorage.clear();'); + }); + + describe('When user opens page and selects a form type', function () { + beforeEach(function () { + + + }); + + it('should have 2 available form types to select', function () { + + }); + + it('should set the selected form type as the current selection' function () { + + }); + + describe('when the user clicks on browse', function () { + beforeEach(function () { + + }); + + it('should display a file selection dialog', function () { + + }); + + describe('when the user selects a file', function () { + beforeEach(function () { + + }); + it('should set No file selected to the name of the file', function () { + + }); + + describe('when the user clicks import csv', function () { + beforeEach(function () { + + }); + + it('should display a progress spinner', function () { + beforeEach(function () { + + }); + + it('should show an upload confirmation', function () { + + }); + + it('should clear the selection and browse inputs' function () { + + }); + }); + }); + }); + }); + }); + }); +}); From 9636d69ef754f8607ae6c0a1b6a3cf8efbc16a7e Mon Sep 17 00:00:00 2001 From: will Date: Thu, 3 Dec 2015 20:16:20 -0500 Subject: [PATCH 004/135] added basic functionality next step is to test with back end, via e2e tests --- app/common/locales/en.json | 13 +++++++++++-- .../controllers/setting-data-import-controller.js | 6 +++--- .../directives/setting-data-import-directive.js | 15 +++++++-------- app/setting/setting-module.js | 1 + server/www/templates/partials/main-menu.html | 2 +- server/www/templates/settings/data-import.html | 14 +++++++------- 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index ddc5553658..746c4e895d 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -147,6 +147,7 @@ "collections" : "Collections", "comments" : "Comments", "data_sources" : "Data Sources", + "data_import" : "Data Import", "edit_profile" : "Edit Profile", "edit_post_type": "Edit Post Type", "forbidden" : "Access Denied", @@ -439,9 +440,14 @@ } } }, - "data-import" :{ + "data_import" :{ "import" : "Import", - "import_explanation" : "Import the data from a CSV spreadsheet into your deployment as posts belonging to a specific post type." + "import_explanation_csv" : "Import the data from a CSV spreadsheet into your deployment as posts belonging to a specific post type.", + "csv" : "CSV", + "post_type" : "Import to which post type?", + "file_csv" : "CSV file", + "import_csv" : "Import CSV" + }, "user": { "add_user" : "Add User", @@ -515,6 +521,9 @@ "bulk_destroy_error" : "Unable to delete resource, please try again", "bulk_destroy_cancelled" : "Delete cancelled" }, + "data_import" : { + "csv_upload" : "File {{name}} successfully uploaded" + }, "general_settings" : { "save_success" : "General settings saved" }, diff --git a/app/setting/controllers/setting-data-import-controller.js b/app/setting/controllers/setting-data-import-controller.js index eeee3e78b0..8e14228b7f 100644 --- a/app/setting/controllers/setting-data-import-controller.js +++ b/app/setting/controllers/setting-data-import-controller.js @@ -11,7 +11,7 @@ function ( Notify, _ ) { - FormEndpoint.query().then(function (results) { - $scope.form = results; + FormEndpoint.get().$promise.then(function (response) { + $scope.forms = response.results; }); -}); +}]; diff --git a/app/setting/directives/setting-data-import-directive.js b/app/setting/directives/setting-data-import-directive.js index 984e416748..d38987f35d 100644 --- a/app/setting/directives/setting-data-import-directive.js +++ b/app/setting/directives/setting-data-import-directive.js @@ -1,5 +1,4 @@ module.exports = [ - '$q', '$location', '$translate', 'FormEndpoint', @@ -7,7 +6,6 @@ module.exports = [ '_', 'Notify', function ( - $q, $location, $translate, FormEndpoint, @@ -22,16 +20,17 @@ function ( $scope.file; $scope.importCSV = function () { DataImportEndpoint.save({ - 'form_id': $scope.formId, - 'file': $scope.file + form_id: $scope.formId, + file: $scope.file }).$promise.then(function () { - $translate('notify.data-import.csv_upload', {$scope.file.name}).then( - function (message) + $translate('notify.data_import.csv_upload', {name: $scope.file.name}).then( + function (message) { Notify.showNotificationSlider(message); }); }, function (errorResponse) { Notify.showApiErrors(errorResponse); }); }; - }); -}); + } + }; +}]; diff --git a/app/setting/setting-module.js b/app/setting/setting-module.js index b205218abd..49e35de949 100644 --- a/app/setting/setting-module.js +++ b/app/setting/setting-module.js @@ -5,6 +5,7 @@ angular.module('ushahidi.tools', [ 'colorpicker.module', 'xeditable' ]) +.directive('dataImport', require('./directives/setting-data-import-directive.js')) .directive('formEditor', require('./directives/setting-form-editor-directive.js')) .directive('settingsEditor', require('./directives/setting-editor-directive.js')) diff --git a/server/www/templates/partials/main-menu.html b/server/www/templates/partials/main-menu.html index a97bcc451c..7260ec3c44 100644 --- a/server/www/templates/partials/main-menu.html +++ b/server/www/templates/partials/main-menu.html @@ -18,7 +18,7 @@
  • nav.posts_and_entities
  • nav.categories
  • nav.users
  • -
  • nav.data-import
  • +
  • nav.data_import
  • diff --git a/server/www/templates/settings/data-import.html b/server/www/templates/settings/data-import.html index 77ee27bc05..1c58b93153 100644 --- a/server/www/templates/settings/data-import.html +++ b/server/www/templates/settings/data-import.html @@ -1,19 +1,19 @@ -
    +
    -

    data-import.csv

    -

    translatedata-import.import_explanation_csv

    +

    data_import.csv

    +

    data_import.import_explanation_csv

    - +
    - +
    From 8f278bf43ec61bad3af2d0887b0b656355431e1e Mon Sep 17 00:00:00 2001 From: will Date: Fri, 4 Dec 2015 17:55:34 -0500 Subject: [PATCH 005/135] updated to send csv file - needs higher privillege setting --- .../setting-data-import-controller.js | 4 ++ .../setting-data-import-directive.js | 36 ++++++++++-------- app/setting/services/endpoints/data-import.js | 38 +++++++++++-------- app/setting/setting-module.js | 5 ++- .../www/templates/settings/data-import.html | 5 ++- 5 files changed, 52 insertions(+), 36 deletions(-) diff --git a/app/setting/controllers/setting-data-import-controller.js b/app/setting/controllers/setting-data-import-controller.js index 8e14228b7f..e5650fe5ed 100644 --- a/app/setting/controllers/setting-data-import-controller.js +++ b/app/setting/controllers/setting-data-import-controller.js @@ -12,6 +12,10 @@ function ( _ ) { FormEndpoint.get().$promise.then(function (response) { + $scope.fileContainer = { + file : null + }; + $scope.forms = response.results; }); }]; diff --git a/app/setting/directives/setting-data-import-directive.js b/app/setting/directives/setting-data-import-directive.js index d38987f35d..b9c6f59e1d 100644 --- a/app/setting/directives/setting-data-import-directive.js +++ b/app/setting/directives/setting-data-import-directive.js @@ -1,36 +1,40 @@ module.exports = [ - '$location', '$translate', 'FormEndpoint', 'DataImportEndpoint', - '_', 'Notify', function ( - $location, $translate, FormEndpoint, DataImportEndpoint, - _, Notify ) { return { restrict: 'A', link: function ($scope, $element, $attrs) { $scope.formId; - $scope.file; + $scope.importCSV = function () { - DataImportEndpoint.save({ - form_id: $scope.formId, - file: $scope.file - }).$promise.then(function () { - $translate('notify.data_import.csv_upload', {name: $scope.file.name}).then( - function (message) { - Notify.showNotificationSlider(message); + if ($scope.fileContainer.file) { + var formData = new FormData(); + formData.append('file', $scope.fileContainer.file); + formData.append('form_id', $scope.formId); + + DataImportEndpoint(formData) + .then(function () { + $translate('notify.data_import.csv_upload', {name: $scope.file.name}).then( + function (message) { + Notify.showNotificationSlider(message); + }); + }, function (errorResponse) { + Notify.showApiErrors(errorResponse); }); - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); + } else { + $translate('notify.fata_import.file_missing').then(function (message) { + Notify.showApiErrors(message); + }); + } }; } - }; + } }]; diff --git a/app/setting/services/endpoints/data-import.js b/app/setting/services/endpoints/data-import.js index bae7132351..909817f098 100644 --- a/app/setting/services/endpoints/data-import.js +++ b/app/setting/services/endpoints/data-import.js @@ -1,29 +1,35 @@ module.exports = [ + '$q', + '$http', '$resource', '$rootScope', 'Util', function ( + $q, + $http, $resource, $rootScope, Util ) { - var DataImportEndpoint = $resource(Util.apiUrl('/csv/:id'), { - id: '@id' - }, { - query: { - method: 'GET', - isArray: true, - transformResponse: function (data /*, header*/) { - return Util.transformResponse(data).results; + var DataImportEndpoint = function (formData) { + var dfd = $q.defer(); + $http.post( + Util.apiUrl('/csv'), + formData, + { + headers: { + 'Content-Type': undefined + } } - }, - update: { - method: 'POST' - } - }); - - - return DataEndpoint; + ).then(function (response) { + dfd.resolve(); + }, function (errorResponse) { + dfd.reject(errorResponse); + }) + return dfd.promise; + }; + + return DataImportEndpoint; }]; diff --git a/app/setting/setting-module.js b/app/setting/setting-module.js index 49e35de949..f384eb30ac 100644 --- a/app/setting/setting-module.js +++ b/app/setting/setting-module.js @@ -5,9 +5,10 @@ angular.module('ushahidi.tools', [ 'colorpicker.module', 'xeditable' ]) -.directive('dataImport', require('./directives/setting-data-import-directive.js')) +.directive('importer', require('./directives/setting-data-import-directive.js')) .directive('formEditor', require('./directives/setting-form-editor-directive.js')) - .directive('settingsEditor', require('./directives/setting-editor-directive.js')) +.service('DataImportEndpoint', require('./services/endpoints/data-import.js')) + .config(require('./setting-routes.js')); diff --git a/server/www/templates/settings/data-import.html b/server/www/templates/settings/data-import.html index 1c58b93153..b2c6b5cee5 100644 --- a/server/www/templates/settings/data-import.html +++ b/server/www/templates/settings/data-import.html @@ -1,4 +1,4 @@ -
    +
    - + +
    From f61fe6bb707dd801665465ad5343819cca95895a Mon Sep 17 00:00:00 2001 From: will Date: Mon, 7 Dec 2015 14:21:53 -0500 Subject: [PATCH 006/135] next step --- test/karma.conf.js | 8 +++- .../collection-selector-directivers-spec.js | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index 3a02b3a3e0..3b1404b09a 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -17,7 +17,10 @@ module.exports = function (config) { 'app/set/**/*.js', 'app/user-profile/**/*.js', 'app/common/locales/**/*.json', - 'test/unit/**/*.js' + 'test/unit/**/*.js', + + //include template files for directive testing + 'server/www/template/**/*.html' ], // we don't want to include the sub module manifest files @@ -51,7 +54,8 @@ module.exports = function (config) { preprocessors: { 'app/**/*.js': ['commonjs', 'coverage'], 'app/common/locales/**/*.json': ['commonjs'], - 'test/unit/**/*.js': ['commonjs'] + 'test/unit/**/*.js': ['commonjs'], + 'server/www/templates/**/*.html': 'html2js' }, coverageReporter: { diff --git a/test/unit/common/directives/collection-selector-directivers-spec.js b/test/unit/common/directives/collection-selector-directivers-spec.js index e69de29bb2..dc8466b017 100644 --- a/test/unit/common/directives/collection-selector-directivers-spec.js +++ b/test/unit/common/directives/collection-selector-directivers-spec.js @@ -0,0 +1,44 @@ +var ROOT_PATH = '../../../../'; + +describe('Collection Selector directive', function () { + var $scope, + $compile, + CollectionEndpoint; + + beforeEach(function () { + var testApp = angular.module('testApp', [ + 'pascalprecht.translate', + 'ngResource', + 'angular-cache' + ]) + .directive('collectionSelector', require(ROOT_PATH + 'app/common/directives/collection-selector.js')) + .service('CollectionEndpoint', require(ROOT_PATH + 'app/set/services/endpoints/collection.js')) + .service('Notify', require(ROOT_PATH + 'app/common/services/notify.js')) + + require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); + + angular.mock.module('testApp'); + }); + + beforeEach(inject(function (_$rootScope_, + _$compile_, + _CollectionEndpoint_ + ) { + $compile = _$compile_; + $scope = _$rootScope_.$new(); + $controller = _$controller_; + PostEndpoint = _PostEndpoint_; + + directiveElem = getCompiledElement(); + })); + + getCompiledElement = function () { + var compiledDirective = compile( + angular.element( + '' + ))($scope); + $scope.$digest(); + return compiledDirective; + }; +}); + From 50ccb80ba8bf79410e5d485a972e62f22bd3ee82 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 7 Dec 2015 16:54:05 -0500 Subject: [PATCH 007/135] added mapping function - adding tests next --- app/common/locales/en.json | 13 +++- .../setting-data-mapper-controller.js | 28 +++++++++ .../setting-data-import-directive.js | 7 ++- .../setting-data-mapper-directive.js | 42 +++++++++++++ app/setting/services/endpoints/data-import.js | 10 ++- app/setting/setting-module.js | 3 +- app/setting/setting-routes.js | 6 +- .../{ => data-import}/data-import.html | 2 +- .../settings/data-import/data-mapper.html | 63 +++++++++++++++++++ 9 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 app/setting/controllers/setting-data-mapper-controller.js create mode 100644 app/setting/directives/setting-data-mapper-directive.js rename server/www/templates/settings/{ => data-import}/data-import.html (95%) create mode 100644 server/www/templates/settings/data-import/data-mapper.html diff --git a/app/common/locales/en.json b/app/common/locales/en.json index 746c4e895d..78f4c44950 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -446,8 +446,17 @@ "csv" : "CSV", "post_type" : "Import to which post type?", "file_csv" : "CSV file", - "import_csv" : "Import CSV" - + "import_csv" : "Import CSV", + "choose_file" : "Choose file", + "organizw_data" : "Organize data", + "organize_your_imported_data" : "Assign CSV columns to post fields", + "assign_csv_message" : "Assign CSV columns to post fields", + "csv_instructions" : "Each of the column names from your CSV file are listed below. Choose the {{form_name}} field that you'd like each column to be imported to.", + "csv_column_name" : "CSV column name", + "post_type_title" : "{{form_name}} field name", + "dont_import" : "Don\'t import", + "cancel_import" : "Cancel import", + "finish_import" : "Finish import" }, "user": { "add_user" : "Add User", diff --git a/app/setting/controllers/setting-data-mapper-controller.js b/app/setting/controllers/setting-data-mapper-controller.js new file mode 100644 index 0000000000..05d12adf28 --- /dev/null +++ b/app/setting/controllers/setting-data-mapper-controller.js @@ -0,0 +1,28 @@ +module.exports = [ + '$scope', + '$q', + '$translate', + 'FormEndpoint', + 'DataImportEndpoint', + 'Notify', + '_', +function ( + $scope, + $q + $translate, + FormEndpoint, + DataImportEndpoint, + Notify, + _ +) { + $scope.formId = $routeParams.formId; + $scope.csvId = $routeParams.id; + + $q.all([ + FormEndpoint.get({id: $scope.formId}).$promise, + DataImportEndpoint.get({id: $scope.csv}).$promise + ]).then(function (results) { + $scope.form = results[0]; + $scope.csv = result[1]; + }); +}]; diff --git a/app/setting/directives/setting-data-import-directive.js b/app/setting/directives/setting-data-import-directive.js index b9c6f59e1d..cd48af7f6d 100644 --- a/app/setting/directives/setting-data-import-directive.js +++ b/app/setting/directives/setting-data-import-directive.js @@ -1,10 +1,12 @@ module.exports = [ '$translate', + '$location', 'FormEndpoint', 'DataImportEndpoint', 'Notify', function ( $translate, + $location, FormEndpoint, DataImportEndpoint, Notify @@ -20,11 +22,12 @@ function ( formData.append('file', $scope.fileContainer.file); formData.append('form_id', $scope.formId); - DataImportEndpoint(formData) - .then(function () { + DataImportEndpoint.upload(formData) + .then(function (csv) { $translate('notify.data_import.csv_upload', {name: $scope.file.name}).then( function (message) { Notify.showNotificationSlider(message); + $location.url('/settings/data-mapper/' + $scope.formId + '/' + csv.id); }); }, function (errorResponse) { Notify.showApiErrors(errorResponse); diff --git a/app/setting/directives/setting-data-mapper-directive.js b/app/setting/directives/setting-data-mapper-directive.js new file mode 100644 index 0000000000..a2e6ba9f7b --- /dev/null +++ b/app/setting/directives/setting-data-mapper-directive.js @@ -0,0 +1,42 @@ +module.exports = [ + '$translate', + '$location', + 'FormEndpoint', + 'DataImportEndpoint', + 'Notify', + '_' +function ( + $translate, + $location, + FormEndpoint, + DataImportEndpoint, + Notify, + _ +) { + return { + restrict: 'A', + link: function ($scope, $element, $attrs) { + $scope.cancelImport = function () { + $translate('notify.data_import.csv_import_cancel') + .then(function (message) { + Notify.showNotificationSlider(message); + $location.url('/settings/data-mapper/' + $scope.formId + '/' + csv.id); + }); + }; + + $scope.submitMappings = function () { + _.defaults($scope.csv, {form_attribute_id: null}); + DataImportEndpoint.save(csv) + .then(function (csv) { + $translate('notify.data_import.csv_mappings_set', {name: $scope.file.name}).then( + function (message) { + Notify.showNotificationSlider(message); + //$location.url('/settings/data-mapper/' + $scope.formId + '/' + csv.id); + }); + }, function (errorResponse) { + Notify.showApiErrors(errorResponse); + }); + }; + } + } +}]; diff --git a/app/setting/services/endpoints/data-import.js b/app/setting/services/endpoints/data-import.js index 909817f098..9c295fdd58 100644 --- a/app/setting/services/endpoints/data-import.js +++ b/app/setting/services/endpoints/data-import.js @@ -12,7 +12,15 @@ function ( Util ) { - var DataImportEndpoint = function (formData) { + var DataImportEndpoint = $resource(Util.apiUrl('/csv/:id'), { + id: '@id' + }, { + get: { + method: 'GET' + } + }); + + DataImportEndpoint.upload = function (formData) { var dfd = $q.defer(); $http.post( Util.apiUrl('/csv'), diff --git a/app/setting/setting-module.js b/app/setting/setting-module.js index f384eb30ac..905fb8a359 100644 --- a/app/setting/setting-module.js +++ b/app/setting/setting-module.js @@ -5,7 +5,8 @@ angular.module('ushahidi.tools', [ 'colorpicker.module', 'xeditable' ]) -.directive('importer', require('./directives/setting-data-import-directive.js')) +.directive('importerCsv', require('./directives/setting-data-import-directive.js')) +.directive('mapperCsv', require('./directives/setting-data-mapper-directive.js')) .directive('formEditor', require('./directives/setting-form-editor-directive.js')) .directive('settingsEditor', require('./directives/setting-editor-directive.js')) diff --git a/app/setting/setting-routes.js b/app/setting/setting-routes.js index 51f68b6491..ef5f44e8eb 100644 --- a/app/setting/setting-routes.js +++ b/app/setting/setting-routes.js @@ -18,7 +18,11 @@ function ( }) .when('/settings/data-import', { controller: require('./controllers/setting-data-import-controller.js'), - templateUrl: 'templates/settings/data-import.html' + templateUrl: 'templates/settings/data-import/data-import.html' + }) + .when('/settings/data-mapper/:formId/:id', { + controller: require('./controllers/setting-data-mapper-controller.js'), + templateUrl: 'templates/settings/data-import/data-mapper.html' }) .when('/settings/plugins', { controller: require('./controllers/setting-plugins-controller.js'), diff --git a/server/www/templates/settings/data-import.html b/server/www/templates/settings/data-import/data-import.html similarity index 95% rename from server/www/templates/settings/data-import.html rename to server/www/templates/settings/data-import/data-import.html index b2c6b5cee5..631b153345 100644 --- a/server/www/templates/settings/data-import.html +++ b/server/www/templates/settings/data-import/data-import.html @@ -1,4 +1,4 @@ -
    +
    From 97ecf4072c110127d7bf1f0111bc26f73dc273de Mon Sep 17 00:00:00 2001 From: will Date: Tue, 8 Dec 2015 11:19:58 -0500 Subject: [PATCH 009/135] updated controller and template --- app/setting/controllers/setting-data-mapper-controller.js | 6 +++++- app/setting/directives/setting-data-mapper-directive.js | 2 +- server/www/templates/settings/data-import/data-mapper.html | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/setting/controllers/setting-data-mapper-controller.js b/app/setting/controllers/setting-data-mapper-controller.js index 136b21cdb0..4bb286c482 100644 --- a/app/setting/controllers/setting-data-mapper-controller.js +++ b/app/setting/controllers/setting-data-mapper-controller.js @@ -22,9 +22,13 @@ function ( $q.all([ FormEndpoint.get({id: $scope.formId}).$promise, + FormAttributeEndpoint.query({ formId: $scope.formId }).$promise, DataImportEndpoint.get({id: $scope.csv}).$promise ]).then(function (results) { $scope.form = results[0]; - $scope.csv = result[1]; + form.attributes = _.chain(results[1]) + .sortBy('priority') + .value(); + $scope.csv = result[2]; }); }]; diff --git a/app/setting/directives/setting-data-mapper-directive.js b/app/setting/directives/setting-data-mapper-directive.js index e50af33873..e3bb49b931 100644 --- a/app/setting/directives/setting-data-mapper-directive.js +++ b/app/setting/directives/setting-data-mapper-directive.js @@ -25,7 +25,7 @@ function ( }; $scope.submitMappings = function () { - _.defaults($scope.csv, {form_attribute_id: null}); + _.defaults($scope.csv, {maps_to: null}); DataImportEndpoint.save(csv) .then(function (csv) { $translate('notify.data_import.csv_mappings_set', {name: $scope.file.name}).then( diff --git a/server/www/templates/settings/data-import/data-mapper.html b/server/www/templates/settings/data-import/data-mapper.html index 3f897ae805..84de6a1523 100644 --- a/server/www/templates/settings/data-import/data-mapper.html +++ b/server/www/templates/settings/data-import/data-mapper.html @@ -41,7 +41,7 @@

    data_import.organize_your_imported_data

    + ng-model="csv.maps_to[$index]" + ng-options="attribute.label for attribute in form.attributes track by attribute.label"> - +
    @@ -55,7 +55,7 @@

    data_import.organize_your_imported_data

    - +
    From 527e20949b7370c57c3fbfc4814ff390047725b7 Mon Sep 17 00:00:00 2001 From: will Date: Fri, 11 Dec 2015 14:13:04 -0500 Subject: [PATCH 011/135] added complete setting --- app/setting/directives/setting-data-mapper-directive.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/setting/directives/setting-data-mapper-directive.js b/app/setting/directives/setting-data-mapper-directive.js index f66e91d956..fbc3ae1e33 100644 --- a/app/setting/directives/setting-data-mapper-directive.js +++ b/app/setting/directives/setting-data-mapper-directive.js @@ -28,6 +28,8 @@ function ( csv.maps_to = _.map(csv.maps_to, function (item) { return item ? item.label : null; }); + csv.completed = true; + csv.unmapped = []; DataImportEndpoint.update(csv) .$promise .then(function (csv) { From 046ac39ef708b7d79a3e647ffc14986dcb5914da Mon Sep 17 00:00:00 2001 From: will Date: Fri, 11 Dec 2015 14:51:31 -0500 Subject: [PATCH 012/135] wired up - next add check to make sure no attribute is double mapped --- app/setting/directives/setting-data-mapper-directive.js | 4 ++-- server/www/templates/settings/data-import/data-mapper.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/setting/directives/setting-data-mapper-directive.js b/app/setting/directives/setting-data-mapper-directive.js index fbc3ae1e33..c2f4d86e42 100644 --- a/app/setting/directives/setting-data-mapper-directive.js +++ b/app/setting/directives/setting-data-mapper-directive.js @@ -26,7 +26,7 @@ function ( $scope.submitMappings = function (csv) { csv.maps_to = _.map(csv.maps_to, function (item) { - return item ? item.label : null; + return item ? item.key : null; }); csv.completed = true; csv.unmapped = []; @@ -36,7 +36,7 @@ function ( $translate('notify.data_import.csv_mappings_set').then( function (message) { Notify.showNotificationSlider(message); - //$location.url('/settings/data-mapper/' + $scope.formId + '/' + csv.id); + $location.url('/views/list'); }); }, function (errorResponse) { Notify.showApiErrors(errorResponse); diff --git a/server/www/templates/settings/data-import/data-mapper.html b/server/www/templates/settings/data-import/data-mapper.html index 3960a87262..1d3e39d96c 100644 --- a/server/www/templates/settings/data-import/data-mapper.html +++ b/server/www/templates/settings/data-import/data-mapper.html @@ -42,7 +42,7 @@

    data_import.organize_your_imported_data

    From f5e166853fa7c6578eafdf84968040a37ccdb09e Mon Sep 17 00:00:00 2001 From: will Date: Fri, 11 Dec 2015 14:52:31 -0500 Subject: [PATCH 013/135] describe tests --- test/e2e/settings/csv-basic-spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/settings/csv-basic-spec.js b/test/e2e/settings/csv-basic-spec.js index 7b919be551..720d30a683 100644 --- a/test/e2e/settings/csv-basic-spec.js +++ b/test/e2e/settings/csv-basic-spec.js @@ -1,5 +1,5 @@ describe('Testing CSV UI interaction', functon () { - +/* describe('as a loggedin admin user', function () { beforeEach(function () { @@ -74,4 +74,5 @@ describe('Testing CSV UI interaction', functon () { }); }); }); +*/ }); From 983ccebc65fb600b1a384773455ef28f333b19f8 Mon Sep 17 00:00:00 2001 From: will Date: Fri, 11 Dec 2015 16:43:45 -0500 Subject: [PATCH 014/135] added csv duplicate mapping alter --- app/common/locales/en.json | 3 ++- .../setting-data-mapper-directive.js | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index d3090397d6..9c080f0ea5 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -532,7 +532,8 @@ }, "data_import" : { "csv_upload" : "File {{name}} successfully uploaded", - "csv_mappings_set" : "CSV mappings set successfully" + "csv_mappings_set" : "CSV mappings set successfully", + "duplicate_fields" : "Columns must be mapped to unique post type fields. The following fields have more than 1 mapping: {{duplicates}}" }, "general_settings" : { "save_success" : "General settings saved" diff --git a/app/setting/directives/setting-data-mapper-directive.js b/app/setting/directives/setting-data-mapper-directive.js index c2f4d86e42..cec0f37dc1 100644 --- a/app/setting/directives/setting-data-mapper-directive.js +++ b/app/setting/directives/setting-data-mapper-directive.js @@ -28,6 +28,29 @@ function ( csv.maps_to = _.map(csv.maps_to, function (item) { return item ? item.key : null; }); + + var dups = _.countBy(csv.maps_to, function (item) { + return item; + }); + + + var duplicateVars = _.filter(csv.maps_to, function (item) { + if (dups[item] > 1) { + return item; + }; + }); + + duplicateVars = _.uniq(duplicateVars); + + if(duplicateVars.length > 0) { + + $translate('notify.data_import.duplicate_fields', {duplicates: duplicateVars.join(', ')}).then( + function (message) { + Notify.showAlerts([message]); + }); + return; + }; + csv.completed = true; csv.unmapped = []; DataImportEndpoint.update(csv) From 56c2cda04b6fbab4763164162a6fb369431e9e25 Mon Sep 17 00:00:00 2001 From: will Date: Fri, 11 Dec 2015 16:49:17 -0500 Subject: [PATCH 015/135] removed tests for the moment --- test/e2e/settings/csv-basic-spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/settings/csv-basic-spec.js b/test/e2e/settings/csv-basic-spec.js index 720d30a683..d76e5c081c 100644 --- a/test/e2e/settings/csv-basic-spec.js +++ b/test/e2e/settings/csv-basic-spec.js @@ -1,5 +1,5 @@ -describe('Testing CSV UI interaction', functon () { -/* +describe('Testing CSV UI interaction', function () { + /* describe('as a loggedin admin user', function () { beforeEach(function () { From c49e4afccfd05f8396caf87a8712129d0b338701 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 4 Jan 2016 12:03:51 -0500 Subject: [PATCH 016/135] fixed failing tests --- .../setting-data-mapper-controller.js | 4 ++-- .../directives/setting-data-import-directive.js | 4 ++-- .../directives/setting-data-mapper-directive.js | 17 ++++++++--------- app/setting/services/endpoints/data-import.js | 8 ++++---- test/e2e/settings/csv-basic-spec.js | 3 +-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/setting/controllers/setting-data-mapper-controller.js b/app/setting/controllers/setting-data-mapper-controller.js index 43f5ddfc09..a91c8aada5 100644 --- a/app/setting/controllers/setting-data-mapper-controller.js +++ b/app/setting/controllers/setting-data-mapper-controller.js @@ -21,7 +21,7 @@ function ( ) { $scope.formId = $routeParams.formId; $scope.csvId = $routeParams.id; - + $q.all([ FormEndpoint.get({id: $scope.formId}).$promise, FormAttributeEndpoint.query({ formId: $scope.formId }).$promise, @@ -32,6 +32,6 @@ function ( .sortBy('priority') .value(); $scope.csv = results[2]; - $scope.csv.maps_to = Array.apply(null, Array($scope.csv.columns.length)); + $scope.csv.maps_to = new Array.apply(null, new Array($scope.csv.columns.length)); }); }]; diff --git a/app/setting/directives/setting-data-import-directive.js b/app/setting/directives/setting-data-import-directive.js index 9d63345ed6..72f7d174d6 100644 --- a/app/setting/directives/setting-data-import-directive.js +++ b/app/setting/directives/setting-data-import-directive.js @@ -34,10 +34,10 @@ function ( }); } else { $translate('notify.fata_import.file_missing').then(function (message) { - Notify.showApiErrors(message); + Notify.showApiErrors(message); }); } }; } - } + }; }]; diff --git a/app/setting/directives/setting-data-mapper-directive.js b/app/setting/directives/setting-data-mapper-directive.js index cec0f37dc1..5c1997052a 100644 --- a/app/setting/directives/setting-data-mapper-directive.js +++ b/app/setting/directives/setting-data-mapper-directive.js @@ -28,29 +28,28 @@ function ( csv.maps_to = _.map(csv.maps_to, function (item) { return item ? item.key : null; }); - + var dups = _.countBy(csv.maps_to, function (item) { - return item; + return item; }); - var duplicateVars = _.filter(csv.maps_to, function (item) { if (dups[item] > 1) { - return item; - }; + return item; + } }); duplicateVars = _.uniq(duplicateVars); - if(duplicateVars.length > 0) { + if (duplicateVars.length > 0) { $translate('notify.data_import.duplicate_fields', {duplicates: duplicateVars.join(', ')}).then( function (message) { Notify.showAlerts([message]); }); return; - }; - + } + csv.completed = true; csv.unmapped = []; DataImportEndpoint.update(csv) @@ -66,5 +65,5 @@ function ( }); }; } - } + }; }]; diff --git a/app/setting/services/endpoints/data-import.js b/app/setting/services/endpoints/data-import.js index b799ec1451..b92eee38b2 100644 --- a/app/setting/services/endpoints/data-import.js +++ b/app/setting/services/endpoints/data-import.js @@ -22,7 +22,7 @@ function ( method: 'PUT' } }); - + DataImportEndpoint.upload = function (formData) { var dfd = $q.defer(); $http.post( @@ -34,13 +34,13 @@ function ( } } ).then(function (response) { - dfd.resolve(Util.transformResponse(response.data)); + dfd.resolve(Util.transformResponse(response.data)); }, function (errorResponse) { dfd.reject(errorResponse); - }) + }); return dfd.promise; }; - + return DataImportEndpoint; }]; diff --git a/test/e2e/settings/csv-basic-spec.js b/test/e2e/settings/csv-basic-spec.js index d76e5c081c..d36f4fa371 100644 --- a/test/e2e/settings/csv-basic-spec.js +++ b/test/e2e/settings/csv-basic-spec.js @@ -22,7 +22,6 @@ describe('Testing CSV UI interaction', function () { describe('When user opens page and selects a form type', function () { beforeEach(function () { - }); @@ -50,7 +49,7 @@ describe('Testing CSV UI interaction', function () { it('should set No file selected to the name of the file', function () { }); - + describe('when the user clicks import csv', function () { beforeEach(function () { From 1d298b691582af6e89c8cc0903d85c63e6c88e83 Mon Sep 17 00:00:00 2001 From: will Date: Tue, 5 Jan 2016 22:30:41 -0500 Subject: [PATCH 017/135] Added automap function and included post title field as a mappable entity --- .../setting-data-mapper-controller.js | 37 ++++++++++++++++++- .../settings/data-import/data-mapper.html | 5 ++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/setting/controllers/setting-data-mapper-controller.js b/app/setting/controllers/setting-data-mapper-controller.js index a91c8aada5..c29db117c9 100644 --- a/app/setting/controllers/setting-data-mapper-controller.js +++ b/app/setting/controllers/setting-data-mapper-controller.js @@ -22,6 +22,29 @@ function ( $scope.formId = $routeParams.formId; $scope.csvId = $routeParams.id; + /* + * This function returns a map of csv columns to post_type fields. + * It checks for the presences of the columns names in the set of attribute labels. + * If the column is not present the entry is set to undefined. + * + * The match is case insensistive. + */ + $scope.autoMap = function (columns, attributes, mapSize) { + // Get set of labels + var attributeLabels = _.map(attributes, function (attribute){ + return attribute.label.toLowerCase(); + }); + + // Create map of labels to attributes + var attributeMap = _.object(attributeLabels, attributes); + + // Check if a column name appears in the set of labels, if it does set a mapping + // to the attribute, otherwise set the mapping to undefined. + return _.map(columns, function (item, index) { + return _.contains(attributeLabels, item.toLowerCase())? attributeMap[item] : undefined; + }); + }; + $q.all([ FormEndpoint.get({id: $scope.formId}).$promise, FormAttributeEndpoint.query({ formId: $scope.formId }).$promise, @@ -31,7 +54,19 @@ function ( $scope.form.attributes = _.chain(results[1]) .sortBy('priority') .value(); + + // Add in the Post specific mappable fields + $scope.form.attributes.push( + { + 'key': 'title', + 'label': 'title' + } + ); $scope.csv = results[2]; - $scope.csv.maps_to = new Array.apply(null, new Array($scope.csv.columns.length)); + $scope.csv.maps_to = $scope.autoMap( + $scope.csv.columns, + $scope.form.attributes, + $scope.csv.columns.length + ); }); }]; diff --git a/server/www/templates/settings/data-import/data-mapper.html b/server/www/templates/settings/data-import/data-mapper.html index 1d3e39d96c..1ea7c94069 100644 --- a/server/www/templates/settings/data-import/data-mapper.html +++ b/server/www/templates/settings/data-import/data-mapper.html @@ -43,8 +43,9 @@

    data_import.organize_your_imported_data

    From efde2136a3f4efac79344e57fc557f4ca8d07ded Mon Sep 17 00:00:00 2001 From: will Date: Tue, 5 Jan 2016 22:53:20 -0500 Subject: [PATCH 018/135] fixed linting --- .../controllers/setting-data-mapper-controller.js | 14 +++++++------- .../settings/data-import/data-mapper.html | 9 --------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/app/setting/controllers/setting-data-mapper-controller.js b/app/setting/controllers/setting-data-mapper-controller.js index c29db117c9..040e8d8f63 100644 --- a/app/setting/controllers/setting-data-mapper-controller.js +++ b/app/setting/controllers/setting-data-mapper-controller.js @@ -25,23 +25,23 @@ function ( /* * This function returns a map of csv columns to post_type fields. * It checks for the presences of the columns names in the set of attribute labels. - * If the column is not present the entry is set to undefined. + * If the column is not present the entry is set to undefined. * - * The match is case insensistive. + * The match is case insensistive. */ $scope.autoMap = function (columns, attributes, mapSize) { // Get set of labels - var attributeLabels = _.map(attributes, function (attribute){ - return attribute.label.toLowerCase(); + var attributeLabels = _.map(attributes, function (attribute) { + return attribute.label.toLowerCase(); }); - + // Create map of labels to attributes var attributeMap = _.object(attributeLabels, attributes); - + // Check if a column name appears in the set of labels, if it does set a mapping // to the attribute, otherwise set the mapping to undefined. return _.map(columns, function (item, index) { - return _.contains(attributeLabels, item.toLowerCase())? attributeMap[item] : undefined; + return _.contains(attributeLabels, item.toLowerCase()) ? attributeMap[item] : undefined; }); }; diff --git a/server/www/templates/settings/data-import/data-mapper.html b/server/www/templates/settings/data-import/data-mapper.html index 1ea7c94069..6fcb8c440d 100644 --- a/server/www/templates/settings/data-import/data-mapper.html +++ b/server/www/templates/settings/data-import/data-mapper.html @@ -8,25 +8,19 @@ data_import.import -

    data_import.import_csv

    -
    1. data_import.choose_file
    2. data_import.organize_data
    -

    data_import.organize_your_imported_data

    -
    -
    data_import.assign_csv_message

    data_import.csv_instructions

    - @@ -34,7 +28,6 @@

    data_import.organize_your_imported_data

    - @@ -53,12 +46,10 @@

    data_import.organize_your_imported_data

    data_import.post_type_title
    {{column}}
    -
    -
    From e773d1890418034d53ca510f1c0baed38ef60373 Mon Sep 17 00:00:00 2001 From: Jason Mule Date: Thu, 7 Jan 2016 15:05:30 +0300 Subject: [PATCH 019/135] Don't show registration and add post links for private deployments --- server/www/index.html | 3 ++- server/www/templates/partials/user-menu.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/www/index.html b/server/www/index.html index c8ee9f4912..8ba89355dc 100644 --- a/server/www/index.html +++ b/server/www/index.html @@ -69,7 +69,8 @@

    - + nav.add_post diff --git a/server/www/templates/partials/user-menu.html b/server/www/templates/partials/user-menu.html index 081e794442..19a6919ef3 100644 --- a/server/www/templates/partials/user-menu.html +++ b/server/www/templates/partials/user-menu.html @@ -1,6 +1,6 @@
    From a03613a29ccd6fb8d3e24d920bce8bddad4432c0 Mon Sep 17 00:00:00 2001 From: will Date: Fri, 8 Jan 2016 14:00:32 -0500 Subject: [PATCH 020/135] Changes based on review --- app/common/services/util.js | 25 ++++++++++++++ .../setting-data-import-controller.js | 8 ++--- .../setting-data-mapper-controller.js | 30 +++------------- .../setting-data-import-directive.js | 34 +++++++++---------- .../setting-data-mapper-directive.js | 9 ++--- .../settings/data-import/data-mapper.html | 6 ++-- 6 files changed, 59 insertions(+), 53 deletions(-) diff --git a/app/common/services/util.js b/app/common/services/util.js index 813174ec15..f88824759c 100644 --- a/app/common/services/util.js +++ b/app/common/services/util.js @@ -23,6 +23,31 @@ function ( _.bindAll.apply(_, [object].concat(functions)); } return object; + }, + + /* + * This function returns a map of csv columns to post_type fields. + * It checks for the presences of the columns names in the set of attribute labels. + * If the column is not present the entry is set to undefined. + * + * The match is case insensistive. + */ + autoMap: function (columns, attributes, mapSize) { + // Get set of labels + var attributeLabels = _.map(attributes, function (attribute) { + return attribute.label.toLowerCase(); + }); + + // Create map of labels to attribute keys + var attributeKeys = _.pluck(attributes, 'key'); + var attributeMap = _.object(attributeLabels, attributeKeys); + + // Check if a column name appears in the set of labels, if it does set a mapping + // to the attribute, otherwise set the mapping to undefined. + return _.map(columns, function (item, index) { + var column = item.toLowerCase().trim(); + return _.contains(attributeLabels, column) ? attributeMap[item] : undefined; + }); } }; diff --git a/app/setting/controllers/setting-data-import-controller.js b/app/setting/controllers/setting-data-import-controller.js index e5650fe5ed..c3d0e20d9e 100644 --- a/app/setting/controllers/setting-data-import-controller.js +++ b/app/setting/controllers/setting-data-import-controller.js @@ -11,11 +11,11 @@ function ( Notify, _ ) { - FormEndpoint.get().$promise.then(function (response) { - $scope.fileContainer = { - file : null - }; + $scope.fileContainer = { + file : null + }; + FormEndpoint.get().$promise.then(function (response) { $scope.forms = response.results; }); }]; diff --git a/app/setting/controllers/setting-data-mapper-controller.js b/app/setting/controllers/setting-data-mapper-controller.js index 040e8d8f63..83a580e4b7 100644 --- a/app/setting/controllers/setting-data-mapper-controller.js +++ b/app/setting/controllers/setting-data-mapper-controller.js @@ -8,6 +8,7 @@ module.exports = [ 'DataImportEndpoint', 'Notify', '_', + 'Util', function ( $scope, $q, @@ -17,34 +18,13 @@ function ( FormAttributeEndpoint, DataImportEndpoint, Notify, - _ + _, + Util ) { $scope.formId = $routeParams.formId; $scope.csvId = $routeParams.id; - /* - * This function returns a map of csv columns to post_type fields. - * It checks for the presences of the columns names in the set of attribute labels. - * If the column is not present the entry is set to undefined. - * - * The match is case insensistive. - */ - $scope.autoMap = function (columns, attributes, mapSize) { - // Get set of labels - var attributeLabels = _.map(attributes, function (attribute) { - return attribute.label.toLowerCase(); - }); - - // Create map of labels to attributes - var attributeMap = _.object(attributeLabels, attributes); - - // Check if a column name appears in the set of labels, if it does set a mapping - // to the attribute, otherwise set the mapping to undefined. - return _.map(columns, function (item, index) { - return _.contains(attributeLabels, item.toLowerCase()) ? attributeMap[item] : undefined; - }); - }; - + $q.all([ FormEndpoint.get({id: $scope.formId}).$promise, FormAttributeEndpoint.query({ formId: $scope.formId }).$promise, @@ -63,7 +43,7 @@ function ( } ); $scope.csv = results[2]; - $scope.csv.maps_to = $scope.autoMap( + $scope.csv.maps_to = Util.autoMap( $scope.csv.columns, $scope.form.attributes, $scope.csv.columns.length diff --git a/app/setting/directives/setting-data-import-directive.js b/app/setting/directives/setting-data-import-directive.js index 72f7d174d6..340bf4f531 100644 --- a/app/setting/directives/setting-data-import-directive.js +++ b/app/setting/directives/setting-data-import-directive.js @@ -17,26 +17,26 @@ function ( $scope.formId; $scope.importCSV = function () { - if ($scope.fileContainer.file) { - var formData = new FormData(); - formData.append('file', $scope.fileContainer.file); - formData.append('form_id', $scope.formId); - - DataImportEndpoint.upload(formData) - .then(function (csv) { - $translate('notify.data_import.csv_upload', {name: $scope.fileContainer.file.name}).then( - function (message) { - Notify.showNotificationSlider(message); - $location.url('/settings/data-mapper/' + $scope.formId + '/' + csv.id); - }); - }, function (errorResponse) { - Notify.showApiErrors(errorResponse); - }); - } else { - $translate('notify.fata_import.file_missing').then(function (message) { + if (!$scope.fileContainer.file) { + $translate('notify.data_import.file_missing').then(function (message) { Notify.showApiErrors(message); }); + return; } + var formData = new FormData(); + formData.append('file', $scope.fileContainer.file); + formData.append('form_id', $scope.formId); + + DataImportEndpoint.upload(formData) + .then(function (csv) { + $translate('notify.data_import.csv_upload', {name: $scope.fileContainer.file.name}).then( + function (message) { + Notify.showNotificationSlider(message); + $location.url('/settings/data-mapper/' + $scope.formId + '/' + csv.id); + }); + }, function (errorResponse) { + Notify.showApiErrors(errorResponse); + }); }; } }; diff --git a/app/setting/directives/setting-data-mapper-directive.js b/app/setting/directives/setting-data-mapper-directive.js index 5c1997052a..3254f8163b 100644 --- a/app/setting/directives/setting-data-mapper-directive.js +++ b/app/setting/directives/setting-data-mapper-directive.js @@ -25,14 +25,14 @@ function ( }; $scope.submitMappings = function (csv) { - csv.maps_to = _.map(csv.maps_to, function (item) { - return item ? item.key : null; - }); + // Check to make sure the user hasn't double mapped a key + // First, collect the coutns for all keys var dups = _.countBy(csv.maps_to, function (item) { return item; }); - + + // Second, check if any of the keys appears more than once var duplicateVars = _.filter(csv.maps_to, function (item) { if (dups[item] > 1) { return item; @@ -41,6 +41,7 @@ function ( duplicateVars = _.uniq(duplicateVars); + // third, warn the user which keys have been duplicated if (duplicateVars.length > 0) { $translate('notify.data_import.duplicate_fields', {duplicates: duplicateVars.join(', ')}).then( diff --git a/server/www/templates/settings/data-import/data-mapper.html b/server/www/templates/settings/data-import/data-mapper.html index 6fcb8c440d..be9411172a 100644 --- a/server/www/templates/settings/data-import/data-mapper.html +++ b/server/www/templates/settings/data-import/data-mapper.html @@ -17,7 +17,7 @@

    data_import.import_csv

    data_import.organize_your_imported_data

    -
    +
    data_import.assign_csv_message

    data_import.csv_instructions

    @@ -35,7 +35,7 @@

    data_import.organize_your_imported_data

    + +
    +
    -
    +
    {{opt}} - -
    - -
    -
    @@ -270,9 +274,6 @@

    - - -

    diff --git a/server/www/templates/settings/forms/form-edit.html b/server/www/templates/settings/forms/form-edit.html index 57e1fff262..d810b996ac 100644 --- a/server/www/templates/settings/forms/form-edit.html +++ b/server/www/templates/settings/forms/form-edit.html @@ -165,7 +165,7 @@

    Fields

    From e3976c306f4a4a1bcd6c207fb1b1c2727ce9243d Mon Sep 17 00:00:00 2001 From: will Date: Mon, 25 Jan 2016 23:30:07 -0500 Subject: [PATCH 030/135] ensure orignal attribute prototype maintained --- .../setting-form-editor-directive.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/setting/directives/setting-form-editor-directive.js b/app/setting/directives/setting-form-editor-directive.js index 2cb587cd99..ff00fb6179 100644 --- a/app/setting/directives/setting-form-editor-directive.js +++ b/app/setting/directives/setting-form-editor-directive.js @@ -178,15 +178,15 @@ function ( newAttrCount++; $scope.isNewAttributeOpen = false; - - attribute.label = 'New ' + attribute.label.toLowerCase() + ' field'; - attribute.required = false; - attribute.options = []; - attribute.config = {}; - attribute.priority = lastPriority + 1; - attribute.form_stage_id = $scope.visibleStage - - $scope.form.attributes.push(attribute); + var newAttribute = _.clone(attribute); + newAttribute.label = 'New ' + attribute.label.toLowerCase() + ' field'; + newAttribute.required = false; + newAttribute.options = []; + newAttribute.config = {}; + newAttribute.priority = lastPriority + 1; + newAttribute.form_stage_id = $scope.visibleStage; + + $scope.form.attributes.push(newAttribute); $scope.form.grouped_attributes = _.sortBy($scope.form.attributes, 'form_stage_id'); var index = _.findLastIndex($scope.form.grouped_attributes, function (item, index) { From dae4d92b844d8331dd538fa79bfd37d8895069cf Mon Sep 17 00:00:00 2001 From: will Date: Mon, 1 Feb 2016 18:07:38 -0500 Subject: [PATCH 031/135] removing spec in favour of e2e test --- .../collection-selector-directivers-spec.js | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 test/unit/common/directives/collection-selector-directivers-spec.js diff --git a/test/unit/common/directives/collection-selector-directivers-spec.js b/test/unit/common/directives/collection-selector-directivers-spec.js deleted file mode 100644 index dc8466b017..0000000000 --- a/test/unit/common/directives/collection-selector-directivers-spec.js +++ /dev/null @@ -1,44 +0,0 @@ -var ROOT_PATH = '../../../../'; - -describe('Collection Selector directive', function () { - var $scope, - $compile, - CollectionEndpoint; - - beforeEach(function () { - var testApp = angular.module('testApp', [ - 'pascalprecht.translate', - 'ngResource', - 'angular-cache' - ]) - .directive('collectionSelector', require(ROOT_PATH + 'app/common/directives/collection-selector.js')) - .service('CollectionEndpoint', require(ROOT_PATH + 'app/set/services/endpoints/collection.js')) - .service('Notify', require(ROOT_PATH + 'app/common/services/notify.js')) - - require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); - - angular.mock.module('testApp'); - }); - - beforeEach(inject(function (_$rootScope_, - _$compile_, - _CollectionEndpoint_ - ) { - $compile = _$compile_; - $scope = _$rootScope_.$new(); - $controller = _$controller_; - PostEndpoint = _PostEndpoint_; - - directiveElem = getCompiledElement(); - })); - - getCompiledElement = function () { - var compiledDirective = compile( - angular.element( - '' - ))($scope); - $scope.$digest(); - return compiledDirective; - }; -}); - From 1441d6c714bca84d22e477a7318963d5ae8185af Mon Sep 17 00:00:00 2001 From: will Date: Tue, 2 Feb 2016 13:48:42 -0500 Subject: [PATCH 032/135] Adding role endpoint --- app/common/common-module.js | 1 + app/common/services/endpoints/role.js | 70 +++++++++ mocked_backend/api/v3/roles.json | 85 +++++++++++ .../services/endpoints/role-endpoint-spec.js | 139 ++++++++++++++++++ 4 files changed, 295 insertions(+) create mode 100644 app/common/services/endpoints/role.js create mode 100644 mocked_backend/api/v3/roles.json create mode 100644 test/unit/common/services/endpoints/role-endpoint-spec.js diff --git a/app/common/common-module.js b/app/common/common-module.js index 4ea4e9aaeb..7eb31d7d4b 100644 --- a/app/common/common-module.js +++ b/app/common/common-module.js @@ -18,6 +18,7 @@ angular.module('ushahidi.common', [ .service('FormAttributeEndpoint', require('./services/endpoints/form-attributes.js')) .service('FormStageEndpoint', require('./services/endpoints/form-stages.js')) .service('TagEndpoint', require('./services/endpoints/tag.js')) +.service('RoleEndpoint', require('./services/endpoints/role.js')) .service('DataProviderEndpoint', require('./services/endpoints/data-providers.js')) .service('FontAwesomeIcons', require('./services/endpoints/FontAwesomeIcons.js')) .service('RoleHelper', require('./services/role-helper.js')) diff --git a/app/common/services/endpoints/role.js b/app/common/services/endpoints/role.js new file mode 100644 index 0000000000..9e9b6b9cbb --- /dev/null +++ b/app/common/services/endpoints/role.js @@ -0,0 +1,70 @@ +module.exports = [ + '$resource', + 'Util', + 'CacheFactory', +function ( + $resource, + Util, + CacheFactory +) { + var cache; + + if (!(cache = CacheFactory.get('formCache'))) { + cache = new CacheFactory('formCache'); + } + + cache.setOnExpire(function (key, value) { + RoleEndpoint.get(value.id); + }); + + var RoleEndpoint = $resource(Util.apiUrl('/forms/:id'), { + id: '@id' + }, { + query: { + method: 'GET', + isArray: true, + transformResponse: function (data /*, header*/) { + return Util.transformResponse(data).results; + } + }, + get: { + method: 'GET', + cache: cache + }, + update: { + method: 'PUT' + }, + deleteEntity: { + method: 'DELETE' + } + }); + + RoleEndpoint.getFresh = function (id) { + cache.remove(Util.apiUrl(id)); + return RoleEndpoint.get(id); + }; + + RoleEndpoint.invalidateCache = function () { + return cache.removeAll(); + }; + + RoleEndpoint.queryFresh = function () { + cache.removeAll(); + return RoleEndpoint.query(); + }; + + RoleEndpoint.saveCache = function (item) { + var persist = item.id ? RoleEndpoint.update : RoleEndpoint.save; + cache.removeAll(); + var result = persist(item); + return result; + }; + + RoleEndpoint.delete = function (item) { + cache.removeAll(); + return RoleEndpoint.deleteEntity(item); + }; + + return RoleEndpoint; + +}]; diff --git a/mocked_backend/api/v3/roles.json b/mocked_backend/api/v3/roles.json new file mode 100644 index 0000000000..db3226934c --- /dev/null +++ b/mocked_backend/api/v3/roles.json @@ -0,0 +1,85 @@ +{ + "count": 5, + "results": [ + { + "id": 1, + "url": "http://api.ushahidi.dev/api/v3/roles/1", + "role": "admin", + "created": "1970-01-01T00:00:00+00:00", + "updated": null, + "role": "user", + "allowed_methods": [ + "get", + "post", + "put", + "delete" + ] + }, + { + "id": 2, + "url": "http://api.ushahidi.dev/api/v3/roles/2", + "role": "member", + "created": "1970-01-01T00:00:00+00:00", + "updated": null, + "role": "admin", + "allowed_methods": [ + "get", + "post", + "put", + "delete", + "update", + "change_status" + ] + }, + { + "id": 3, + "url": "http://api.ushahidi.dev/api/v3/roles/3", + "role": "guest", + "created": "1970-01-01T00:00:00+00:00", + "updated": null, + "role": "user", + "allowed_methods": [ + "get", + "post", + "put", + "delete" + ] + }, + { + "id": 4, + "url": "http://api.ushahidi.dev/api/v3/roles/4", + "role": "custom role 1", + "created": "1970-01-01T00:00:00+00:00", + "updated": null, + "role": "admin", + "allowed_methods": [ + "get", + "post", + "put", + "delete" + ] + }, + { + "id": 5, + "url": "http://api.ushahidi.dev/api/v3/roles/5", + "role": "custom role 2", + "created": "1970-01-01T00:00:00+00:00", + "updated": null, + "role": "admin", + "allowed_methods": [ + "get", + "post", + "put", + "delete" + ] + } + ], + "limit": 100, + "offset": 0, + "order": "desc", + "orderby": "created", + "curr": "http://api.ushahidi.dev/api/v3/roles?access_token=defaulttoken&orderby=created&order=desc&limit=100&offset=0", + "next": "http://api.ushahidi.dev/api/v3/roles?access_token=defaulttoken&orderby=created&order=desc&limit=100&offset=100", + "prev": "http://api.ushahidi.dev/api/v3/roles?access_token=defaulttoken&orderby=created&order=desc&limit=100&offset=0", + "total_count": 5 +} diff --git a/test/unit/common/services/endpoints/role-endpoint-spec.js b/test/unit/common/services/endpoints/role-endpoint-spec.js new file mode 100644 index 0000000000..2780e87420 --- /dev/null +++ b/test/unit/common/services/endpoints/role-endpoint-spec.js @@ -0,0 +1,139 @@ +var rootPath = '../../../../../'; + +describe('RoleEndpoint', function () { + + var $rootScope, + $httpBackend, + BACKEND_URL, + RoleEndpoint; + + + beforeEach(function () { + var testApp = angular.module('testApp', [ + 'ngResource', + 'angular-cache' + ]) + .service('RoleEndpoint', require(rootPath + 'app/common/services/endpoints/role.js')) + .config(require(rootPath + 'app/common/configs/cache-config.js')); + + require(rootPath + 'test/unit/simple-test-app-config.js')(testApp); + + angular.mock.module('testApp'); + }); + + beforeEach(inject(function (_$httpBackend_, _$rootScope_, _CONST_, _RoleEndpoint_) { + $rootScope = _$rootScope_; + $httpBackend = _$httpBackend_; + BACKEND_URL = _CONST_.BACKEND_URL; + RoleEndpoint = _RoleEndpoint_; + })); + + describe('"roles/:id" for data of all roles', function () { + describe('get all roles', function () { + + var mockRolesDataResponse; + + beforeEach(function () { + mockRolesDataResponse = + { + 'count': 2, + 'results': + [ + { + 'id': 1, + 'url': 'http://ushahidi-backend/api/v3/roles/1', + 'role': 'admin' + }, + { + 'id': 2, + 'url': 'http://ushahidi-backend/api/v3/roles/2', + 'role': 'member' + } + ] + }; + }); + + it('should call the correct url and parse and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + $httpBackend.expectGET(BACKEND_URL + '/api/v3/roles').respond(mockRoleDataResponse); + + RoleEndpoint.queryFresh().$promise.then(successCallback); + + $httpBackend.flush(); + $rootScope.$digest(); + + expect(successCallback).toHaveBeenCalled(); + + var actualRoleData = successCallback.calls.mostRecent().args[0]; + expect(actualRoleData.results.length).toEqual(mockRoleDataResponse.results.length); + expect(actualRoleData.results[0].email).toEqual(mockRoleDataResponse.results[0].email); + }); + }); + }); + + describe('"roles/1" for specific role', function () { + + var mockRoleDataResponse; + + beforeEach(function () { + mockRoleDataResponse = { + 'id': 1, + 'url': 'http://ushahidi-backend/api/v3/roles/1', + 'role': 'admin' + }; + }); + + describe('get role data', function () { + it('should call the correct url and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + $httpBackend.expectGET(BACKEND_URL + '/api/v3/roles/1').respond(mockRoleDataResponse); + + RoleEndpoint.get({id: '1'}).$promise.then(successCallback); + + $httpBackend.flush(); + $rootScope.$digest(); + + expect(successCallback).toHaveBeenCalled(); + + var actualRoleData = successCallback.calls.mostRecent().args[0]; + expect(actualRoleData.id).toEqual(mockRoleDataResponse.id); + expect(actualRoleData.realname).toEqual(mockRoleDataResponse.realname); + expect(actualRoleData.email).toEqual(mockRoleDataResponse.email); + }); + }); + + describe('update role data', function () { + + beforeEach(function () { + mockRoleDataResponse = { + 'id': 2, + 'url': 'http://ushahidi-backend/api/v3/roles/2', + 'role': 'new' + }; + }); + + it('should call the correct url and return the updated role data', function () { + var successCallback = jasmine.createSpy('success'); + $httpBackend.expectPUT(BACKEND_URL + '/api/v3/roles/2').respond(mockRoleDataResponse); + + var roleDataToUpdate = { + 'role': 'new' + }; + + RoleEndpoint.update({id: '2'}, roleDataToUpdate).$promise.then(successCallback); + + $httpBackend.flush(); + $rootScope.$digest(); + + expect(successCallback).toHaveBeenCalled(); + + var actualRoleData = successCallback.calls.mostRecent().args[0]; + expect(actualRoleData.id).toEqual(mockRoleDataResponse.id); + expect(actualRoleData.realname).toEqual(roleDataToUpdate.realname); + expect(actualRoleData.email).toEqual(roleDataToUpdate.email); + }); + }); + + }); + +}); From 4145c2dcee5218da5a15a577503aa12b25376cf9 Mon Sep 17 00:00:00 2001 From: will Date: Tue, 2 Feb 2016 15:04:33 -0500 Subject: [PATCH 033/135] adding outline of role spec test and menu settings --- app/common/locales/en.json | 2 + server/www/templates/partials/main-menu.html | 1 + server/www/templates/settings/roles-edit.html | 0 server/www/templates/settings/roles.html | 0 test/e2e/settings/roles-e2e-spec.js | 129 ++++++++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 server/www/templates/settings/roles-edit.html create mode 100644 server/www/templates/settings/roles.html create mode 100644 test/e2e/settings/roles-e2e-spec.js diff --git a/app/common/locales/en.json b/app/common/locales/en.json index 47acea500b..1d23497afe 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -189,6 +189,8 @@ "unselect_all" : "Unselect All", "user" : "User", "users" : "Users", + "role" : "Role", + "roles" : "Roles", "views" : "Views", "workspace" : "Workspace" }, diff --git a/server/www/templates/partials/main-menu.html b/server/www/templates/partials/main-menu.html index 7260ec3c44..66dae44f54 100644 --- a/server/www/templates/partials/main-menu.html +++ b/server/www/templates/partials/main-menu.html @@ -18,6 +18,7 @@
  • nav.posts_and_entities
  • nav.categories
  • nav.users
  • +
  • nav.roles
  • nav.data_import
  • diff --git a/server/www/templates/settings/roles-edit.html b/server/www/templates/settings/roles-edit.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/server/www/templates/settings/roles.html b/server/www/templates/settings/roles.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/e2e/settings/roles-e2e-spec.js b/test/e2e/settings/roles-e2e-spec.js new file mode 100644 index 0000000000..2aab06c86a --- /dev/null +++ b/test/e2e/settings/roles-e2e-spec.js @@ -0,0 +1,129 @@ +var _ = require('underscore'); + +describe('roles management', function () { + + describe('as a loggedin admin role', function () { + + beforeEach(function () { + browser.get('/login'); + + element(by.model('email')).sendKeys('admin@ush.com'); + element(by.model('password')).sendKeys('admin'); + element(by.css('button[type="submit"]')).click(); + }); + + afterEach(function () { + // Clear localStorage to reset session + browser.executeScript('window.sessionStorage.clear();'); + browser.executeScript('window.localStorage.clear();'); + }); + + + describe('clicking the "settings" menu link in the menu', function () { + var settingsLinkSelector = '.settings-nav span.settings-nav-button'; + + beforeEach(function () { + var settingsMenuLink = element(by.css(settingsLinkSelector)); + settingsMenuLink.click(); + }); + + describe('clicking the "roles" link in the "settings" menu', function () { + var rolesLinkSelector = '.main-nav a[href="/settings/roles"]'; + + beforeEach(function () { + var rolesLink = element(by.css(rolesLinkSelector)); + rolesLink.click(); + }); + + describe('with some existing roles in the backend', function () { + it('should list all roles (but only 10 per page)', function () { + expect(element.all(by.repeater('role in roles')).count()).toEqual(10); + // TODO: click page 2 and check if the remaining roles are displayed there + }); + + describe('open existing role', function () { + var adminLink; + beforeEach(function () { + adminLink = element(by.css('a[href="/settings/roles/2"')); + }); + + describe('link to roles detail view', function () { + it('should exist and have the role name as link text', function () { + expect(adminLink.getText()).toEqual('Admin'); + }); + }); + }); + + describe('When user clicks create new role', function () { + beforeEach(function () { + + }); + + it('should open the create role page', function () { + + }); + + it('should show available permission types', function () { + + }); + + describe('when user saves new role', function () { + beforeEach(function () { + var confirmModal = element(by.css('button#confirm-modal-ok')); + confirmModal.click(); + browser.sleep(500); + }); + + it('should show a confirmation of the role creation', function () { + var confirmMessage = element(by.css(confirmationMessageSelector)); + expect(confirmMessage.getInnerHtml()).toEqual('Role type Test Role created'); + }); + }); + }); + + describe('selecting some roles', function () { + beforeEach(function () { + _.range(1, 4).forEach(function (i) { + element(by.css('#role-' + i + ' input[type="checkbox"]')).click(); + }); + element(by.css('#role-1 input[type="checkbox"]')).click(); + }); + + describe('delete button', function () { + var deleteButton; + beforeEach(function () { + deleteButton = element(by.css('button#delete-roles')); + }); + + describe('clicking the button', function () { + beforeEach(function () { + browser.executeScript('window.scrollTo(0,0);').then(function () { + deleteButton.click(); + }); + browser.sleep(500); + }); + + it('should confirm the deletion of the roles', function () { + expect(element(by.css('#confirm-modal-text')).getText()).toEqual('Are you sure you want to delete these roles?'); + }); + + describe('When the user confirms deletion of the roles', function () { + beforeEach(function () { + var confirmModal = element(by.css('button#confirm-modal-ok')); + confirmModal.click(); + browser.sleep(500); + }); + + it('should show a confirmation of the roles deletion', function () { + var confirmMessage = element(by.css(confirmationMessageSelector)); + expect(confirmMessage.getInnerHtml()).toEqual('Roles deleted'); + }); + }); + }); + }); + }); + }); + }); + }); + }); +}); From 99d603483c9c82ab8191d4e4eb95d39aa8efcddf Mon Sep 17 00:00:00 2001 From: will Date: Thu, 4 Feb 2016 12:19:36 -0500 Subject: [PATCH 034/135] stubs for permission endpoints --- app/common/services/endpoints/permissions.js | 70 +++++++++ app/common/services/endpoints/role.js | 6 +- .../endpoints/permission-endpoint-spec.js | 139 ++++++++++++++++++ 3 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 app/common/services/endpoints/permissions.js create mode 100644 test/unit/common/services/endpoints/permission-endpoint-spec.js diff --git a/app/common/services/endpoints/permissions.js b/app/common/services/endpoints/permissions.js new file mode 100644 index 0000000000..bb78944435 --- /dev/null +++ b/app/common/services/endpoints/permissions.js @@ -0,0 +1,70 @@ +module.exports = [ + '$resource', + 'Util', + 'CacheFactory', +function ( + $resource, + Util, + CacheFactory +) { + var cache; + + if (!(cache = CacheFactory.get('permissionCache'))) { + cache = new CacheFactory('permissionCache'); + } + + cache.setOnExpire(function (key, value) { + PermissionEndpoint.get(value.id); + }); + + var PermissionEndpoint = $resource(Util.apiUrl('/permissions/:id'), { + id: '@id' + }, { + query: { + method: 'GET', + isArray: true, + transpermissionResponse: function (data /*, header*/) { + return Util.transformResponse(data).results; + } + }, + get: { + method: 'GET', + cache: cache + }, + update: { + method: 'PUT' + }, + deleteEntity: { + method: 'DELETE' + } + }); + + PermissionEndpoint.getFresh = function (id) { + cache.remove(Util.apiUrl(id)); + return PermissionEndpoint.get(id); + }; + + PermissionEndpoint.invalidateCache = function () { + return cache.removeAll(); + }; + + PermissionEndpoint.queryFresh = function () { + cache.removeAll(); + return PermissionEndpoint.query(); + }; + + PermissionEndpoint.saveCache = function (item) { + var persist = item.id ? PermissionEndpoint.update : PermissionEndpoint.save; + cache.removeAll(); + var result = persist(item); + return result; + }; + + PermissionEndpoint.delete = function (item) { + cache.removeAll(); + return PermissionEndpoint.deleteEntity(item); + }; + + return PermissionEndpoint; + +}]; diff --git a/app/common/services/endpoints/role.js b/app/common/services/endpoints/role.js index 9e9b6b9cbb..2d9e65b847 100644 --- a/app/common/services/endpoints/role.js +++ b/app/common/services/endpoints/role.js @@ -9,15 +9,15 @@ function ( ) { var cache; - if (!(cache = CacheFactory.get('formCache'))) { - cache = new CacheFactory('formCache'); + if (!(cache = CacheFactory.get('roleCache'))) { + cache = new CacheFactory('roleCache'); } cache.setOnExpire(function (key, value) { RoleEndpoint.get(value.id); }); - var RoleEndpoint = $resource(Util.apiUrl('/forms/:id'), { + var RoleEndpoint = $resource(Util.apiUrl('/roles/:id'), { id: '@id' }, { query: { diff --git a/test/unit/common/services/endpoints/permission-endpoint-spec.js b/test/unit/common/services/endpoints/permission-endpoint-spec.js new file mode 100644 index 0000000000..5c7ebad8bb --- /dev/null +++ b/test/unit/common/services/endpoints/permission-endpoint-spec.js @@ -0,0 +1,139 @@ +var rootPath = '../../../../../'; + +describe('PermissionEndpoint', function () { + + var $rootScope, + $httpBackend, + BACKEND_URL, + PermissionEndpoint; + + + beforeEach(function () { + var testApp = angular.module('testApp', [ + 'ngResource', + 'angular-cache' + ]) + .service('PermissionEndpoint', require(rootPath + 'app/common/services/endpoints/permission.js')) + .config(require(rootPath + 'app/common/configs/cache-config.js')); + + require(rootPath + 'test/unit/simple-test-app-config.js')(testApp); + + angular.mock.module('testApp'); + }); + + beforeEach(inject(function (_$httpBackend_, _$rootScope_, _CONST_, _PermissionEndpoint_) { + $rootScope = _$rootScope_; + $httpBackend = _$httpBackend_; + BACKEND_URL = _CONST_.BACKEND_URL; + PermissionEndpoint = _PermissionEndpoint_; + })); + + describe('"permissions/:id" for data of all permissions', function () { + describe('get all permissions', function () { + + var mockPermissionsDataResponse; + + beforeEach(function () { + mockPermissionsDataResponse = + { + 'count': 2, + 'results': + [ + { + 'id': 1, + 'url': 'http://ushahidi-backend/api/v3/permissions/1', + 'permission': 'admin' + }, + { + 'id': 2, + 'url': 'http://ushahidi-backend/api/v3/permissions/2', + 'permission': 'member' + } + ] + }; + }); + + it('should call the correct url and parse and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + $httpBackend.expectGET(BACKEND_URL + '/api/v3/permissions').respond(mockPermissionDataResponse); + + PermissionEndpoint.queryFresh().$promise.then(successCallback); + + $httpBackend.flush(); + $rootScope.$digest(); + + expect(successCallback).toHaveBeenCalled(); + + var actualPermissionData = successCallback.calls.mostRecent().args[0]; + expect(actualPermissionData.results.length).toEqual(mockPermissionDataResponse.results.length); + expect(actualPermissionData.results[0].email).toEqual(mockPermissionDataResponse.results[0].email); + }); + }); + }); + + describe('"permissions/1" for specific permission', function () { + + var mockPermissionDataResponse; + + beforeEach(function () { + mockPermissionDataResponse = { + 'id': 1, + 'url': 'http://ushahidi-backend/api/v3/permissions/1', + 'permission': 'admin' + }; + }); + + describe('get permission data', function () { + it('should call the correct url and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + $httpBackend.expectGET(BACKEND_URL + '/api/v3/permissions/1').respond(mockPermissionDataResponse); + + PermissionEndpoint.get({id: '1'}).$promise.then(successCallback); + + $httpBackend.flush(); + $rootScope.$digest(); + + expect(successCallback).toHaveBeenCalled(); + + var actualPermissionData = successCallback.calls.mostRecent().args[0]; + expect(actualPermissionData.id).toEqual(mockPermissionDataResponse.id); + expect(actualPermissionData.realname).toEqual(mockPermissionDataResponse.realname); + expect(actualPermissionData.email).toEqual(mockPermissionDataResponse.email); + }); + }); + + describe('update permission data', function () { + + beforeEach(function () { + mockPermissionDataResponse = { + 'id': 2, + 'url': 'http://ushahidi-backend/api/v3/permissions/2', + 'permission': 'new' + }; + }); + + it('should call the correct url and return the updated permission data', function () { + var successCallback = jasmine.createSpy('success'); + $httpBackend.expectPUT(BACKEND_URL + '/api/v3/permissions/2').respond(mockPermissionDataResponse); + + var permissionDataToUpdate = { + 'permission': 'new' + }; + + PermissionEndpoint.update({id: '2'}, permissionDataToUpdate).$promise.then(successCallback); + + $httpBackend.flush(); + $rootScope.$digest(); + + expect(successCallback).toHaveBeenCalled(); + + var actualPermissionData = successCallback.calls.mostRecent().args[0]; + expect(actualPermissionData.id).toEqual(mockPermissionDataResponse.id); + expect(actualPermissionData.realname).toEqual(permissionDataToUpdate.realname); + expect(actualPermissionData.email).toEqual(permissionDataToUpdate.email); + }); + }); + + }); + +}); From 663290989c706d587ea541dcb14d073463d13358 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 4 Feb 2016 12:25:13 -0500 Subject: [PATCH 035/135] PermissionEndpoint set up --- app/common/common-module.js | 5 ++++- .../services/endpoints/{permissions.js => permission.js} | 0 2 files changed, 4 insertions(+), 1 deletion(-) rename app/common/services/endpoints/{permissions.js => permission.js} (100%) diff --git a/app/common/common-module.js b/app/common/common-module.js index 7eb31d7d4b..7dafc2a870 100644 --- a/app/common/common-module.js +++ b/app/common/common-module.js @@ -12,6 +12,7 @@ angular.module('ushahidi.common', [ .service('Authentication', require('./services/authentication.js')) .service('Session', require('./services/session.js')) + .service('ConfigEndpoint', require('./services/endpoints/config.js')) .service('UserEndpoint', require('./services/endpoints/user-endpoint.js')) .service('FormEndpoint', require('./services/endpoints/form.js')) @@ -19,8 +20,9 @@ angular.module('ushahidi.common', [ .service('FormStageEndpoint', require('./services/endpoints/form-stages.js')) .service('TagEndpoint', require('./services/endpoints/tag.js')) .service('RoleEndpoint', require('./services/endpoints/role.js')) +.service('PermissionEndpoint', require('./services/endpoints/permission.js')) .service('DataProviderEndpoint', require('./services/endpoints/data-providers.js')) -.service('FontAwesomeIcons', require('./services/endpoints/FontAwesomeIcons.js')) + .service('RoleHelper', require('./services/role-helper.js')) .service('PostViewHelper', require('./services/view-helper.js')) .service('Config', require('./services/config.js')) @@ -35,6 +37,7 @@ angular.module('ushahidi.common', [ .service('Registration', require('./services/registration.js')) .service('PasswordReset', require('./services/password-reset.js')) .service('IconManager', require('./services/icon-manager.js')) +.service('FontAwesomeIcons', require('./services/endpoints/FontAwesomeIcons.js')) .controller('navigation', require('./controllers/navigation.js')) .controller('PageMetadata', require('./controllers/page-metadata.js')) diff --git a/app/common/services/endpoints/permissions.js b/app/common/services/endpoints/permission.js similarity index 100% rename from app/common/services/endpoints/permissions.js rename to app/common/services/endpoints/permission.js From 4880e56999a98760031a93c212ca229b817dac32 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 4 Feb 2016 14:12:33 -0500 Subject: [PATCH 036/135] templates, directives and controller --- app/common/locales/en.json | 8 ++++ .../controllers/setting-roles-controller.js | 15 +++--- .../directives/setting-roles-directive.js | 41 +++++++++++++++++ .../setting-roles-editor-directive.js | 46 +++++++++++++++++++ app/setting/setting-module.js | 2 + app/setting/setting-routes.js | 10 +++- .../templates/settings/roles/roles-edit.html | 44 ++++++++++++++++++ .../www/templates/settings/roles/roles.html | 46 +++++++++++++++++++ 8 files changed, 204 insertions(+), 8 deletions(-) create mode 100644 app/setting/directives/setting-roles-directive.js create mode 100644 app/setting/directives/setting-roles-editor-directive.js create mode 100644 server/www/templates/settings/roles/roles-edit.html create mode 100644 server/www/templates/settings/roles/roles.html diff --git a/app/common/locales/en.json b/app/common/locales/en.json index 1d23497afe..8e6406b934 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -323,6 +323,10 @@ } } }, + "role": { + "add_role" : "Add Role", + "delete" : "Delete", + }, "set": { "create_collection" : "Create Collection", "create_savedsearch": "Create Saved Search", @@ -583,6 +587,9 @@ "destroy_error" : "Unable to delete category, please try again", "bulk_destroy_confirm" : "Are you sure you want to delete {{count}} categories?", "bulk_destroy_success" : "{{count}} categories deleted" + }, + "role" : { + }, "datasource" : { "save_success" : "Saved Data Source {{name}}", @@ -635,6 +642,7 @@ "post" : "No posts found.", "user" : "No users found.", "category" : "No categories found.", + "role" : "No roles found.", "form": "No forms found." }, "location": { diff --git a/app/setting/controllers/setting-roles-controller.js b/app/setting/controllers/setting-roles-controller.js index 8177fa0f14..64f1a2dc82 100644 --- a/app/setting/controllers/setting-roles-controller.js +++ b/app/setting/controllers/setting-roles-controller.js @@ -1,14 +1,15 @@ module.exports = [ '$scope', - '$translate', + 'RoleEndpoint', + 'PermissionEndpoint', function ( $scope, - $translate + RoleEndpoint, + PermissionEndpoint ) { - - $translate('tool.manage_roles').then(function (title) { - $scope.title = title; - $scope.$emit('setPageTitle', title); - }); + + RoleEndpoint.queryFresh().$promise.then(function (roles) { + $scope.roles = roles.results; + }); }]; diff --git a/app/setting/directives/setting-roles-directive.js b/app/setting/directives/setting-roles-directive.js new file mode 100644 index 0000000000..2f87b919d8 --- /dev/null +++ b/app/setting/directives/setting-roles-directive.js @@ -0,0 +1,41 @@ +module.exports = [ + '$translate', + '$location', + 'RoleEndpoint', + 'Notify', +function ( + $translate, + $location, + RoleEndpoint, + Notify +) { + return { + restrict: 'A', + link: function ($scope, $element, $attrs) { + handleResponseErrors = function (errorResponse) { + Notify.showApiErrors(errorResponse); + }; + + $scope.selectedRoles = []; + + $scope.deleteRoles = function () { + $translate('notify.role.bulk_destroy_confirm', { + count: $scope.selectedRoles.length + }).then(function (message) { + Notify.showConfirm(message).then(function () { + var calls = []; + angular.forEach($scope.selectedRoles, function (roleId) { + calls.push(RoleEndpoint.delete({ id: roleId }).$promise); + }); + + $q.all(calls).then(function () { + $translate('notify.user.bulk_destroy_success').then(function (message) { + Notify.showNotificationSlider(message); + }); + }, handleResponseErrors); + }, function () {}); + }); + }; + } + }; +}]; diff --git a/app/setting/directives/setting-roles-editor-directive.js b/app/setting/directives/setting-roles-editor-directive.js new file mode 100644 index 0000000000..f638799d00 --- /dev/null +++ b/app/setting/directives/setting-roles-editor-directive.js @@ -0,0 +1,46 @@ +module.exports = [ + '$translate', + '$location', + '$routeParams', + 'RoleEndpoint', + 'PermissionEndpoint', + 'Notify', +function ( + $translate, + $location, + $routeParams, + RoleEndpoint, + PermissionEndpoint, + Notify +) { + return { + restrict: 'A', + link: function ($scope, $element, $attrs) { + + $translate('role.add_role').then(function (title) { + $scope.title = title; + $scope.$emit('setPageTitle', title); + }); + + + PermissionEndpoint.query().$promise.then(function (permissions) { + $scope.permissions = permissions.results; + }); + + $scope.role = RoleEndpoint.getFresh({id: $routeParams.id}); + + $scope.saveRole = function (role) { + $scope.processing = true; + RoleEndpoint.saveCache(role).$promise.then(function (result) { + $rootScope.goBack(); + $translate('notify.role.save_success', {name: role.role}).then(function (message) { + Notify.showNotificationSlider(message); + }); + }, function (errorResponse) { // error + Notify.showApiErrors(errorResponse); + $scope.processing = false; + }); + }; + } + }; +}]; diff --git a/app/setting/setting-module.js b/app/setting/setting-module.js index 905fb8a359..8d9fea852a 100644 --- a/app/setting/setting-module.js +++ b/app/setting/setting-module.js @@ -9,6 +9,8 @@ angular.module('ushahidi.tools', [ .directive('mapperCsv', require('./directives/setting-data-mapper-directive.js')) .directive('formEditor', require('./directives/setting-form-editor-directive.js')) .directive('settingsEditor', require('./directives/setting-editor-directive.js')) +.directive('customRoles', require('./directives/setting-roles-directive.js')) +.directive('customRolesEditor', require('./directives/setting-roles-editor-directive.js')) .service('DataImportEndpoint', require('./services/endpoints/data-import.js')) diff --git a/app/setting/setting-routes.js b/app/setting/setting-routes.js index 1c3366a822..d3cb969a20 100644 --- a/app/setting/setting-routes.js +++ b/app/setting/setting-routes.js @@ -74,7 +74,15 @@ function ( }) .when('/settings/roles', { controller: require('./controllers/setting-roles-controller.js'), - templateUrl: 'templates/settings/todo.html' + templateUrl: 'templates/settings/roles/roles.html' + }) + .when('/settings/roles/create', { + controller: require('./controllers/setting-roles-controller.js'), + templateUrl: 'templates/settings/roles/roles-edit.html' + }) + .when('/settings/roles/:id', { + controller: require('./controllers/setting-roles-controller.js'), + templateUrl: 'templates/settings/roles/roles-edit.html' }) .when('/settings/datasources', { controller: require('./controllers/setting-datasources-controller.js'), diff --git a/server/www/templates/settings/roles/roles-edit.html b/server/www/templates/settings/roles/roles-edit.html new file mode 100644 index 0000000000..d42f0b4ba8 --- /dev/null +++ b/server/www/templates/settings/roles/roles-edit.html @@ -0,0 +1,44 @@ +
    + + +
    + +

    {{title}}

    + +
    + + + + + + + + + + + + + + +
    + +
    + + +
    +
    diff --git a/server/www/templates/settings/roles/roles.html b/server/www/templates/settings/roles/roles.html new file mode 100644 index 0000000000..703a0f6ad3 --- /dev/null +++ b/server/www/templates/settings/roles/roles.html @@ -0,0 +1,46 @@ +
    + +
    +
    + +
    +

    empty.role

    +
    + +
    + +
    + +
    + +
    +
    + +
    +
    + +

    + {{tag.tag}}

    +
    +

    {{role.description}}

    +
    +
    +
    + +
    +
    +
    From 199c4183c6088d45e67168983211bd93939f6cef Mon Sep 17 00:00:00 2001 From: will Date: Thu, 4 Feb 2016 14:13:54 -0500 Subject: [PATCH 037/135] first step of removing role-helper --- app/common/common-module.js | 1 - app/common/services/role-helper.js | 44 ------------------------------ 2 files changed, 45 deletions(-) delete mode 100644 app/common/services/role-helper.js diff --git a/app/common/common-module.js b/app/common/common-module.js index 7dafc2a870..7d3601e429 100644 --- a/app/common/common-module.js +++ b/app/common/common-module.js @@ -23,7 +23,6 @@ angular.module('ushahidi.common', [ .service('PermissionEndpoint', require('./services/endpoints/permission.js')) .service('DataProviderEndpoint', require('./services/endpoints/data-providers.js')) -.service('RoleHelper', require('./services/role-helper.js')) .service('PostViewHelper', require('./services/view-helper.js')) .service('Config', require('./services/config.js')) .service('Util', require('./services/util.js')) diff --git a/app/common/services/role-helper.js b/app/common/services/role-helper.js deleted file mode 100644 index 698b0dcd5f..0000000000 --- a/app/common/services/role-helper.js +++ /dev/null @@ -1,44 +0,0 @@ -module.exports = [ - '_', -function ( - _ -) { - var allRoles = [ - { - name: 'user', - display_name: 'Member' - }, - { - name: 'admin', - display_name: 'Admin' - } - ], - - rolesWithoutGuest = _.filter(allRoles, function (role) { - return role.name !== 'guest'; - }), - - RoleHelper = { - roles: function (includeGuest) { - return includeGuest ? allRoles : rolesWithoutGuest; - }, - getRole: function (role, roles) { - if (!roles) { - roles = allRoles; - } - var match = _.findWhere(roles, {name: role}); - return match ? match.display_name : role; - }, - getDefault: function (roles) { - if (!roles) { - roles = allRoles; - } - - // assuming the default role has a blank name - could change this to a db - // field but seemed a bit heavy-handed - var match = _.findWhere(roles, {name: ''}); - return match ? match.display_name : null; - } - }; - return RoleHelper; -}]; From 6765e9f109ba83f24555df9f5fe6477a0386a4ee Mon Sep 17 00:00:00 2001 From: will Date: Thu, 4 Feb 2016 14:24:02 -0500 Subject: [PATCH 038/135] change basic usage of role helper to role endpoint --- app/set/directives/collection-editor-directive.js | 6 +++--- app/set/directives/savedsearch-editor-directive.js | 6 +++--- app/setting/controllers/setting-categories-controller.js | 3 --- .../controllers/setting-categories-create-controller.js | 6 +++--- .../controllers/setting-categories-edit-controller.js | 6 +++--- app/setting/controllers/setting-users-controller.js | 7 +++---- app/setting/controllers/setting-users-create-controller.js | 6 +++--- app/setting/controllers/setting-users-edit-controller.js | 6 +++--- 8 files changed, 21 insertions(+), 25 deletions(-) diff --git a/app/set/directives/collection-editor-directive.js b/app/set/directives/collection-editor-directive.js index 4dda158b58..007d022461 100644 --- a/app/set/directives/collection-editor-directive.js +++ b/app/set/directives/collection-editor-directive.js @@ -7,7 +7,7 @@ module.exports = [ '_', 'Notify', 'PostViewHelper', - 'RoleHelper', + 'RoleEndpoint', function ( $q, $location, @@ -17,7 +17,7 @@ function ( _, Notify, PostViewHelper, - RoleHelper + RoleEndpoint ) { return { restrict: 'E', @@ -30,7 +30,7 @@ function ( link: function ($scope, $element, $attrs) { $scope.isAdmin = $rootScope.isAdmin; - $scope.roles = RoleHelper.roles(); + $scope.roles = RoleEndpoint.query(); $scope.views = PostViewHelper.views(); // Set default view for Collection to be Map diff --git a/app/set/directives/savedsearch-editor-directive.js b/app/set/directives/savedsearch-editor-directive.js index c6bcf5ad98..8da7da4c2c 100644 --- a/app/set/directives/savedsearch-editor-directive.js +++ b/app/set/directives/savedsearch-editor-directive.js @@ -7,7 +7,7 @@ module.exports = [ '_', 'Notify', 'PostViewHelper', - 'RoleHelper', + 'RoleEndpoint', function ( $q, $location, @@ -17,7 +17,7 @@ function ( _, Notify, PostViewHelper, - RoleHelper + RoleEndpoint ) { return { restrict: 'E', @@ -36,7 +36,7 @@ function ( $scope.isAdmin = $rootScope.isAdmin; - $scope.roles = RoleHelper.roles(); + $scope.roles = RoleEndpoint.query(); $scope.views = PostViewHelper.views(); $scope.cpySavedSearch = _.clone($scope.savedSearch); diff --git a/app/setting/controllers/setting-categories-controller.js b/app/setting/controllers/setting-categories-controller.js index c1267c9b0d..079dfde9c1 100644 --- a/app/setting/controllers/setting-categories-controller.js +++ b/app/setting/controllers/setting-categories-controller.js @@ -3,14 +3,12 @@ module.exports = [ '$translate', '$q', 'TagEndpoint', - 'RoleHelper', 'Notify', function ( $scope, $translate, $q, TagEndpoint, - RoleHelper, Notify ) { $translate('tool.manage_tags').then(function (title) { @@ -18,7 +16,6 @@ function ( $scope.$emit('setPageTitle', title); }); - $scope.getRole = RoleHelper.getRole; $scope.refreshView = function () { $scope.tags = TagEndpoint.query(); diff --git a/app/setting/controllers/setting-categories-create-controller.js b/app/setting/controllers/setting-categories-create-controller.js index 4060480e6b..6970c6bc59 100644 --- a/app/setting/controllers/setting-categories-create-controller.js +++ b/app/setting/controllers/setting-categories-create-controller.js @@ -3,7 +3,7 @@ module.exports = [ '$location', '$translate', 'multiTranslate', - 'RoleHelper', + 'RoleEndpoint', 'TagEndpoint', 'Notify', '_', @@ -12,7 +12,7 @@ function ( $location, $translate, multiTranslate, - RoleHelper, + RoleEndpoint, TagEndpoint, Notify, _ @@ -23,7 +23,7 @@ function ( }); $scope.types = multiTranslate(['tag.types.category', 'tag.types.status']); - $scope.roles = RoleHelper.roles(); + $scope.roles = RoleEndpoint.query(); $scope.tag = { type: 'category', icon: 'tag' }; $scope.processing = false; diff --git a/app/setting/controllers/setting-categories-edit-controller.js b/app/setting/controllers/setting-categories-edit-controller.js index 9319e9be00..02e302600e 100644 --- a/app/setting/controllers/setting-categories-edit-controller.js +++ b/app/setting/controllers/setting-categories-edit-controller.js @@ -4,7 +4,7 @@ module.exports = [ '$routeParams', '$translate', 'multiTranslate', - 'RoleHelper', + 'RoleEndpoint', 'TagEndpoint', 'Notify', '_', @@ -15,7 +15,7 @@ function ( $routeParams, $translate, multiTranslate, - RoleHelper, + RoleEndpoint, TagEndpoint, Notify, _, @@ -27,7 +27,7 @@ function ( }); $scope.types = multiTranslate(['tag.types.category', 'tag.types.status']); - $scope.roles = RoleHelper.roles(); + $scope.roles = RoleEndpoint.query(); $scope.tag = TagEndpoint.getFresh({id: $routeParams.id}); $scope.processing = false; diff --git a/app/setting/controllers/setting-users-controller.js b/app/setting/controllers/setting-users-controller.js index c8761d6b6e..b3d542ed9f 100644 --- a/app/setting/controllers/setting-users-controller.js +++ b/app/setting/controllers/setting-users-controller.js @@ -8,7 +8,7 @@ module.exports = [ 'Session', 'UserEndpoint', 'Notify', - 'RoleHelper', + 'RoleEndpoint', function ( $scope, $translate, @@ -19,7 +19,7 @@ function ( Session, UserEndpoint, Notify, - RoleHelper + RoleEndpoint ) { var handleResponseErrors, checkAndNotifyAboutManipulateOwnUser, getUsersForPagination; @@ -28,8 +28,7 @@ function ( $scope.$emit('setPageTitle', title); }); - $scope.roles = RoleHelper.roles(true); - $scope.getRole = RoleHelper.getRole; + $scope.roles = RoleEndpoint.query(); $scope.filter = { role: '', diff --git a/app/setting/controllers/setting-users-create-controller.js b/app/setting/controllers/setting-users-create-controller.js index 8a7c7d5726..bc8a488cee 100644 --- a/app/setting/controllers/setting-users-create-controller.js +++ b/app/setting/controllers/setting-users-create-controller.js @@ -6,7 +6,7 @@ module.exports = [ 'UserEndpoint', 'Notify', '_', - 'RoleHelper', + 'RoleEndpoint', function ( $scope, $rootScope, @@ -15,7 +15,7 @@ function ( UserEndpoint, Notify, _, - RoleHelper + RoleEndpoint ) { $translate('user.add_user').then(function (title) { $scope.title = title; @@ -43,5 +43,5 @@ function ( }); }; - $scope.roles = RoleHelper.roles(true); + $scope.roles = RoleEndpoint.query(); }]; diff --git a/app/setting/controllers/setting-users-edit-controller.js b/app/setting/controllers/setting-users-edit-controller.js index f2f0912604..43fa51c9a9 100644 --- a/app/setting/controllers/setting-users-edit-controller.js +++ b/app/setting/controllers/setting-users-edit-controller.js @@ -7,7 +7,7 @@ module.exports = [ 'UserEndpoint', 'Notify', '_', - 'RoleHelper', + 'RoleEndpoint', function ( $scope, $rootScope, @@ -17,7 +17,7 @@ function ( UserEndpoint, Notify, _, - RoleHelper + RoleEndpoint ) { $translate('user.edit_user').then(function (title) { $scope.title = title; @@ -49,5 +49,5 @@ function ( }); }; - $scope.roles = RoleHelper.roles(true); + $scope.roles = RoleEndpoint.query(); }]; From 53194b047c0e786f16eebeeb773fec874d494eba Mon Sep 17 00:00:00 2001 From: will Date: Fri, 5 Feb 2016 20:29:30 -0500 Subject: [PATCH 039/135] replaced rolehelper with roleendpoint --- app/post/controllers/post-detail-controller.js | 10 +++++----- app/post/directives/post-editor-directive.js | 7 +++---- app/post/directives/post-preview-directive.js | 14 +++++++------- server/www/templates/posts/detail.html | 4 ++-- server/www/templates/posts/post-editor.html | 4 ++-- server/www/templates/posts/preview.html | 4 ++-- server/www/templates/settings/roles-edit.html | 0 server/www/templates/settings/roles.html | 0 .../www/templates/settings/roles/roles-edit.html | 8 -------- 9 files changed, 21 insertions(+), 30 deletions(-) delete mode 100644 server/www/templates/settings/roles-edit.html delete mode 100644 server/www/templates/settings/roles.html diff --git a/app/post/controllers/post-detail-controller.js b/app/post/controllers/post-detail-controller.js index d41e735a09..fba9c42ac3 100644 --- a/app/post/controllers/post-detail-controller.js +++ b/app/post/controllers/post-detail-controller.js @@ -18,7 +18,7 @@ module.exports = [ 'Leaflet', 'leafletData', '_', - 'RoleHelper', + 'RoleEndpoint', 'Notify', function ( $scope, @@ -40,19 +40,19 @@ function ( L, leafletData, _, - RoleHelper, + RoleEndpoint, Notify ) { $scope.post = post; $scope.mapDataLoaded = false; - $scope.availableRoles = RoleHelper.roles(); + $scope.availableRoles = RoleEndpoint.query(); $scope.publishedFor = function () { if ($scope.post.status === 'draft') { return 'post.publish_for_you'; } if (!_.isEmpty($scope.post.published_to)) { - return RoleHelper.getRole($scope.post.published_to[0]); + return RoleEndpoint.get({id:$scope.post.published_to[0]}); } return 'post.publish_for_everyone'; @@ -349,7 +349,7 @@ function ( PostEndpoint.update($scope.post). $promise .then(function () { - var role = $scope.publishRole === '' ? 'Everyone' : RoleHelper.getRole($scope.publishRole); + var role = $scope.publishRole === '' ? 'Everyone' : RoleEndpoint.getRole({id: $scope.publishRole}); var message = post.status === 'draft' ? 'notify.post.set_draft' : 'notify.post.publish_success'; $translate(message, { role: role }) .then(function (message) { diff --git a/app/post/directives/post-editor-directive.js b/app/post/directives/post-editor-directive.js index d0b9ec2aca..70fddcec7d 100644 --- a/app/post/directives/post-editor-directive.js +++ b/app/post/directives/post-editor-directive.js @@ -8,7 +8,7 @@ function ( '$translate', 'PostEntity', 'PostEndpoint', - 'RoleHelper', + 'RoleEndpoint', 'TagEndpoint', 'FormEndpoint', 'FormStageEndpoint', @@ -22,7 +22,7 @@ function ( $translate, postEntity, PostEndpoint, - RoleHelper, + RoleEndpoint, TagEndpoint, FormEndpoint, FormStageEndpoint, @@ -32,8 +32,7 @@ function ( ) { $scope.categories = TagEndpoint.query(); - $scope.availableRoles = RoleHelper.roles(); - $scope.getRoleDisplayName = RoleHelper.getRole; + $scope.availableRoles = RoleEndpoint.query(); $scope.everyone = $filter('translate')('post.modify.everyone'); $scope.isEdit = !!$scope.post.id; $scope.validationErrors = []; diff --git a/app/post/directives/post-preview-directive.js b/app/post/directives/post-preview-directive.js index 41c28a1af4..b0ddf1d111 100644 --- a/app/post/directives/post-preview-directive.js +++ b/app/post/directives/post-preview-directive.js @@ -9,7 +9,7 @@ module.exports = [ 'UserEndpoint', 'FormEndpoint', 'FormStageEndpoint', - 'RoleHelper', + 'RoleEndpoint', 'Notify', '_', function ( @@ -23,7 +23,7 @@ function ( UserEndpoint, FormEndpoint, FormStageEndpoint, - RoleHelper, + RoleEndpoint, Notify, _ ) { @@ -71,19 +71,19 @@ function ( link: function ($scope) { $scope.showNewCollectionInput = false; $scope.newCollection = ''; - $scope.getRoleDisplayName = RoleHelper.getRole; - $scope.availableRoles = RoleHelper.roles(); + $scope.availableRoles = RoleEndpoint.query(); $scope.publishedFor = function () { if ($scope.post.status === 'draft') { return 'post.publish_for_you'; } if (!_.isEmpty($scope.post.published_to)) { - return RoleHelper.getRole($scope.post.published_to[0]); + return RoleEndpoint.get({id: $scope.post.published_to[0]}); } return 'post.publish_for_everyone'; }; + // Ensure completes stages array is numeric $scope.updateSelectedItems = function () { $rootScope.$broadcast('event:post:selection', $scope.post); @@ -186,9 +186,9 @@ function ( PostEndpoint.update($scope.post). $promise .then(function (post) { - var role = $scope.publishRole === '' ? 'Everyone' : RoleHelper.getRole($scope.publishRole); + var role = $scope.publishRole === '' ? 'Everyone' : RoleEndpoint.getRole({id: $scope.publishRole}); var message = post.status === 'draft' ? 'notify.post.set_draft' : 'notify.post.publish_success'; - $translate(message, {role: role}) + $translate(message, {role: role.name}) .then(function (message) { Notify.showNotificationSlider(message); }); diff --git a/server/www/templates/posts/detail.html b/server/www/templates/posts/detail.html index 94bb1d665a..d9198a9c1c 100644 --- a/server/www/templates/posts/detail.html +++ b/server/www/templates/posts/detail.html @@ -25,9 +25,9 @@

    diff --git a/server/www/templates/settings/roles-edit.html b/server/www/templates/settings/roles-edit.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/server/www/templates/settings/roles.html b/server/www/templates/settings/roles.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/server/www/templates/settings/roles/roles-edit.html b/server/www/templates/settings/roles/roles-edit.html index d42f0b4ba8..e46022e1c9 100644 --- a/server/www/templates/settings/roles/roles-edit.html +++ b/server/www/templates/settings/roles/roles-edit.html @@ -24,14 +24,6 @@

    {{title}}

    ng-maxlength="150" ng-model="tag.description"> - - - - - -

    data_import.csv

    -
    -
    - -

    - {{tag.tag}}

    -
    -

    {{role.description}}

    -
    -
    - - From d6a5d513cb736792fa741557c104f2ad6174dbf3 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 15:30:12 -0500 Subject: [PATCH 063/135] role and permission editing ux created --- app/common/locales/en.json | 10 ++- app/common/services/endpoints/permission.js | 1 - .../controllers/setting-roles-controller.js | 5 -- .../directives/setting-roles-directive.js | 38 +++------ .../setting-roles-editor-directive.js | 22 +++-- .../templates/settings/roles/roles-edit.html | 80 ++++++++++++------- .../www/templates/settings/roles/roles.html | 8 +- 7 files changed, 90 insertions(+), 74 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index 8e6406b934..b03aef7017 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -325,6 +325,11 @@ }, "role": { "add_role" : "Add Role", + "edit_role" : "Edit Role", + "name" : "Name", + "description" : "Description", + "save" : "Save Role", + "permissions" : "Permissions", "delete" : "Delete", }, "set": { @@ -589,7 +594,9 @@ "bulk_destroy_success" : "{{count}} categories deleted" }, "role" : { - + "delete_question" : "Are you sure you want to delete the role {{role}}?", + "destroy_success" : "Role {{role}} deleted.", + "save_success" : "Role {{role}} saved.", }, "datasource" : { "save_success" : "Saved Data Source {{name}}", @@ -643,6 +650,7 @@ "user" : "No users found.", "category" : "No categories found.", "role" : "No roles found.", + "permission" : "No permissions found.", "form": "No forms found." }, "location": { diff --git a/app/common/services/endpoints/permission.js b/app/common/services/endpoints/permission.js index 000ca9d2ab..4844d69c10 100644 --- a/app/common/services/endpoints/permission.js +++ b/app/common/services/endpoints/permission.js @@ -22,7 +22,6 @@ function ( }, { query: { method: 'GET', - isArray: true, transpermissionResponse: function (data /*, header*/) { return Util.transformResponse(data).results; } diff --git a/app/setting/controllers/setting-roles-controller.js b/app/setting/controllers/setting-roles-controller.js index 64f1a2dc82..2b6da52f5c 100644 --- a/app/setting/controllers/setting-roles-controller.js +++ b/app/setting/controllers/setting-roles-controller.js @@ -7,9 +7,4 @@ function ( RoleEndpoint, PermissionEndpoint ) { - - RoleEndpoint.queryFresh().$promise.then(function (roles) { - $scope.roles = roles.results; - }); - }]; diff --git a/app/setting/directives/setting-roles-directive.js b/app/setting/directives/setting-roles-directive.js index 7e65c7540d..a5610c1785 100644 --- a/app/setting/directives/setting-roles-directive.js +++ b/app/setting/directives/setting-roles-directive.js @@ -17,47 +17,29 @@ function ( }; $scope.refreshView = function () { - $scope.roles = RoleEndpoint.query(); - $scope.selectedRoles = []; + RoleEndpoint.queryFresh().$promise.then(function (roles) { + $scope.roles = roles; + }); }; $scope.refreshView(); - $scope.selectedRoles = []; - - $scope.deleteRoles = function () { - $translate('notify.role.bulk_destroy_confirm', { - count: $scope.selectedRoles.length + $scope.deleteRole = function (role) { + $translate('notify.role.delete_question', { + role: role.display_name }).then(function (message) { Notify.showConfirm(message).then(function () { - var calls = []; - angular.forEach($scope.selectedRoles, function (roleId) { - calls.push(RoleEndpoint.delete({ id: roleId }).$promise); - }); - - $q.all(calls).then(function () { - $translate('notify.user.bulk_destroy_success').then(function (message) { + RoleEndpoint.delete({ id: role.id }).$promise.then(function () { + $translate('notify.role.destroy_success', { + role: role.display_name + }).then(function (message) { Notify.showNotificationSlider(message); }); - $scope.refreshView(); }, handleResponseErrors); }, function () {}); }); }; - - $scope.isToggled = function (role) { - return $scope.selectedRoles.indexOf(role.id) > -1; - }; - - $scope.toggleRole = function (role) { - var idx = $scope.selectedRoles.indexOf(role.id); - if (idx > -1) { - $scope.selectedRoles.splice(idx, 1); - } else { - $scope.selectedRoles.push(role.id); - } - }; } }; }]; diff --git a/app/setting/directives/setting-roles-editor-directive.js b/app/setting/directives/setting-roles-editor-directive.js index f638799d00..d6d546109c 100644 --- a/app/setting/directives/setting-roles-editor-directive.js +++ b/app/setting/directives/setting-roles-editor-directive.js @@ -17,9 +17,15 @@ function ( restrict: 'A', link: function ($scope, $element, $attrs) { - $translate('role.add_role').then(function (title) { - $scope.title = title; - $scope.$emit('setPageTitle', title); + RoleEndpoint.getFresh({id: $routeParams.id}).$promise.then(function (role) { + $scope.role = role; + + $scope.title = $scope.role.id ? 'role.edit_role' : 'role.add_role'; + + $translate($scope.title).then(function (title) { + $scope.title = title; + $scope.$emit('setPageTitle', title); + }); }); @@ -27,19 +33,19 @@ function ( $scope.permissions = permissions.results; }); - $scope.role = RoleEndpoint.getFresh({id: $routeParams.id}); - $scope.saveRole = function (role) { $scope.processing = true; + role.name = role.display_name; + RoleEndpoint.saveCache(role).$promise.then(function (result) { - $rootScope.goBack(); - $translate('notify.role.save_success', {name: role.role}).then(function (message) { + $translate('notify.role.save_success', {role: role.display_name}).then(function (message) { Notify.showNotificationSlider(message); + $location.path('/settings/roles/' + response.id); }); }, function (errorResponse) { // error Notify.showApiErrors(errorResponse); - $scope.processing = false; }); + $scope.processing = false; }; } }; diff --git a/server/www/templates/settings/roles/roles-edit.html b/server/www/templates/settings/roles/roles-edit.html index e46022e1c9..deeb626fc9 100644 --- a/server/www/templates/settings/roles/roles-edit.html +++ b/server/www/templates/settings/roles/roles-edit.html @@ -1,36 +1,62 @@ -
    - +
    +
    - -

    {{title}}

    - -
    +
    + + +
    - - +
    + + +
    - - +
    + role.permissions -
    - -
    - +
    +

    empty.permission

    +
    +
    + +
    +
    +
    diff --git a/server/www/templates/settings/roles/roles.html b/server/www/templates/settings/roles/roles.html index e704cd69b8..565673ddf6 100644 --- a/server/www/templates/settings/roles/roles.html +++ b/server/www/templates/settings/roles/roles.html @@ -19,17 +19,17 @@

    tool.manage_roles

    -
    -

    empty.role

    +
    +

    empty.role

    From ce11f9ed4e79366b31f838038546590dab164ee3 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 15:31:39 -0500 Subject: [PATCH 064/135] typoe --- app/setting/directives/setting-roles-editor-directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/setting/directives/setting-roles-editor-directive.js b/app/setting/directives/setting-roles-editor-directive.js index d6d546109c..5542351817 100644 --- a/app/setting/directives/setting-roles-editor-directive.js +++ b/app/setting/directives/setting-roles-editor-directive.js @@ -40,7 +40,7 @@ function ( RoleEndpoint.saveCache(role).$promise.then(function (result) { $translate('notify.role.save_success', {role: role.display_name}).then(function (message) { Notify.showNotificationSlider(message); - $location.path('/settings/roles/' + response.id); + $location.path('/settings/roles/' + result.id); }); }, function (errorResponse) { // error Notify.showApiErrors(errorResponse); From b13a19417758b1b634313f7ad3073e72c6371fdc Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 15:52:33 -0500 Subject: [PATCH 065/135] updating test: removed rolehelper added endpoints --- .../endpoints/permission-endpoint-spec.js | 114 ++++++------ .../services/endpoints/role-endpoint-spec.js | 164 ++++++++++++++---- test/unit/common/services/role-helper-spec.js | 62 ------- 3 files changed, 200 insertions(+), 140 deletions(-) delete mode 100644 test/unit/common/services/role-helper-spec.js diff --git a/test/unit/common/services/endpoints/permission-endpoint-spec.js b/test/unit/common/services/endpoints/permission-endpoint-spec.js index 5c7ebad8bb..ded95c53dc 100644 --- a/test/unit/common/services/endpoints/permission-endpoint-spec.js +++ b/test/unit/common/services/endpoints/permission-endpoint-spec.js @@ -31,31 +31,53 @@ describe('PermissionEndpoint', function () { describe('"permissions/:id" for data of all permissions', function () { describe('get all permissions', function () { - var mockPermissionsDataResponse; + var mockPermissionDataResponse; beforeEach(function () { - mockPermissionsDataResponse = + mockPermissionDataResponse = { 'count': 2, - 'results': - [ + 'results': [ { 'id': 1, - 'url': 'http://ushahidi-backend/api/v3/permissions/1', - 'permission': 'admin' + 'url': 'http://192.168.33.110/api/v3/permissions/1', + 'description': null, + 'name': 'test permission', + 'display_name': 'Test permission', + 'created': '1970-01-01T00:00:00+00:00', + 'permission': null, + 'allowed_privileges': [ + 'read', + 'search' + ] }, { 'id': 2, - 'url': 'http://ushahidi-backend/api/v3/permissions/2', - 'permission': 'member' + 'url': 'http://192.168.33.110/api/v3/permissions/2', + 'description': 'test desc', + 'name': 'test permission', + 'display_name': 'Test permission', + 'created': '1970-01-01T00:00:00+00:00', + 'allowed_privileges': [ + 'read', + 'search' + ] } - ] + ], + 'limit': null, + 'offset': 0, + 'order': 'asc', + 'orderby': 'id', + 'curr': 'http://192.168.33.110/api/v3/permissions?orderby=id&order=asc&offset=0', + 'next': 'http://192.168.33.110/api/v3/permissions?orderby=id&order=asc&offset=0', + 'prev': 'http://192.168.33.110/api/v3/permissions?orderby=id&order=asc&offset=0', + 'total_count': 2 }; }); it('should call the correct url and parse and return the correct data', function () { var successCallback = jasmine.createSpy('success'); - $httpBackend.expectGET(BACKEND_URL + '/api/v3/permissions').respond(mockPermissionDataResponse); + $httpBackend.expectGET(BACKEND_URL + '/api/v2/permissions').respond(mockPermissionDataResponse); PermissionEndpoint.queryFresh().$promise.then(successCallback); @@ -64,31 +86,49 @@ describe('PermissionEndpoint', function () { expect(successCallback).toHaveBeenCalled(); - var actualPermissionData = successCallback.calls.mostRecent().args[0]; - expect(actualPermissionData.results.length).toEqual(mockPermissionDataResponse.results.length); - expect(actualPermissionData.results[0].email).toEqual(mockPermissionDataResponse.results[0].email); + var actualPermissionData = successCallback.calls.mostRecent().args[0].results; + expect(actualPermissionData.length).toEqual(mockPermissionDataResponse.results.length); + expect(actualPermissionData[0].name).toEqual(mockPermissionDataResponse.results[0].name); + }); + + it('using queryFresh should call the correct url and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + + spyOn(PermissionEndpoint, 'query').and.callThrough(); + + PermissionEndpoint.queryFresh().$promise.then(successCallback); + + expect(PermissionEndpoint.query).toHaveBeenCalled(); }); + }); }); - describe('"permissions/1" for specific permission', function () { + describe('get data for "permissions/1"', function () { var mockPermissionDataResponse; beforeEach(function () { mockPermissionDataResponse = { 'id': 1, - 'url': 'http://ushahidi-backend/api/v3/permissions/1', - 'permission': 'admin' + 'url': 'http://192.168.33.110/api/v3/permissions/1', + 'name': 'test permission', + 'display_name': ' Test permission', + 'description': null, + 'created': '1970-01-01T00:00:00+00:00', + 'allowed_privileges': [ + 'read', + 'search' + ] }; }); describe('get permission data', function () { it('should call the correct url and return the correct data', function () { var successCallback = jasmine.createSpy('success'); - $httpBackend.expectGET(BACKEND_URL + '/api/v3/permissions/1').respond(mockPermissionDataResponse); + $httpBackend.expectGET(BACKEND_URL + '/api/v2/permissions/1').respond(mockPermissionDataResponse); - PermissionEndpoint.get({id: '1'}).$promise.then(successCallback); + PermissionEndpoint.get({id: 1}).$promise.then(successCallback); $httpBackend.flush(); $rootScope.$digest(); @@ -97,43 +137,19 @@ describe('PermissionEndpoint', function () { var actualPermissionData = successCallback.calls.mostRecent().args[0]; expect(actualPermissionData.id).toEqual(mockPermissionDataResponse.id); - expect(actualPermissionData.realname).toEqual(mockPermissionDataResponse.realname); - expect(actualPermissionData.email).toEqual(mockPermissionDataResponse.email); + expect(actualPermissionData.display_name).toEqual(mockPermissionDataResponse.display_name); + expect(actualPermissionData.name).toEqual(mockPermissionDataResponse.name); }); - }); - - describe('update permission data', function () { - beforeEach(function () { - mockPermissionDataResponse = { - 'id': 2, - 'url': 'http://ushahidi-backend/api/v3/permissions/2', - 'permission': 'new' - }; - }); - - it('should call the correct url and return the updated permission data', function () { + it('using getFresh should call the correct url and return the correct data', function () { var successCallback = jasmine.createSpy('success'); - $httpBackend.expectPUT(BACKEND_URL + '/api/v3/permissions/2').respond(mockPermissionDataResponse); - - var permissionDataToUpdate = { - 'permission': 'new' - }; - PermissionEndpoint.update({id: '2'}, permissionDataToUpdate).$promise.then(successCallback); + spyOn(PermissionEndpoint, 'get').and.callThrough(); - $httpBackend.flush(); - $rootScope.$digest(); - - expect(successCallback).toHaveBeenCalled(); - - var actualPermissionData = successCallback.calls.mostRecent().args[0]; - expect(actualPermissionData.id).toEqual(mockPermissionDataResponse.id); - expect(actualPermissionData.realname).toEqual(permissionDataToUpdate.realname); - expect(actualPermissionData.email).toEqual(permissionDataToUpdate.email); + PermissionEndpoint.getFresh({id: 1}).$promise.then(successCallback); + expect(PermissionEndpoint.get).toHaveBeenCalled(); }); - }); + }); }); - }); diff --git a/test/unit/common/services/endpoints/role-endpoint-spec.js b/test/unit/common/services/endpoints/role-endpoint-spec.js index 2780e87420..64580a32a9 100644 --- a/test/unit/common/services/endpoints/role-endpoint-spec.js +++ b/test/unit/common/services/endpoints/role-endpoint-spec.js @@ -31,31 +31,61 @@ describe('RoleEndpoint', function () { describe('"roles/:id" for data of all roles', function () { describe('get all roles', function () { - var mockRolesDataResponse; + var mockRoleDataResponse; beforeEach(function () { - mockRolesDataResponse = + mockRoleDataResponse = { 'count': 2, - 'results': - [ + 'results': [ { 'id': 1, - 'url': 'http://ushahidi-backend/api/v3/roles/1', - 'role': 'admin' + 'url': 'http://192.168.33.110/api/v3/roles/1', + 'description': null, + 'name': 'test role', + 'permissions': ['Manage Users', 'Manage Posts'], + 'display_name': 'Test role', + 'created': '1970-01-01T00:00:00+00:00', + 'role': null, + 'allowed_privileges': [ + 'read', + 'create', + 'update', + 'delete', + 'search' + ] }, { 'id': 2, - 'url': 'http://ushahidi-backend/api/v3/roles/2', - 'role': 'member' + 'url': 'http://192.168.33.110/api/v3/roles/2', + 'description': 'test desc', + 'name': 'test role', + 'permissions': ['Manage Users', 'Manage Posts'], + 'display_name': 'Test role', + 'created': '1970-01-01T00:00:00+00:00', + 'allowed_privileges': [ + 'read', + 'create', + 'update', + 'delete', + 'search' + ] } - ] + ], + 'limit': null, + 'offset': 0, + 'order': 'asc', + 'orderby': 'id', + 'curr': 'http://192.168.33.110/api/v3/roles?orderby=id&order=asc&offset=0', + 'next': 'http://192.168.33.110/api/v3/roles?orderby=id&order=asc&offset=0', + 'prev': 'http://192.168.33.110/api/v3/roles?orderby=id&order=asc&offset=0', + 'total_count': 2 }; }); it('should call the correct url and parse and return the correct data', function () { var successCallback = jasmine.createSpy('success'); - $httpBackend.expectGET(BACKEND_URL + '/api/v3/roles').respond(mockRoleDataResponse); + $httpBackend.expectGET(BACKEND_URL + '/api/v2/roles').respond(mockRoleDataResponse); RoleEndpoint.queryFresh().$promise.then(successCallback); @@ -65,30 +95,52 @@ describe('RoleEndpoint', function () { expect(successCallback).toHaveBeenCalled(); var actualRoleData = successCallback.calls.mostRecent().args[0]; - expect(actualRoleData.results.length).toEqual(mockRoleDataResponse.results.length); - expect(actualRoleData.results[0].email).toEqual(mockRoleDataResponse.results[0].email); + expect(actualRoleData.length).toEqual(mockRoleDataResponse.results.length); + expect(actualRoleData[0].name).toEqual(mockRoleDataResponse.results[0].name); + }); + + it('using queryFresh should call the correct url and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + + spyOn(RoleEndpoint, 'query').and.callThrough(); + + RoleEndpoint.queryFresh().$promise.then(successCallback); + + expect(RoleEndpoint.query).toHaveBeenCalled(); }); + }); }); - describe('"roles/1" for specific role', function () { + describe('get data for "roles/1"', function () { var mockRoleDataResponse; beforeEach(function () { mockRoleDataResponse = { 'id': 1, - 'url': 'http://ushahidi-backend/api/v3/roles/1', - 'role': 'admin' + 'url': 'http://192.168.33.110/api/v3/roles/1', + 'name': 'test role', + 'display_name': ' Test role', + 'description': null, + 'permissions': ['Manage users'], + 'created': '1970-01-01T00:00:00+00:00', + 'allowed_privileges': [ + 'read', + 'create', + 'update', + 'delete', + 'search' + ] }; }); describe('get role data', function () { it('should call the correct url and return the correct data', function () { var successCallback = jasmine.createSpy('success'); - $httpBackend.expectGET(BACKEND_URL + '/api/v3/roles/1').respond(mockRoleDataResponse); + $httpBackend.expectGET(BACKEND_URL + '/api/v2/roles/1').respond(mockRoleDataResponse); - RoleEndpoint.get({id: '1'}).$promise.then(successCallback); + RoleEndpoint.get({id: 1}).$promise.then(successCallback); $httpBackend.flush(); $rootScope.$digest(); @@ -97,30 +149,53 @@ describe('RoleEndpoint', function () { var actualRoleData = successCallback.calls.mostRecent().args[0]; expect(actualRoleData.id).toEqual(mockRoleDataResponse.id); - expect(actualRoleData.realname).toEqual(mockRoleDataResponse.realname); - expect(actualRoleData.email).toEqual(mockRoleDataResponse.email); + expect(actualRoleData.display_name).toEqual(mockRoleDataResponse.display_name); + expect(actualRoleData.name).toEqual(mockRoleDataResponse.name); + }); + + it('using getFresh should call the correct url and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + + spyOn(RoleEndpoint, 'get').and.callThrough(); + + RoleEndpoint.getFresh({id: 1}).$promise.then(successCallback); + expect(RoleEndpoint.get).toHaveBeenCalled(); }); + }); describe('update role data', function () { beforeEach(function () { mockRoleDataResponse = { - 'id': 2, - 'url': 'http://ushahidi-backend/api/v3/roles/2', - 'role': 'new' + 'id': 1, + 'url': 'http://192.168.33.110/api/v3/roles/1', + 'name': 'Test role', + 'display_name': ' Test role', + 'description': 'Test', + 'permissions': ['Manage users'], + 'created': '1970-01-01T00:00:00+00:00', + 'allowed_privileges': [ + 'read', + 'create', + 'update', + 'delete', + 'search' + ] }; }); it('should call the correct url and return the updated role data', function () { var successCallback = jasmine.createSpy('success'); - $httpBackend.expectPUT(BACKEND_URL + '/api/v3/roles/2').respond(mockRoleDataResponse); + $httpBackend.expectPUT(BACKEND_URL + '/api/v2/roles/1').respond(mockRoleDataResponse); var roleDataToUpdate = { - 'role': 'new' + 'id': 1, + 'name': 'Test role', + 'description': 'Test' }; - RoleEndpoint.update({id: '2'}, roleDataToUpdate).$promise.then(successCallback); + RoleEndpoint.update(roleDataToUpdate).$promise.then(successCallback); $httpBackend.flush(); $rootScope.$digest(); @@ -129,11 +204,42 @@ describe('RoleEndpoint', function () { var actualRoleData = successCallback.calls.mostRecent().args[0]; expect(actualRoleData.id).toEqual(mockRoleDataResponse.id); - expect(actualRoleData.realname).toEqual(roleDataToUpdate.realname); - expect(actualRoleData.email).toEqual(roleDataToUpdate.email); + expect(actualRoleData.name).toEqual(roleDataToUpdate.name); + expect(actualRoleData.description).toEqual(roleDataToUpdate.description); }); - }); - }); + it('using saveCache should call the correct url and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + + spyOn(RoleEndpoint, 'update').and.callThrough(); + RoleEndpoint.saveCache({id: 1}).$promise.then(successCallback); + expect(RoleEndpoint.update).toHaveBeenCalled(); + }); + + it('should return an id when deleting an entity', function () { + var successCallback = jasmine.createSpy('success'); + $httpBackend.expectDELETE(BACKEND_URL + '/api/v2/roles/1').respond(mockRoleDataResponse); + + RoleEndpoint.deleteEntity({id: 1}).$promise.then(successCallback); + + $httpBackend.flush(); + $rootScope.$digest(); + + expect(successCallback).toHaveBeenCalled(); + + var actualRoleData = successCallback.calls.mostRecent().args[0]; + expect(actualRoleData.id).toEqual(mockRoleDataResponse.id); + }); + + it('using delete should call the correct url and return the correct data', function () { + var successCallback = jasmine.createSpy('success'); + + spyOn(RoleEndpoint, 'deleteEntity').and.callThrough(); + + RoleEndpoint.delete({id: 1}).$promise.then(successCallback); + expect(RoleEndpoint.deleteEntity).toHaveBeenCalled(); + }); + }); + }); }); diff --git a/test/unit/common/services/role-helper-spec.js b/test/unit/common/services/role-helper-spec.js deleted file mode 100644 index 6880a49b57..0000000000 --- a/test/unit/common/services/role-helper-spec.js +++ /dev/null @@ -1,62 +0,0 @@ -var ROOT_PATH = '../../../../'; - -describe('role helper', function () { - - var RoleHelper; - - beforeEach(function () { - var testApp = angular.module('testApp', [ - 'pascalprecht.translate' - ]) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')) - .config(require(ROOT_PATH + 'app/common/configs/locale-config.js')); - - require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); - - angular.mock.module('testApp'); - }); - - beforeEach(inject(function (_RoleHelper_) { - RoleHelper = _RoleHelper_; - })); - - describe('some existing role names', function () { - var existingRoles; - - beforeEach(function () { - existingRoles = [ - { - name: 'admin', - display_name: 'Admin' - } - ]; - }); - - describe('returned role', function () { - - var returnedRole; - - describe('with an existing role name', function () { - - beforeEach(function () { - returnedRole = RoleHelper.getRole('admin', existingRoles); - }); - - it('should return the display_name for the role name', function () { - expect(returnedRole).toEqual('Admin'); - }); - }); - - describe('with an non existing role name', function () { - beforeEach(function () { - returnedRole = RoleHelper.getRole('foo', existingRoles); - }); - - it('should return the value of the input role', function () { - expect(returnedRole).toEqual('foo'); - }); - }); - - }); - }); -}); From 353a887439d0d947b0a3a507ae7664de7e561314 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 15:55:45 -0500 Subject: [PATCH 066/135] changed post detail test to remove rolehelper and add role endpoint --- test/karma.conf.js | 2 ++ test/unit/post/controllers/post-detail-controller-spec.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/karma.conf.js b/test/karma.conf.js index 3b1404b09a..a1e2649a56 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -15,6 +15,8 @@ module.exports = function (config) { 'app/common/**/*.js', 'app/post/**/*.js', 'app/set/**/*.js', + 'app/setting/**/*.js', + 'app/activity/**/*.js', 'app/user-profile/**/*.js', 'app/common/locales/**/*.json', 'test/unit/**/*.js', diff --git a/test/unit/post/controllers/post-detail-controller-spec.js b/test/unit/post/controllers/post-detail-controller-spec.js index e7e980b0f7..7558a9005f 100644 --- a/test/unit/post/controllers/post-detail-controller-spec.js +++ b/test/unit/post/controllers/post-detail-controller-spec.js @@ -15,6 +15,7 @@ describe('Post detail controller', function () { .controller('postDetailController', require(ROOT_PATH + 'app/post/controllers/post-detail-controller.js')) .service('PostEndpoint', require(ROOT_PATH + 'app/post/services/endpoints/post-endpoint.js')) .service('UserEndpoint', require(ROOT_PATH + 'app/common/services/endpoints/user-endpoint.js')) + .service('RoleEndpoint', require(ROOT_PATH + 'app/common/services/endpoints/role.js')) .service('ConfigEndpoint', require(ROOT_PATH + 'app/common/services/endpoints/config.js')) .service('CollectionEndpoint', require(ROOT_PATH + 'app/set/services/endpoints/collection.js')) .service('TagEndpoint', require(ROOT_PATH + 'app/common/services/endpoints/tag.js')) @@ -23,7 +24,6 @@ describe('Post detail controller', function () { .service('FormEndpoint', require(ROOT_PATH + 'app/common/services/endpoints/form.js')) .service('Maps', require(ROOT_PATH + 'app/common/services/maps.js')) .service('Notify', require(ROOT_PATH + 'app/common/services/notify.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')) .factory('Leaflet', function () { return window.L; }); From 991f576702561456cc8365fb0f67e1ab0102c1f2 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 16:06:05 -0500 Subject: [PATCH 067/135] fixing jscs issues --- app/post/controllers/post-detail-controller.js | 2 +- app/setting/directives/setting-roles-directive.js | 8 ++++---- .../common/services/endpoints/permission-endpoint-spec.js | 4 ++-- test/unit/common/services/endpoints/role-endpoint-spec.js | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/post/controllers/post-detail-controller.js b/app/post/controllers/post-detail-controller.js index fba9c42ac3..3501e8b132 100644 --- a/app/post/controllers/post-detail-controller.js +++ b/app/post/controllers/post-detail-controller.js @@ -52,7 +52,7 @@ function ( return 'post.publish_for_you'; } if (!_.isEmpty($scope.post.published_to)) { - return RoleEndpoint.get({id:$scope.post.published_to[0]}); + return RoleEndpoint.get({id: $scope.post.published_to[0]}); } return 'post.publish_for_everyone'; diff --git a/app/setting/directives/setting-roles-directive.js b/app/setting/directives/setting-roles-directive.js index a5610c1785..c365de01e9 100644 --- a/app/setting/directives/setting-roles-directive.js +++ b/app/setting/directives/setting-roles-directive.js @@ -12,18 +12,18 @@ function ( return { restrict: 'A', link: function ($scope, $element, $attrs) { - handleResponseErrors = function (errorResponse) { + var handleResponseErrors = function (errorResponse) { Notify.showApiErrors(errorResponse); }; - + $scope.refreshView = function () { RoleEndpoint.queryFresh().$promise.then(function (roles) { $scope.roles = roles; }); }; - + $scope.refreshView(); - + $scope.deleteRole = function (role) { $translate('notify.role.delete_question', { role: role.display_name diff --git a/test/unit/common/services/endpoints/permission-endpoint-spec.js b/test/unit/common/services/endpoints/permission-endpoint-spec.js index ded95c53dc..b813336c72 100644 --- a/test/unit/common/services/endpoints/permission-endpoint-spec.js +++ b/test/unit/common/services/endpoints/permission-endpoint-spec.js @@ -43,7 +43,7 @@ describe('PermissionEndpoint', function () { 'url': 'http://192.168.33.110/api/v3/permissions/1', 'description': null, 'name': 'test permission', - 'display_name': 'Test permission', + 'display_name': 'Test permission', 'created': '1970-01-01T00:00:00+00:00', 'permission': null, 'allowed_privileges': [ @@ -56,7 +56,7 @@ describe('PermissionEndpoint', function () { 'url': 'http://192.168.33.110/api/v3/permissions/2', 'description': 'test desc', 'name': 'test permission', - 'display_name': 'Test permission', + 'display_name': 'Test permission', 'created': '1970-01-01T00:00:00+00:00', 'allowed_privileges': [ 'read', diff --git a/test/unit/common/services/endpoints/role-endpoint-spec.js b/test/unit/common/services/endpoints/role-endpoint-spec.js index 64580a32a9..46acfe2e26 100644 --- a/test/unit/common/services/endpoints/role-endpoint-spec.js +++ b/test/unit/common/services/endpoints/role-endpoint-spec.js @@ -44,7 +44,7 @@ describe('RoleEndpoint', function () { 'description': null, 'name': 'test role', 'permissions': ['Manage Users', 'Manage Posts'], - 'display_name': 'Test role', + 'display_name': 'Test role', 'created': '1970-01-01T00:00:00+00:00', 'role': null, 'allowed_privileges': [ @@ -61,7 +61,7 @@ describe('RoleEndpoint', function () { 'description': 'test desc', 'name': 'test role', 'permissions': ['Manage Users', 'Manage Posts'], - 'display_name': 'Test role', + 'display_name': 'Test role', 'created': '1970-01-01T00:00:00+00:00', 'allowed_privileges': [ 'read', From 2993fdde584a2fd8f7797be0b8478c4dc39eed1f Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 17:52:46 -0500 Subject: [PATCH 068/135] changed user to use new role end point --- app/setting/controllers/setting-users-edit-controller.js | 4 +++- app/setting/directives/setting-roles-editor-directive.js | 2 +- server/www/templates/settings/users-edit.html | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/setting/controllers/setting-users-edit-controller.js b/app/setting/controllers/setting-users-edit-controller.js index 43fa51c9a9..a4cbdf3207 100644 --- a/app/setting/controllers/setting-users-edit-controller.js +++ b/app/setting/controllers/setting-users-edit-controller.js @@ -49,5 +49,7 @@ function ( }); }; - $scope.roles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.roles = roles; + }); }]; diff --git a/app/setting/directives/setting-roles-editor-directive.js b/app/setting/directives/setting-roles-editor-directive.js index 5542351817..dfe3713a12 100644 --- a/app/setting/directives/setting-roles-editor-directive.js +++ b/app/setting/directives/setting-roles-editor-directive.js @@ -35,7 +35,7 @@ function ( $scope.saveRole = function (role) { $scope.processing = true; - role.name = role.display_name; + role.name = role.name === '' ? role.display_name : role.name; RoleEndpoint.saveCache(role).$promise.then(function (result) { $translate('notify.role.save_success', {role: role.display_name}).then(function (message) { diff --git a/server/www/templates/settings/users-edit.html b/server/www/templates/settings/users-edit.html index 714ff18b32..b4fb2c0315 100644 --- a/server/www/templates/settings/users-edit.html +++ b/server/www/templates/settings/users-edit.html @@ -45,7 +45,7 @@

    {{title}}

    - +
    From f874f9de596813ee32430423302587d3a1ddebb5 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 18:01:45 -0500 Subject: [PATCH 069/135] fixed weird non redirect issue, added user create roles element --- app/post/directives/post-editor-directive.js | 1 + app/setting/controllers/setting-users-create-controller.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/post/directives/post-editor-directive.js b/app/post/directives/post-editor-directive.js index 6a00f2632a..3859dabe7e 100644 --- a/app/post/directives/post-editor-directive.js +++ b/app/post/directives/post-editor-directive.js @@ -275,6 +275,7 @@ function ( name: $scope.post.title }).then(function (message) { Notify.showNotificationSlider(message); + $location.path('/posts/' + response.id); }); } else { Notify.showSingleAlert('Saved!'); diff --git a/app/setting/controllers/setting-users-create-controller.js b/app/setting/controllers/setting-users-create-controller.js index bc8a488cee..6429132618 100644 --- a/app/setting/controllers/setting-users-create-controller.js +++ b/app/setting/controllers/setting-users-create-controller.js @@ -43,5 +43,7 @@ function ( }); }; - $scope.roles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.roles = roles; + }); }]; From dbfde18be8c66bc346c6e6b44ce9f5423ceb2bb5 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 18:19:58 -0500 Subject: [PATCH 070/135] updating more views --- app/post/directives/post-preview-directive.js | 4 +++- app/set/directives/collection-editor-directive.js | 5 ++++- app/set/directives/savedsearch-editor-directive.js | 5 ++++- .../controllers/setting-categories-create-controller.js | 4 +++- .../controllers/setting-categories-edit-controller.js | 4 +++- server/www/templates/posts/preview.html | 4 ++-- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/post/directives/post-preview-directive.js b/app/post/directives/post-preview-directive.js index b3c1871113..15e4ef6faa 100644 --- a/app/post/directives/post-preview-directive.js +++ b/app/post/directives/post-preview-directive.js @@ -66,7 +66,9 @@ function ( }, templateUrl: 'templates/posts/preview.html', link: function ($scope) { - $scope.availableRoles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.availableRoles = roles; + }); $scope.publishedFor = function () { if ($scope.post.status === 'draft') { diff --git a/app/set/directives/collection-editor-directive.js b/app/set/directives/collection-editor-directive.js index 007d022461..71c8dbb589 100644 --- a/app/set/directives/collection-editor-directive.js +++ b/app/set/directives/collection-editor-directive.js @@ -30,7 +30,10 @@ function ( link: function ($scope, $element, $attrs) { $scope.isAdmin = $rootScope.isAdmin; - $scope.roles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.roles = roles; + }); + $scope.views = PostViewHelper.views(); // Set default view for Collection to be Map diff --git a/app/set/directives/savedsearch-editor-directive.js b/app/set/directives/savedsearch-editor-directive.js index 8da7da4c2c..141360e9ea 100644 --- a/app/set/directives/savedsearch-editor-directive.js +++ b/app/set/directives/savedsearch-editor-directive.js @@ -36,7 +36,10 @@ function ( $scope.isAdmin = $rootScope.isAdmin; - $scope.roles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.roles = roles; + }); + $scope.views = PostViewHelper.views(); $scope.cpySavedSearch = _.clone($scope.savedSearch); diff --git a/app/setting/controllers/setting-categories-create-controller.js b/app/setting/controllers/setting-categories-create-controller.js index 6970c6bc59..cee399233f 100644 --- a/app/setting/controllers/setting-categories-create-controller.js +++ b/app/setting/controllers/setting-categories-create-controller.js @@ -23,7 +23,9 @@ function ( }); $scope.types = multiTranslate(['tag.types.category', 'tag.types.status']); - $scope.roles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.roles = roles; + }); $scope.tag = { type: 'category', icon: 'tag' }; $scope.processing = false; diff --git a/app/setting/controllers/setting-categories-edit-controller.js b/app/setting/controllers/setting-categories-edit-controller.js index 02e302600e..a047c04db5 100644 --- a/app/setting/controllers/setting-categories-edit-controller.js +++ b/app/setting/controllers/setting-categories-edit-controller.js @@ -27,7 +27,9 @@ function ( }); $scope.types = multiTranslate(['tag.types.category', 'tag.types.status']); - $scope.roles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.roles = roles; + }); $scope.tag = TagEndpoint.getFresh({id: $routeParams.id}); $scope.processing = false; diff --git a/server/www/templates/posts/preview.html b/server/www/templates/posts/preview.html index 0565d2bd00..8a9a3d5630 100644 --- a/server/www/templates/posts/preview.html +++ b/server/www/templates/posts/preview.html @@ -57,9 +57,9 @@

    From 3fcc7c233d308a4dcda08b9dbfda045662d2b647 Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 18:59:49 -0500 Subject: [PATCH 071/135] adding permission check for setting menus --- app/common/global/event-handlers.js | 20 +++++++++++++++++-- app/common/services/authentication.js | 3 ++- .../controllers/post-detail-controller.js | 4 +++- app/post/directives/post-editor-directive.js | 4 +++- server/www/index.html | 2 +- server/www/templates/partials/main-menu.html | 18 ++++++++--------- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/app/common/global/event-handlers.js b/app/common/global/event-handlers.js index e9db85f2bc..cb66c3a169 100644 --- a/app/common/global/event-handlers.js +++ b/app/common/global/event-handlers.js @@ -2,12 +2,16 @@ module.exports = [ '$rootScope', '$location', 'Authentication', + 'PermissionEndpoint', 'Session', + '_', function ( $rootScope, $location, Authentication, - Session + PermissionEndpoint, + Session, + _ ) { function loadSessionData() { $rootScope.currentUser = Session.getSessionData(); @@ -29,6 +33,18 @@ function ( } } + PermissionEndpoint.query().$promise.then(function (permissions) { + $rootScope.permissions = permissions.results; + }); + + $rootScope.hasManagePermission = function () { + return (($rootScope.currentUser || {}).permissions.length > 0); + }; + + $rootScope.hasPermission = function (permission) { + return _.contains($rootScope.permissions, permission); + }; + $rootScope.isAdmin = function () { return (($rootScope.currentUser || {}).role === 'admin'); }; @@ -44,7 +60,7 @@ function ( $rootScope.switchRtl = function () { $rootScope.rtlEnabled = !$rootScope.rtlEnabled; - }; + }; $rootScope.$on('event:authentication:login:succeeded', function () { doLogin(Session.getSessionDataEntry('loginPath') || '/'); diff --git a/app/common/services/authentication.js b/app/common/services/authentication.js index 7b9339f12b..92b9a6a08d 100644 --- a/app/common/services/authentication.js +++ b/app/common/services/authentication.js @@ -24,7 +24,8 @@ function ( userId: userData.id, realname: userData.realname, email: userData.email, - role: userData.role + role: userData.role, + permissions: userData.permissions }); loginStatus = true; diff --git a/app/post/controllers/post-detail-controller.js b/app/post/controllers/post-detail-controller.js index 3501e8b132..509d8ea850 100644 --- a/app/post/controllers/post-detail-controller.js +++ b/app/post/controllers/post-detail-controller.js @@ -46,7 +46,9 @@ function ( $scope.post = post; $scope.mapDataLoaded = false; - $scope.availableRoles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.availableRoles = roles; + }); $scope.publishedFor = function () { if ($scope.post.status === 'draft') { return 'post.publish_for_you'; diff --git a/app/post/directives/post-editor-directive.js b/app/post/directives/post-editor-directive.js index 3859dabe7e..c266936b10 100644 --- a/app/post/directives/post-editor-directive.js +++ b/app/post/directives/post-editor-directive.js @@ -32,7 +32,9 @@ function ( ) { $scope.categories = TagEndpoint.query(); - $scope.availableRoles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.availableRoles = roles; + }); $scope.everyone = $filter('translate')('post.modify.everyone'); $scope.isEdit = !!$scope.post.id; $scope.validationErrors = []; diff --git a/server/www/index.html b/server/www/index.html index c8ee9f4912..c5c1e532f1 100644 --- a/server/www/index.html +++ b/server/www/index.html @@ -103,7 +103,7 @@

  • nav.activity
  • app.documentation
  • app.report_a_bug
  • -
  • nav.settings
  • +
  • nav.settings
  • diff --git a/server/www/templates/partials/main-menu.html b/server/www/templates/partials/main-menu.html index 66dae44f54..eab571161d 100644 --- a/server/www/templates/partials/main-menu.html +++ b/server/www/templates/partials/main-menu.html @@ -8,18 +8,18 @@
  • nav.home
  • nav.activity
  • -
  • +
  • nav.settings
  • From 8cf39f098644ced23970f5d28497b3edd5d0ca1a Mon Sep 17 00:00:00 2001 From: will Date: Thu, 11 Feb 2016 19:54:26 -0500 Subject: [PATCH 072/135] changed isAdmin() to hasPermission() --- server/www/templates/posts/choose-form.html | 2 +- server/www/templates/posts/post-view-filters.html | 2 +- server/www/templates/sets/collection-editor.html | 2 +- server/www/templates/sets/savedsearch-editor.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/www/templates/posts/choose-form.html b/server/www/templates/posts/choose-form.html index 572466bb95..3f904fa25d 100644 --- a/server/www/templates/posts/choose-form.html +++ b/server/www/templates/posts/choose-form.html @@ -2,7 +2,7 @@
    diff --git a/server/www/templates/posts/post-view-filters.html b/server/www/templates/posts/post-view-filters.html index 5ebb4f2a57..6fb768915b 100644 --- a/server/www/templates/posts/post-view-filters.html +++ b/server/www/templates/posts/post-view-filters.html @@ -99,7 +99,7 @@

    Search & Filter

    -
  • +
  • diff --git a/server/www/templates/sets/collection-editor.html b/server/www/templates/sets/collection-editor.html index d607b30d01..9c2fc470ee 100644 --- a/server/www/templates/sets/collection-editor.html +++ b/server/www/templates/sets/collection-editor.html @@ -20,7 +20,7 @@
  • -
    +
    -
    +
    -
    @@ -118,9 +118,9 @@

    attribute="form_attributes[key]" >

    -

    post.location

    diff --git a/server/www/templates/settings/users.html b/server/www/templates/settings/users.html index 55a3d76746..7d7b46e2e3 100644 --- a/server/www/templates/settings/users.html +++ b/server/www/templates/settings/users.html @@ -68,12 +68,12 @@

    user.search_and_filter

    ng-click="deleteUsers()"> nav.delete - +
    From bbe8d57c230813c4e475b361c35027edcd61f549 Mon Sep 17 00:00:00 2001 From: will Date: Sat, 13 Feb 2016 12:30:18 -0500 Subject: [PATCH 076/135] update user permissions return for userdata --- app/common/global/event-handlers.js | 5 +++-- app/common/services/authentication.js | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/common/global/event-handlers.js b/app/common/global/event-handlers.js index d20a925009..a7353f13ad 100644 --- a/app/common/global/event-handlers.js +++ b/app/common/global/event-handlers.js @@ -38,11 +38,12 @@ function ( }); $rootScope.hasManagePermission = function () { - return (($rootScope.currentUser || {}).permissions.length > 0); + return $rootScope.isAdmin ? true : (($rootScope.currentUser || {}).permissions.length > 0); }; $rootScope.hasPermission = function (permission) { - return _.contains($rootScope.permissions, permission); + + return $rootScope.isAdmin ? true : _.contains($rootScope.permissions, permission); }; $rootScope.isAdmin = function () { diff --git a/app/common/services/authentication.js b/app/common/services/authentication.js index 92b9a6a08d..9c8306bdd5 100644 --- a/app/common/services/authentication.js +++ b/app/common/services/authentication.js @@ -63,11 +63,14 @@ function ( $http.get(Util.apiUrl('/users/me')).then( function (userDataResponse) { - setToLoginState(userDataResponse.data); + RoleEndpoint.query({name: userDataResponse.data.role}).$promise.then( function (role) { + userDataResponse.data.permissions = role.results[0].permissions; + setToLoginState(userDataResponse.data); - $rootScope.$broadcast('event:authentication:login:succeeded'); - deferred.resolve(); + $rootScope.$broadcast('event:authentication:login:succeeded'); + deferred.resolve(); + }); }, handleRequestError); }; From 43c8ed34d18c32fd094a6b1f5b15c9b13ed59edf Mon Sep 17 00:00:00 2001 From: will Date: Sat, 13 Feb 2016 12:41:54 -0500 Subject: [PATCH 077/135] update session check data --- app/common/global/event-handlers.js | 10 ++-------- app/common/services/authentication.js | 4 +++- app/common/services/session.js | 1 + 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/common/global/event-handlers.js b/app/common/global/event-handlers.js index a7353f13ad..a5eca90f70 100644 --- a/app/common/global/event-handlers.js +++ b/app/common/global/event-handlers.js @@ -2,14 +2,12 @@ module.exports = [ '$rootScope', '$location', 'Authentication', - 'PermissionEndpoint', 'Session', '_', function ( $rootScope, $location, Authentication, - PermissionEndpoint, Session, _ ) { @@ -33,17 +31,13 @@ function ( } } - PermissionEndpoint.query().$promise.then(function (permissions) { - $rootScope.permissions = permissions.results; - }); - $rootScope.hasManagePermission = function () { - return $rootScope.isAdmin ? true : (($rootScope.currentUser || {}).permissions.length > 0); + return $rootScope.isAdmin() ? true : (($rootScope.currentUser || {}).permissions.length > 0); }; $rootScope.hasPermission = function (permission) { - return $rootScope.isAdmin ? true : _.contains($rootScope.permissions, permission); + return $rootScope.isAdmin() ? true : _.contains($rootScope.currentUser.permissions, permission); }; $rootScope.isAdmin = function () { diff --git a/app/common/services/authentication.js b/app/common/services/authentication.js index 9c8306bdd5..79c6314ae6 100644 --- a/app/common/services/authentication.js +++ b/app/common/services/authentication.js @@ -1,5 +1,6 @@ module.exports = [ '$rootScope', + 'RoleEndpoint', '$http', '$q', 'Util', @@ -7,6 +8,7 @@ module.exports = [ 'Session', function ( $rootScope, + RoleEndpoint, $http, $q, Util, @@ -64,7 +66,7 @@ function ( function (userDataResponse) { RoleEndpoint.query({name: userDataResponse.data.role}).$promise.then( function (role) { - userDataResponse.data.permissions = role.results[0].permissions; + userDataResponse.data.permissions = role[0].permissions; setToLoginState(userDataResponse.data); $rootScope.$broadcast('event:authentication:login:succeeded'); diff --git a/app/common/services/session.js b/app/common/services/session.js index 5252f3728b..9c32d73525 100644 --- a/app/common/services/session.js +++ b/app/common/services/session.js @@ -10,6 +10,7 @@ function ( email: undefined, accessToken: undefined, role: undefined, + permissions: undefined, loginPath: undefined }; From b2462bda5a297b3d7298269db257bf2b34d255ce Mon Sep 17 00:00:00 2001 From: will Date: Sat, 13 Feb 2016 14:36:23 -0500 Subject: [PATCH 078/135] role selector working, though the logic is clean, the structure should be addressed in future --- app/common/common-module.js | 1 + app/common/directives/role-selector.js | 43 +++++++++++++++--- .../controllers/post-detail-controller.js | 4 +- server/www/templates/posts/detail.html | 29 ++---------- .../role-selector/role-selector.html | 45 ++++++++++++++----- 5 files changed, 77 insertions(+), 45 deletions(-) diff --git a/app/common/common-module.js b/app/common/common-module.js index 5000aa74bd..4aa87a1a7d 100644 --- a/app/common/common-module.js +++ b/app/common/common-module.js @@ -43,6 +43,7 @@ angular.module('ushahidi.common', [ .controller('notifier', require('./controllers/notifier.js')) .directive('collectionSelector', require('./directives/collection-selector.js')) +.directive('roleSelector', require('./directives/role-selector.js')) .directive('iconPicker', require('./directives/iconpicker.js')) .directive('firstTimeConfig', require('./directives/first-time-config.js')) diff --git a/app/common/directives/role-selector.js b/app/common/directives/role-selector.js index 7459d3eb56..2d85289bbf 100644 --- a/app/common/directives/role-selector.js +++ b/app/common/directives/role-selector.js @@ -22,14 +22,45 @@ function ( RoleEndpoint, _ ) { - $scope.roles = RoleEndpoint.query(); + $scope.status = null; - $scope.userRoleSet = function (role) { - return _.contains($scope.currentRoles, String(role.id)); + // Check if draft, published to specific roles or for everyone + $scope.refreshStatus = function () { + if ($scope.post.status === 'draft') { + $scope.status = 'draft'; + } else if ($scope.post.status === 'published') { + // If post is puslihed but published_to is empty + // the post is pusblished for everyone, indicated by '' + if (!$scope.post.published_to) { + $scope.status = ''; + } else{ + $scope.status = null; + } + } + }; + + $scope.refreshStatus(); + + RoleEndpoint.query().$promise.then(function (roles) { + $scope.roles = roles; + }); + + $scope.checkIfAllSelected = function () { + return ($scope.roles.length === $scope.post.published_to.length); }; $scope.toggleRole = function (role) { - $scope.toggleRoleFunc(role); + if ( role === 'draft' || role === '') { + $scope.post.published_to = null; + } else if ($scope.checkIfAllSelected()) { + // All check boxes selected, therefore publish to everyone + $scope.post.published_to = null; + } + + $scope.post.status = role === 'draft' ? role : 'published'; + + $scope.refreshStatus(); + //$scope.toggleRoleFunc({role: role}); }; }]; @@ -37,8 +68,8 @@ function ( restrict: 'E', templateUrl: 'templates/role-selector/role-selector.html', scope: { - currentRoles: '=', - toggleRoleFunc: '=' + post: '=', + toggleRoleFunc: '&' }, controller: controller }; diff --git a/app/post/controllers/post-detail-controller.js b/app/post/controllers/post-detail-controller.js index 190c21f7a0..fd679cbb06 100644 --- a/app/post/controllers/post-detail-controller.js +++ b/app/post/controllers/post-detail-controller.js @@ -325,7 +325,7 @@ function ( }); }; - $scope.publishPostTo = function () { + $scope.publishPostTo = function (role) { // first check if stages required have been marked complete var requiredStages = _.where($scope.stages, {required: true}), errors = []; @@ -351,7 +351,7 @@ function ( } } else { $scope.post.status = 'published'; - $scope.post.published_to = []; + $scope.post.published_to = null; } PostEndpoint.update($scope.post). diff --git a/server/www/templates/posts/detail.html b/server/www/templates/posts/detail.html index e6db33d394..ac12711e9f 100644 --- a/server/www/templates/posts/detail.html +++ b/server/www/templates/posts/detail.html @@ -12,32 +12,9 @@

    -
    - -
    - +

    diff --git a/server/www/templates/role-selector/role-selector.html b/server/www/templates/role-selector/role-selector.html index 384fd7c3c5..f1401083f6 100644 --- a/server/www/templates/role-selector/role-selector.html +++ b/server/www/templates/role-selector/role-selector.html @@ -1,15 +1,38 @@ -
    - - global_filter.roles.roles - +
    + post.who_can_see_this
    -
    - -
    - +
    -
  • nav.posts_and_entities
  • -
  • nav.categories
  • -
  • nav.users
  • -
  • nav.roles
  • +
  • nav.posts_and_entities
  • +
  • nav.categories
  • +
  • nav.users
  • +
  • nav.roles
  • diff --git a/server/www/templates/posts/choose-form.html b/server/www/templates/posts/choose-form.html index 15876e6bd5..ab6954d7b4 100644 --- a/server/www/templates/posts/choose-form.html +++ b/server/www/templates/posts/choose-form.html @@ -3,7 +3,7 @@

    post.modify.add_a_post

    post.modify.edit_post

    - Edit Post Types + Edit Post Types
    diff --git a/server/www/templates/posts/post-view-filters.html b/server/www/templates/posts/post-view-filters.html index 6fb768915b..915c5d422b 100644 --- a/server/www/templates/posts/post-view-filters.html +++ b/server/www/templates/posts/post-view-filters.html @@ -99,7 +99,7 @@

    Search & Filter

    -
  • +
  • diff --git a/server/www/templates/sets/collection-editor.html b/server/www/templates/sets/collection-editor.html index 9c2fc470ee..fee70b823f 100644 --- a/server/www/templates/sets/collection-editor.html +++ b/server/www/templates/sets/collection-editor.html @@ -20,7 +20,7 @@
  • -
    +
    -
    +
    diff --git a/server/www/templates/partials/main-menu.html b/server/www/templates/partials/main-menu.html index 8e03c531c6..c4bf43a231 100644 --- a/server/www/templates/partials/main-menu.html +++ b/server/www/templates/partials/main-menu.html @@ -8,7 +8,7 @@
  • nav.home
  • nav.activity
  • -
  • +
  • nav.settings
    • nav.general
    • From 300da92403b21c3314a1395cf48db75cd5a0f85d Mon Sep 17 00:00:00 2001 From: will Date: Sun, 14 Feb 2016 15:53:00 -0500 Subject: [PATCH 097/135] fixed tests --- app/mock-backend-config.js | 1 + .../controllers/post-detail-controller.js | 3 +- app/post/directives/post-editor-directive.js | 3 +- app/post/directives/post-preview-directive.js | 3 +- .../controllers/setting-users-controller.js | 4 +- mocked_backend/api/v3/roles.json | 50 ++++++++----------- mocked_backend/api/v3/users.json | 40 +++++++-------- mocked_backend/api/v3/users/me.json | 2 +- server/www/templates/settings/users.html | 2 +- test/e2e/post/views/post-list-e2e-spec.js | 6 +-- test/e2e/settings/users-e2e-spec.js | 6 +-- 11 files changed, 58 insertions(+), 62 deletions(-) diff --git a/app/mock-backend-config.js b/app/mock-backend-config.js index 1397651275..4bb23ac644 100644 --- a/app/mock-backend-config.js +++ b/app/mock-backend-config.js @@ -13,6 +13,7 @@ angular.module('e2e-mocks', ['ngMockE2E']) 'config/map': require('../mocked_backend/api/v3/config/map.json'), 'sets': require('../mocked_backend/api/v3/sets.json'), 'collections': require('../mocked_backend/api/v3/collections.json'), + 'roles': require('../mocked_backend/api/v3/roles.json'), 'users': require('../mocked_backend/api/v3/users.json'), 'users/me': require('../mocked_backend/api/v3/users/me.json'), 'config/site': require('../mocked_backend/api/v3/config/site.json') diff --git a/app/post/controllers/post-detail-controller.js b/app/post/controllers/post-detail-controller.js index cde02680ad..a59ff301d1 100644 --- a/app/post/controllers/post-detail-controller.js +++ b/app/post/controllers/post-detail-controller.js @@ -264,7 +264,8 @@ function ( $promise .then(function () { var message = post.status === 'draft' ? 'notify.post.set_draft' : 'notify.post.publish_success'; - $translate(message) + var role = message == 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(", ")); + $translate(message, {role: role}) .then(function (message) { Notify.showNotificationSlider(message); }); diff --git a/app/post/directives/post-editor-directive.js b/app/post/directives/post-editor-directive.js index a0e926b8e4..c12310bcf6 100644 --- a/app/post/directives/post-editor-directive.js +++ b/app/post/directives/post-editor-directive.js @@ -179,7 +179,8 @@ function ( $promise .then(function (post) { var message = post.status === 'draft' ? 'notify.post.set_draft' : 'notify.post.publish_success'; - $translate(message) + var role = message == 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(", ")); + $translate(message, {role: role}) .then(function (message) { Notify.showNotificationSlider(message); }); diff --git a/app/post/directives/post-preview-directive.js b/app/post/directives/post-preview-directive.js index 4f8b255e43..0bb5863f55 100644 --- a/app/post/directives/post-preview-directive.js +++ b/app/post/directives/post-preview-directive.js @@ -122,7 +122,8 @@ function ( $promise .then(function (post) { var message = post.status === 'draft' ? 'notify.post.set_draft' : 'notify.post.publish_success'; - $translate(message) + var role = message == 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(", ")); + $translate(message, {role: role}) .then(function (message) { Notify.showNotificationSlider(message); }); diff --git a/app/setting/controllers/setting-users-controller.js b/app/setting/controllers/setting-users-controller.js index b3d542ed9f..92feccaa7c 100644 --- a/app/setting/controllers/setting-users-controller.js +++ b/app/setting/controllers/setting-users-controller.js @@ -28,7 +28,9 @@ function ( $scope.$emit('setPageTitle', title); }); - $scope.roles = RoleEndpoint.query(); + RoleEndpoint.query().$promise.then(function (roles) { + $scope.roles = roles; + }); $scope.filter = { role: '', diff --git a/mocked_backend/api/v3/roles.json b/mocked_backend/api/v3/roles.json index db3226934c..de3e46daa6 100644 --- a/mocked_backend/api/v3/roles.json +++ b/mocked_backend/api/v3/roles.json @@ -1,13 +1,14 @@ { - "count": 5, + "count": 4, "results": [ { "id": 1, "url": "http://api.ushahidi.dev/api/v3/roles/1", - "role": "admin", + "name": "Admin", + "display_name": "Admin", "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "permissions": [], "allowed_methods": [ "get", "post", @@ -18,10 +19,11 @@ { "id": 2, "url": "http://api.ushahidi.dev/api/v3/roles/2", - "role": "member", + "name": "Member", + "display_name": "Member", "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "permissions": [], "allowed_methods": [ "get", "post", @@ -33,44 +35,36 @@ }, { "id": 3, - "url": "http://api.ushahidi.dev/api/v3/roles/3", - "role": "guest", + "url": "http://api.ushahidi.dev/api/v3/roles/2", + "name": "Importer", + "display_name": "Importer", "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "permissions": ["Bulk Data Import"], "allowed_methods": [ "get", "post", "put", - "delete" + "delete", + "update", + "change_status" ] }, { "id": 4, - "url": "http://api.ushahidi.dev/api/v3/roles/4", - "role": "custom role 1", - "created": "1970-01-01T00:00:00+00:00", - "updated": null, - "role": "admin", - "allowed_methods": [ - "get", - "post", - "put", - "delete" - ] - }, - { - "id": 5, - "url": "http://api.ushahidi.dev/api/v3/roles/5", - "role": "custom role 2", + "url": "http://api.ushahidi.dev/api/v3/roles/2", + "name": "Manager", + "display_name": "Manager", "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "permissions": ["Manage Settings", "Manage Users", "Manage Posts"], "allowed_methods": [ "get", "post", "put", - "delete" + "delete", + "update", + "change_status" ] } ], @@ -81,5 +75,5 @@ "curr": "http://api.ushahidi.dev/api/v3/roles?access_token=defaulttoken&orderby=created&order=desc&limit=100&offset=0", "next": "http://api.ushahidi.dev/api/v3/roles?access_token=defaulttoken&orderby=created&order=desc&limit=100&offset=100", "prev": "http://api.ushahidi.dev/api/v3/roles?access_token=defaulttoken&orderby=created&order=desc&limit=100&offset=0", - "total_count": 5 + "total_count": 4 } diff --git a/mocked_backend/api/v3/users.json b/mocked_backend/api/v3/users.json index 6c71e35a4f..d1c8a5e172 100644 --- a/mocked_backend/api/v3/users.json +++ b/mocked_backend/api/v3/users.json @@ -12,7 +12,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "role": "User", "allowed_methods": [ "get", "post", @@ -31,7 +31,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -52,7 +52,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "role": "User", "allowed_methods": [ "get", "post", @@ -71,7 +71,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -90,7 +90,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -110,7 +110,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "role": "User", "allowed_methods": [ "get", "post", @@ -129,7 +129,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -147,7 +147,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "role": "User", "allowed_methods": [ "get", "post", @@ -166,7 +166,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -185,7 +185,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -204,7 +204,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "role": "User", "allowed_methods": [ "get", "post", @@ -223,7 +223,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -241,7 +241,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "role": "User", "allowed_methods": [ "get", "post", @@ -260,7 +260,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -279,7 +279,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -298,7 +298,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "role": "User", "allowed_methods": [ "get", "post", @@ -317,7 +317,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -335,7 +335,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "user", + "role": "User", "allowed_methods": [ "get", "post", @@ -354,7 +354,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", @@ -373,7 +373,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", diff --git a/mocked_backend/api/v3/users/me.json b/mocked_backend/api/v3/users/me.json index ff39f91c73..b753c87c4d 100644 --- a/mocked_backend/api/v3/users/me.json +++ b/mocked_backend/api/v3/users/me.json @@ -9,7 +9,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": "2014-12-13T19:17:57+00:00", - "role": "admin", + "role": "Admin", "allowed_methods": [ "get", "post", diff --git a/server/www/templates/settings/users.html b/server/www/templates/settings/users.html index 9ab9e65ff5..576332fab9 100644 --- a/server/www/templates/settings/users.html +++ b/server/www/templates/settings/users.html @@ -90,7 +90,7 @@

      user.search_and_filter

  • {{user.realname}}

    -

    {{ getRole(user.role) }}

    +

    {{ user.role }}

    diff --git a/test/e2e/post/views/post-list-e2e-spec.js b/test/e2e/post/views/post-list-e2e-spec.js index 1ee790d4b2..729ffc0d4e 100644 --- a/test/e2e/post/views/post-list-e2e-spec.js +++ b/test/e2e/post/views/post-list-e2e-spec.js @@ -10,7 +10,7 @@ describe('post detail interaction', function () { postCollectionsButtonSelector = '.actions-content .dropdown-trigger.init.dropdown-toggle', postCollectionsMenuSelector = '.actions-content .dropdown-menu.init', collectionItem = '.form-field.checkbox input', - visibilityButtonsSelector = '.step select', + visibilityButtonsSelector = '.step legend', confirmationMessageSelector = '.confirmation-message-wrapper p'; describe('as a logged in admin user', function () { @@ -37,13 +37,13 @@ describe('post detail interaction', function () { describe('when clicking a visibility option', function () { beforeEach(function () { - var optionElement = visibilitySelect.element(by.cssContainingText('option', 'Member')); + var optionElement = element.all(by.css('.step .radio input')).get(1); optionElement.click(); }); it('should set the visibility of the post and display a confirmation', function () { var confirmMessage = element(by.css(confirmationMessageSelector)); - expect(confirmMessage.getInnerHtml()).toEqual('Post has been published for Member'); + expect(confirmMessage.getInnerHtml()).toEqual('Post has been published for everyone'); }); }); }); diff --git a/test/e2e/settings/users-e2e-spec.js b/test/e2e/settings/users-e2e-spec.js index dd0cfb1a08..5369ea1ced 100644 --- a/test/e2e/settings/users-e2e-spec.js +++ b/test/e2e/settings/users-e2e-spec.js @@ -133,9 +133,6 @@ describe('users management', function () { _.range(3, 6).forEach(function (i) { element(by.css('#user-' + i + ' input[type="checkbox"]')).click(); }); - // element.all(by.css('tr.user input[type="checkbox"]')).then(function(userCheckBoxes){ - // - // }); element(by.css('#user-1 input[type="checkbox"]')).click(); }); @@ -159,8 +156,7 @@ describe('users management', function () { browser.sleep(500); }); it('shows an alert which asks if you really want to change the roles', function () { - expect(element(by.css('#confirm-modal-text')).getText()).toEqual('Are you sure you want to change the role of 4 users to Member?'); - element(by.css('button#confirm-modal-ok')).click(); + expect(element(by.css('#confirm-modal-text')).getText()).toEqual('Are you sure you want to change the role of 2 users to Member?'); }); }); From 6192e6ba6964500e40edf3e17e2f4cc1db36042c Mon Sep 17 00:00:00 2001 From: will Date: Sun, 14 Feb 2016 16:13:55 -0500 Subject: [PATCH 098/135] weirdness in local vs travis --- test/e2e/settings/users-e2e-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/settings/users-e2e-spec.js b/test/e2e/settings/users-e2e-spec.js index 5369ea1ced..2a920f7ba1 100644 --- a/test/e2e/settings/users-e2e-spec.js +++ b/test/e2e/settings/users-e2e-spec.js @@ -156,7 +156,7 @@ describe('users management', function () { browser.sleep(500); }); it('shows an alert which asks if you really want to change the roles', function () { - expect(element(by.css('#confirm-modal-text')).getText()).toEqual('Are you sure you want to change the role of 2 users to Member?'); + expect(element(by.css('#confirm-modal-text')).getText()).toEqual('Are you sure you want to change the role of 4 users to Member?'); }); }); From cf6c3c18435d9210e3398f2f88b4e65d4cba801c Mon Sep 17 00:00:00 2001 From: will Date: Sun, 14 Feb 2016 16:44:04 -0500 Subject: [PATCH 099/135] linting --- app/common/global/event-handlers.js | 2 +- app/post/controllers/post-detail-controller.js | 2 +- app/post/directives/post-editor-directive.js | 2 +- app/post/directives/post-preview-directive.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/common/global/event-handlers.js b/app/common/global/event-handlers.js index 562364063b..772732ad08 100644 --- a/app/common/global/event-handlers.js +++ b/app/common/global/event-handlers.js @@ -36,7 +36,7 @@ function ( }; $rootScope.hasManageSettingsPermission = function () { - return $rootScope.isAdmin() ? true : (_.intersection(($rootScope.currentUser || {}).permissions, ["Manage Users", "Manage Settings", "Bulk Data Import"]).length > 0); + return $rootScope.isAdmin() ? true : (_.intersection(($rootScope.currentUser || {}).permissions, ['Manage Users', 'Manage Settings', 'Bulk Data Import']).length > 0); }; $rootScope.hasPermission = function (permission) { diff --git a/app/post/controllers/post-detail-controller.js b/app/post/controllers/post-detail-controller.js index a59ff301d1..4169cca60e 100644 --- a/app/post/controllers/post-detail-controller.js +++ b/app/post/controllers/post-detail-controller.js @@ -264,7 +264,7 @@ function ( $promise .then(function () { var message = post.status === 'draft' ? 'notify.post.set_draft' : 'notify.post.publish_success'; - var role = message == 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(", ")); + var role = message === 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(', ')); $translate(message, {role: role}) .then(function (message) { Notify.showNotificationSlider(message); diff --git a/app/post/directives/post-editor-directive.js b/app/post/directives/post-editor-directive.js index c12310bcf6..3b5a8076cb 100644 --- a/app/post/directives/post-editor-directive.js +++ b/app/post/directives/post-editor-directive.js @@ -179,7 +179,7 @@ function ( $promise .then(function (post) { var message = post.status === 'draft' ? 'notify.post.set_draft' : 'notify.post.publish_success'; - var role = message == 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(", ")); + var role = message === 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(', ')); $translate(message, {role: role}) .then(function (message) { Notify.showNotificationSlider(message); diff --git a/app/post/directives/post-preview-directive.js b/app/post/directives/post-preview-directive.js index 0bb5863f55..4f397d54bd 100644 --- a/app/post/directives/post-preview-directive.js +++ b/app/post/directives/post-preview-directive.js @@ -122,7 +122,7 @@ function ( $promise .then(function (post) { var message = post.status === 'draft' ? 'notify.post.set_draft' : 'notify.post.publish_success'; - var role = message == 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(", ")); + var role = message === 'draft' ? 'draft' : (_.isEmpty(post.published_to) ? 'everyone' : post.published_to.join(', ')); $translate(message, {role: role}) .then(function (message) { Notify.showNotificationSlider(message); From b39e558de4eb1807ec95b545023c77bd8cba27dd Mon Sep 17 00:00:00 2001 From: will Date: Mon, 15 Feb 2016 17:53:11 -0500 Subject: [PATCH 100/135] removed role-helper from merged tests --- .../controllers/activity-controller-spec.js | 3 +- .../password-reset-confirm-controller-spec.js | 3 +- .../password-reset-controller-spec.js | 3 +- test/unit/mock/mock-modules.js | 2 + test/unit/mock/services/permission.js | 55 +++++++++++++++++++ test/unit/mock/services/role.js | 55 +++++++++++++++++++ .../post-detail-controller-spec.js | 10 ---- .../collections-controller-spec.js | 3 +- .../savedsearch-controller-spec.js | 3 +- .../setting-categories-controller-spec.js | 3 +- ...tting-categories-create-controller-spec.js | 1 - ...setting-categories-edit-controller-spec.js | 1 - .../setting-roles-controller-spec.js | 4 -- .../setting-users-controller-spec.js | 3 +- .../setting-users-create-controller-spec.js | 3 +- .../setting-users-edit-controller-spec.js | 3 +- .../setting-views-controller-spec.js | 3 +- .../notification-controller-spec.js | 3 +- 18 files changed, 123 insertions(+), 38 deletions(-) create mode 100644 test/unit/mock/services/permission.js create mode 100644 test/unit/mock/services/role.js diff --git a/test/unit/activity/controllers/activity-controller-spec.js b/test/unit/activity/controllers/activity-controller-spec.js index cfaa1ce8da..8bdb24e05e 100644 --- a/test/unit/activity/controllers/activity-controller-spec.js +++ b/test/unit/activity/controllers/activity-controller-spec.js @@ -15,8 +15,7 @@ describe('activity activity controller', function () { 'ushahidi.mock' ]); - testApp.controller('activityController', require(ROOT_PATH + 'app/activity/controllers/activity-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('activityController', require(ROOT_PATH + 'app/activity/controllers/activity-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/common/controllers/password-reset-confirm-controller-spec.js b/test/unit/common/controllers/password-reset-confirm-controller-spec.js index 38efc8a414..63fd963296 100644 --- a/test/unit/common/controllers/password-reset-confirm-controller-spec.js +++ b/test/unit/common/controllers/password-reset-confirm-controller-spec.js @@ -15,8 +15,7 @@ describe('common password reset confirm controller', function () { 'ushahidi.mock' ]); - testApp.controller('passwordResetConfirmController', require(ROOT_PATH + 'app/common/controllers/password-reset-confirm-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('passwordResetConfirmController', require(ROOT_PATH + 'app/common/controllers/password-reset-confirm-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/common/controllers/password-reset-controller-spec.js b/test/unit/common/controllers/password-reset-controller-spec.js index 13d062d65d..998029ed4b 100644 --- a/test/unit/common/controllers/password-reset-controller-spec.js +++ b/test/unit/common/controllers/password-reset-controller-spec.js @@ -15,8 +15,7 @@ describe('common password reset controller', function () { 'ushahidi.mock' ]); - testApp.controller('passwordResetController', require(ROOT_PATH + 'app/common/controllers/password-reset-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('passwordResetController', require(ROOT_PATH + 'app/common/controllers/password-reset-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/mock/mock-modules.js b/test/unit/mock/mock-modules.js index 9473ba1c42..99be86116a 100644 --- a/test/unit/mock/mock-modules.js +++ b/test/unit/mock/mock-modules.js @@ -23,6 +23,8 @@ angular.module('ushahidi.mock', []) .service('CollectionEndpoint', require('./services/collection.js')) .service('ContactEndpoint', require('./services/contact.js')) .service('ConfigEndpoint', require('./services/config.js')) +.service('RoleEndpoint', require('./services/role.js')) +.service('PermissionEndpoint', require('./services/permission.js')) .service('DataProviderEndpoint', require('./services/data-provider.js')) .service('Authentication', require('./services/authentication.js')) diff --git a/test/unit/mock/services/permission.js b/test/unit/mock/services/permission.js new file mode 100644 index 0000000000..24d252d0c5 --- /dev/null +++ b/test/unit/mock/services/permission.js @@ -0,0 +1,55 @@ +module.exports = [function () { + return { + query: function () { + return {$promise: { + then: function (successCallback, failCallback) { + successCallback([{ + name: 'test permission', + id: 1 + }]); + } + }}; + }, + stats: function () { + return {$promise: { + then: function (successCallback, failCallback) { + successCallback( + {'totals': [{ + values: [1,2,3,4,5] + }]} + ); + } + }}; + }, + get: function () { + return {$promise: { + then: function (successCallback, failCallback) { + successCallback({ + name: 'test permission', + id: 1 + }); + } + }}; + }, + getFresh: function () { + return { + name: 'test permission', + id: 1 + }; + }, + delete: function () { + return {$promise: { + then: function (successCallback) { + successCallback(); + } + }}; + }, + saveCache: function (permission) { + return {$promise: { + then: function (successCallback, failCallback) { + permission.id === 'pass' ? successCallback({id: 1}) : failCallback('error'); + } + }}; + } + }; +}]; diff --git a/test/unit/mock/services/role.js b/test/unit/mock/services/role.js new file mode 100644 index 0000000000..5b4db78df9 --- /dev/null +++ b/test/unit/mock/services/role.js @@ -0,0 +1,55 @@ +module.exports = [function () { + return { + query: function () { + return {$promise: { + then: function (successCallback, failCallback) { + successCallback([{ + name: 'test role', + id: 1 + }]); + } + }}; + }, + stats: function () { + return {$promise: { + then: function (successCallback, failCallback) { + successCallback( + {'totals': [{ + values: [1,2,3,4,5] + }]} + ); + } + }}; + }, + get: function () { + return {$promise: { + then: function (successCallback, failCallback) { + successCallback({ + name: 'test role', + id: 1 + }); + } + }}; + }, + getFresh: function () { + return { + name: 'test role', + id: 1 + }; + }, + delete: function () { + return {$promise: { + then: function (successCallback) { + successCallback(); + } + }}; + }, + saveCache: function (role) { + return {$promise: { + then: function (successCallback, failCallback) { + role.id === 'pass' ? successCallback({id: 1}) : failCallback('error'); + } + }}; + } + }; +}]; diff --git a/test/unit/post/controllers/post-detail-controller-spec.js b/test/unit/post/controllers/post-detail-controller-spec.js index 210bd4e6c3..d6d095fa4d 100644 --- a/test/unit/post/controllers/post-detail-controller-spec.js +++ b/test/unit/post/controllers/post-detail-controller-spec.js @@ -129,16 +129,6 @@ describe('Post detail controller', function () { expect($scope.publishedFor()).toEqual('post.publish_for_you'); }); - it('should publish post for everyone', function () { - expect($scope.postIsPublishedTo()).toEqual('draft'); - - spyOn(PostEndpoint, 'update').and.callThrough(); - $scope.publishRole = ''; - $scope.publishPostTo(); - - expect($scope.postIsPublishedTo()).toEqual(''); - }); - it('should show type as false for point and geometry but true for other', function () { expect($scope.showType('point')).toEqual(false); expect($scope.showType('geometry')).toEqual(false); diff --git a/test/unit/set/controllers/collections-controller-spec.js b/test/unit/set/controllers/collections-controller-spec.js index 54bfa7a238..d753a49dc4 100644 --- a/test/unit/set/controllers/collections-controller-spec.js +++ b/test/unit/set/controllers/collections-controller-spec.js @@ -15,8 +15,7 @@ describe('set collections controller', function () { 'ushahidi.mock' ]); - testApp.controller('collectionsController', require(ROOT_PATH + 'app/set/controllers/collections-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('collectionsController', require(ROOT_PATH + 'app/set/controllers/collections-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/set/controllers/savedsearch-controller-spec.js b/test/unit/set/controllers/savedsearch-controller-spec.js index 1f6ebcd656..c35c8bcf0d 100644 --- a/test/unit/set/controllers/savedsearch-controller-spec.js +++ b/test/unit/set/controllers/savedsearch-controller-spec.js @@ -15,8 +15,7 @@ describe('set savedsearches controller', function () { 'ushahidi.mock' ]); - testApp.controller('savedsearchesController', require(ROOT_PATH + 'app/set/controllers/savedsearches-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('savedsearchesController', require(ROOT_PATH + 'app/set/controllers/savedsearches-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/setting/controllers/setting-categories-controller-spec.js b/test/unit/setting/controllers/setting-categories-controller-spec.js index 97da6a4829..e4d11a7040 100644 --- a/test/unit/setting/controllers/setting-categories-controller-spec.js +++ b/test/unit/setting/controllers/setting-categories-controller-spec.js @@ -13,8 +13,7 @@ describe('setting categories controller', function () { 'ushahidi.mock' ]); - testApp.controller('settingCategoriesController', require(ROOT_PATH + 'app/setting/controllers/setting-categories-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('settingCategoriesController', require(ROOT_PATH + 'app/setting/controllers/setting-categories-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/setting/controllers/setting-categories-create-controller-spec.js b/test/unit/setting/controllers/setting-categories-create-controller-spec.js index fcac594fde..0e79e9bd12 100644 --- a/test/unit/setting/controllers/setting-categories-create-controller-spec.js +++ b/test/unit/setting/controllers/setting-categories-create-controller-spec.js @@ -17,7 +17,6 @@ describe('setting categories create controller', function () { testApp.controller('settingCategoriesCreateController', require(ROOT_PATH + 'app/setting/controllers/setting-categories-create-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')) .service('multiTranslate', require(ROOT_PATH + 'app/common/services/multi-translate.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/setting/controllers/setting-categories-edit-controller-spec.js b/test/unit/setting/controllers/setting-categories-edit-controller-spec.js index aaa735b80e..c3faacd0f7 100644 --- a/test/unit/setting/controllers/setting-categories-edit-controller-spec.js +++ b/test/unit/setting/controllers/setting-categories-edit-controller-spec.js @@ -17,7 +17,6 @@ describe('setting categories edit controller', function () { testApp.controller('settingCategoriesEditController', require(ROOT_PATH + 'app/setting/controllers/setting-categories-edit-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')) .service('multiTranslate', require(ROOT_PATH + 'app/common/services/multi-translate.js')) .run(require(ROOT_PATH + 'app/common/global/event-handlers.js')); diff --git a/test/unit/setting/controllers/setting-roles-controller-spec.js b/test/unit/setting/controllers/setting-roles-controller-spec.js index 65d1860d0a..eb040a0276 100644 --- a/test/unit/setting/controllers/setting-roles-controller-spec.js +++ b/test/unit/setting/controllers/setting-roles-controller-spec.js @@ -44,8 +44,4 @@ describe('setting roles controller', function () { }); - it('should retrieve load and set title', function () { - expect($rootScope.$emit).toHaveBeenCalled(); - }); - }); diff --git a/test/unit/setting/controllers/setting-users-controller-spec.js b/test/unit/setting/controllers/setting-users-controller-spec.js index 4ae373ff97..d9d5a6e237 100644 --- a/test/unit/setting/controllers/setting-users-controller-spec.js +++ b/test/unit/setting/controllers/setting-users-controller-spec.js @@ -15,8 +15,7 @@ describe('setting users controller', function () { 'ushahidi.mock' ]); - testApp.controller('settingUsersController', require(ROOT_PATH + 'app/setting/controllers/setting-users-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('settingUsersController', require(ROOT_PATH + 'app/setting/controllers/setting-users-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/setting/controllers/setting-users-create-controller-spec.js b/test/unit/setting/controllers/setting-users-create-controller-spec.js index 68dce70284..5e15263c2c 100644 --- a/test/unit/setting/controllers/setting-users-create-controller-spec.js +++ b/test/unit/setting/controllers/setting-users-create-controller-spec.js @@ -15,8 +15,7 @@ describe('setting users create controller', function () { 'ushahidi.mock' ]); - testApp.controller('settingUsersCreateController', require(ROOT_PATH + 'app/setting/controllers/setting-users-create-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('settingUsersCreateController', require(ROOT_PATH + 'app/setting/controllers/setting-users-create-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/setting/controllers/setting-users-edit-controller-spec.js b/test/unit/setting/controllers/setting-users-edit-controller-spec.js index 4ae7f7fdb5..ce9b0f5eab 100644 --- a/test/unit/setting/controllers/setting-users-edit-controller-spec.js +++ b/test/unit/setting/controllers/setting-users-edit-controller-spec.js @@ -15,8 +15,7 @@ describe('setting users edit controller', function () { 'ushahidi.mock' ]); - testApp.controller('settingUsersEditController', require(ROOT_PATH + 'app/setting/controllers/setting-users-edit-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('settingUsersEditController', require(ROOT_PATH + 'app/setting/controllers/setting-users-edit-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/setting/controllers/setting-views-controller-spec.js b/test/unit/setting/controllers/setting-views-controller-spec.js index dcb09b3275..8ece055c94 100644 --- a/test/unit/setting/controllers/setting-views-controller-spec.js +++ b/test/unit/setting/controllers/setting-views-controller-spec.js @@ -15,8 +15,7 @@ describe('setting views controller', function () { 'ushahidi.mock' ]); - testApp.controller('settingViewsController', require(ROOT_PATH + 'app/setting/controllers/setting-views-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('settingViewsController', require(ROOT_PATH + 'app/setting/controllers/setting-views-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); diff --git a/test/unit/user-profile/controllers/notification-controller-spec.js b/test/unit/user-profile/controllers/notification-controller-spec.js index b89be66f3e..6c7b87e839 100644 --- a/test/unit/user-profile/controllers/notification-controller-spec.js +++ b/test/unit/user-profile/controllers/notification-controller-spec.js @@ -15,8 +15,7 @@ describe('user-profile notification controller', function () { 'ushahidi.mock' ]); - testApp.controller('notificationController', require(ROOT_PATH + 'app/user-profile/controllers/notification-controller.js')) - .service('RoleHelper', require(ROOT_PATH + 'app/common/services/role-helper.js')); + testApp.controller('notificationController', require(ROOT_PATH + 'app/user-profile/controllers/notification-controller.js')); require(ROOT_PATH + 'test/unit/simple-test-app-config')(testApp); From 46741484b9e49c2f37f468225af7d0e2d2905baf Mon Sep 17 00:00:00 2001 From: will Date: Mon, 15 Feb 2016 18:18:51 -0500 Subject: [PATCH 101/135] changed to use query instead of expecting permissions from platform --- app/common/services/authentication.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/common/services/authentication.js b/app/common/services/authentication.js index c9c9354589..64a6b78773 100644 --- a/app/common/services/authentication.js +++ b/app/common/services/authentication.js @@ -5,6 +5,7 @@ module.exports = [ 'Util', 'CONST', 'Session', + 'RoleEndpoint', '_', function ( $rootScope, @@ -13,6 +14,7 @@ function ( Util, CONST, Session, + RoleEndpoint, _ ) { @@ -64,12 +66,14 @@ function ( $http.get(Util.apiUrl('/users/me')).then( function (userDataResponse) { - + RoleEndpoint.query({name: userDataResponse.data.role}).$promise.then(function (results) { + userDataResponse.data.permissions = !_.isEmpty(results) ? results[0].permissions : []; setToLoginState(userDataResponse.data); $rootScope.$broadcast('event:authentication:login:succeeded'); deferred.resolve(); + }); }, handleRequestError); }; From ffd8c29c26f840d8a4876c2990e457432702db08 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 15 Feb 2016 18:48:20 -0500 Subject: [PATCH 102/135] linting --- app/common/services/authentication.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/common/services/authentication.js b/app/common/services/authentication.js index 64a6b78773..053561c0c0 100644 --- a/app/common/services/authentication.js +++ b/app/common/services/authentication.js @@ -67,12 +67,12 @@ function ( $http.get(Util.apiUrl('/users/me')).then( function (userDataResponse) { RoleEndpoint.query({name: userDataResponse.data.role}).$promise.then(function (results) { - userDataResponse.data.permissions = !_.isEmpty(results) ? results[0].permissions : []; - setToLoginState(userDataResponse.data); + userDataResponse.data.permissions = !_.isEmpty(results) ? results[0].permissions : []; + setToLoginState(userDataResponse.data); - $rootScope.$broadcast('event:authentication:login:succeeded'); + $rootScope.$broadcast('event:authentication:login:succeeded'); - deferred.resolve(); + deferred.resolve(); }); }, handleRequestError); }; From 977a7dd9e4a9e5cc4a600bc107a991b71a4fe1aa Mon Sep 17 00:00:00 2001 From: will Date: Mon, 15 Feb 2016 22:02:28 -0500 Subject: [PATCH 103/135] reverting capitalisation of role names --- app/common/global/event-handlers.js | 2 +- mocked_backend/api/v3/roles.json | 2 +- mocked_backend/api/v3/users.json | 40 ++++++++++++++--------------- mocked_backend/api/v3/users/me.json | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/common/global/event-handlers.js b/app/common/global/event-handlers.js index 772732ad08..87633feb81 100644 --- a/app/common/global/event-handlers.js +++ b/app/common/global/event-handlers.js @@ -44,7 +44,7 @@ function ( }; $rootScope.isAdmin = function () { - return (($rootScope.currentUser || {}).role === 'Admin'); + return (($rootScope.currentUser || {}).role === 'admin'); }; $rootScope.goBack = function () { diff --git a/mocked_backend/api/v3/roles.json b/mocked_backend/api/v3/roles.json index de3e46daa6..e9f5b55ce7 100644 --- a/mocked_backend/api/v3/roles.json +++ b/mocked_backend/api/v3/roles.json @@ -4,7 +4,7 @@ { "id": 1, "url": "http://api.ushahidi.dev/api/v3/roles/1", - "name": "Admin", + "name": "admin", "display_name": "Admin", "created": "1970-01-01T00:00:00+00:00", "updated": null, diff --git a/mocked_backend/api/v3/users.json b/mocked_backend/api/v3/users.json index d1c8a5e172..6c71e35a4f 100644 --- a/mocked_backend/api/v3/users.json +++ b/mocked_backend/api/v3/users.json @@ -12,7 +12,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "User", + "role": "user", "allowed_methods": [ "get", "post", @@ -31,7 +31,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -52,7 +52,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "User", + "role": "user", "allowed_methods": [ "get", "post", @@ -71,7 +71,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -90,7 +90,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -110,7 +110,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "User", + "role": "user", "allowed_methods": [ "get", "post", @@ -129,7 +129,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -147,7 +147,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "User", + "role": "user", "allowed_methods": [ "get", "post", @@ -166,7 +166,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -185,7 +185,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -204,7 +204,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "User", + "role": "user", "allowed_methods": [ "get", "post", @@ -223,7 +223,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -241,7 +241,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "User", + "role": "user", "allowed_methods": [ "get", "post", @@ -260,7 +260,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -279,7 +279,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -298,7 +298,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "User", + "role": "user", "allowed_methods": [ "get", "post", @@ -317,7 +317,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -335,7 +335,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "User", + "role": "user", "allowed_methods": [ "get", "post", @@ -354,7 +354,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", @@ -373,7 +373,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": null, - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", diff --git a/mocked_backend/api/v3/users/me.json b/mocked_backend/api/v3/users/me.json index b753c87c4d..ff39f91c73 100644 --- a/mocked_backend/api/v3/users/me.json +++ b/mocked_backend/api/v3/users/me.json @@ -9,7 +9,7 @@ "last_attempt": null, "created": "1970-01-01T00:00:00+00:00", "updated": "2014-12-13T19:17:57+00:00", - "role": "Admin", + "role": "admin", "allowed_methods": [ "get", "post", From bc1104b583c29f6bfb5b7efaa2d9a4d196fd9784 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 15 Feb 2016 22:30:35 -0500 Subject: [PATCH 104/135] prevent admin role deletion --- app/common/locales/en.json | 1 + .../directives/setting-roles-directive.js | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index bf491a8db6..a28d6079c4 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -601,6 +601,7 @@ "delete_question" : "Are you sure you want to delete the role {{role}}?", "destroy_success" : "Role {{role}} deleted.", "save_success" : "Role {{role}} saved.", + "last_admin" : "You can not delete the only admin role" }, "datasource" : { "save_success" : "Saved Data Source {{name}}", diff --git a/app/setting/directives/setting-roles-directive.js b/app/setting/directives/setting-roles-directive.js index c365de01e9..101af6202d 100644 --- a/app/setting/directives/setting-roles-directive.js +++ b/app/setting/directives/setting-roles-directive.js @@ -3,11 +3,13 @@ module.exports = [ '$location', 'RoleEndpoint', 'Notify', + '_', function ( $translate, $location, RoleEndpoint, - Notify + Notify, + _ ) { return { restrict: 'A', @@ -24,7 +26,27 @@ function ( $scope.refreshView(); + $scope.checkIfLastAdmin = function () { + var admins = 0; + _.each($scope.roles, function (role) { + if (role.name === 'admin') { + admins++; + } + }); + + return admins === 1; + }; + $scope.deleteRole = function (role) { + if (role.name === 'admin' && $scope.checkIfLastAdmin()) { + $translate('notify.role.last_admin') + .then(function (message) { + Notify.showSingleAlert(message); + }); + return; + + } + $translate('notify.role.delete_question', { role: role.display_name }).then(function (message) { From dbe5865804de8d845a7e008660b2de281ba733c2 Mon Sep 17 00:00:00 2001 From: will Date: Tue, 16 Feb 2016 13:25:22 -0500 Subject: [PATCH 105/135] changed flow of save for tag, role, user --- app/common/locales/en.json | 3 +++ .../controllers/setting-categories-create-controller.js | 8 ++++++-- .../controllers/setting-users-create-controller.js | 8 ++++++-- app/setting/directives/setting-roles-editor-directive.js | 7 +++++-- server/www/templates/settings/categories-edit.html | 7 ++++++- server/www/templates/settings/roles/roles-edit.html | 6 +++++- server/www/templates/settings/users-edit.html | 7 ++++++- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index a28d6079c4..f61788baeb 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -329,6 +329,7 @@ "name" : "Name", "description" : "Description", "save" : "Save Role", + "save_add_another" : "Save & Add Another", "permissions" : "Permissions", "delete" : "Delete", }, @@ -360,6 +361,7 @@ "tag": { "add_tag" : "Add Category", "save" : "Save Category", + "save_add_another" : "Save & Add Another", "choose_roles" : "Choose Roles", "create_tag" : "Create Category", "saved_tag": "Category saved.", @@ -475,6 +477,7 @@ "edit_user" : "Edit User", "change_role" : "Change Role", "save" : "Save User", + "save_add_another" : "Save & Add Another", "show_all_roles" : "Show All Roles", "cannot_delete_yourself" : "You cannot delete your own user", "cannot_change_your_own_role" : "You cannot change your own role", diff --git a/app/setting/controllers/setting-categories-create-controller.js b/app/setting/controllers/setting-categories-create-controller.js index cee399233f..83374c8566 100644 --- a/app/setting/controllers/setting-categories-create-controller.js +++ b/app/setting/controllers/setting-categories-create-controller.js @@ -2,6 +2,7 @@ module.exports = [ '$scope', '$location', '$translate', + '$route', 'multiTranslate', 'RoleEndpoint', 'TagEndpoint', @@ -11,6 +12,7 @@ function ( $scope, $location, $translate, + $route, multiTranslate, RoleEndpoint, TagEndpoint, @@ -30,8 +32,10 @@ function ( $scope.tag = { type: 'category', icon: 'tag' }; $scope.processing = false; - $scope.saveTag = function (tag) { + $scope.saveTag = function (tag, addAnother) { $scope.processing = true; + var whereToNext = 'settings/categories'; + TagEndpoint.saveCache(tag).$promise.then(function (response) { if (response.id) { $translate( @@ -41,7 +45,7 @@ function ( }).then(function (message) { Notify.showNotificationSlider(message); }); - $location.path('/settings/categories/' + response.id); + addAnother ? $route.reload() : $location.path(whereToNext); } }, function (errorResponse) { // error Notify.showApiErrors(errorResponse); diff --git a/app/setting/controllers/setting-users-create-controller.js b/app/setting/controllers/setting-users-create-controller.js index 6429132618..2e018a1e11 100644 --- a/app/setting/controllers/setting-users-create-controller.js +++ b/app/setting/controllers/setting-users-create-controller.js @@ -3,6 +3,7 @@ module.exports = [ '$rootScope', '$translate', '$location', + '$route', 'UserEndpoint', 'Notify', '_', @@ -12,6 +13,7 @@ function ( $rootScope, $translate, $location, + $route, UserEndpoint, Notify, _, @@ -25,8 +27,10 @@ function ( $scope.user = {}; $scope.processing = false; - $scope.saveUser = function (user) { + $scope.saveUser = function (user, addAnother) { $scope.processing = true; + var whereToNext = '/settings/users'; + UserEndpoint.saveCache(user).$promise.then(function (response) { if (response.id) { $translate('notify.user.save_success', {name: user.realname}).then(function (message) { @@ -35,7 +39,7 @@ function ( $scope.processing = false; $scope.userSavedUser = true; $scope.user.id = response.id; - $location.path('/settings/users/' + response.id); + addAnother ? $route.reload() : $location.path(whereToNext); } }, function (errorResponse) { // error Notify.showApiErrors(errorResponse); diff --git a/app/setting/directives/setting-roles-editor-directive.js b/app/setting/directives/setting-roles-editor-directive.js index d577ae3abe..347522bbb9 100644 --- a/app/setting/directives/setting-roles-editor-directive.js +++ b/app/setting/directives/setting-roles-editor-directive.js @@ -2,6 +2,7 @@ module.exports = [ '$translate', '$location', '$routeParams', + '$route', 'RoleEndpoint', 'PermissionEndpoint', 'Notify', @@ -9,6 +10,7 @@ function ( $translate, $location, $routeParams, + $route, RoleEndpoint, PermissionEndpoint, Notify @@ -33,14 +35,15 @@ function ( $scope.permissions = permissions.results; }); - $scope.saveRole = function (role) { + $scope.saveRole = function (role, addAnother) { $scope.processing = true; role.name = role.name ? role.name : role.display_name; + var whereToNext = 'settings/roles'; RoleEndpoint.saveCache(role).$promise.then(function (result) { $translate('notify.role.save_success', {role: role.display_name}).then(function (message) { Notify.showNotificationSlider(message); - $location.path('/settings/roles/' + result.id); + addAnother ? $route.reload() : $location.path(whereToNext); }); }, function (errorResponse) { // error Notify.showApiErrors(errorResponse); diff --git a/server/www/templates/settings/categories-edit.html b/server/www/templates/settings/categories-edit.html index ca352ea568..9da2764e73 100644 --- a/server/www/templates/settings/categories-edit.html +++ b/server/www/templates/settings/categories-edit.html @@ -50,10 +50,15 @@

    {{title}}

    - + +
    diff --git a/server/www/templates/settings/roles/roles-edit.html b/server/www/templates/settings/roles/roles-edit.html index deeb626fc9..bd0c773ac1 100644 --- a/server/www/templates/settings/roles/roles-edit.html +++ b/server/www/templates/settings/roles/roles-edit.html @@ -19,9 +19,13 @@

    - + +
    diff --git a/server/www/templates/settings/users-edit.html b/server/www/templates/settings/users-edit.html index b4fb2c0315..988e9383a2 100644 --- a/server/www/templates/settings/users-edit.html +++ b/server/www/templates/settings/users-edit.html @@ -49,10 +49,15 @@

    {{title}}

    - + +
    From a66ca646f5372f809f42c677790f41051bd7734f Mon Sep 17 00:00:00 2001 From: will Date: Tue, 16 Feb 2016 13:55:58 -0500 Subject: [PATCH 106/135] adding $route param for tests --- .../controllers/setting-categories-create-controller-spec.js | 3 ++- .../controllers/setting-users-create-controller-spec.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/setting/controllers/setting-categories-create-controller-spec.js b/test/unit/setting/controllers/setting-categories-create-controller-spec.js index 0e79e9bd12..8c16ba45d8 100644 --- a/test/unit/setting/controllers/setting-categories-create-controller-spec.js +++ b/test/unit/setting/controllers/setting-categories-create-controller-spec.js @@ -36,7 +36,8 @@ describe('setting categories create controller', function () { spyOn($scope, '$emit').and.callThrough(); $controller('settingCategoriesCreateController', { - $scope: $scope + $scope: $scope, + $route: {reload: function () {}} }); $rootScope.$digest(); diff --git a/test/unit/setting/controllers/setting-users-create-controller-spec.js b/test/unit/setting/controllers/setting-users-create-controller-spec.js index 5e15263c2c..9246a092df 100644 --- a/test/unit/setting/controllers/setting-users-create-controller-spec.js +++ b/test/unit/setting/controllers/setting-users-create-controller-spec.js @@ -35,7 +35,8 @@ describe('setting users create controller', function () { spyOn($rootScope, '$emit').and.callThrough(); $controller('settingUsersCreateController', { - $scope: $scope + $scope: $scope, + $route: {reload: function () {}} }); $rootScope.$digest(); From e0c8c6cf868900963cc7c2cd1fd85a527fd1e79b Mon Sep 17 00:00:00 2001 From: will Date: Tue, 16 Feb 2016 14:30:46 -0500 Subject: [PATCH 107/135] fixed merge issue --- server/www/templates/posts/detail.html | 1 - 1 file changed, 1 deletion(-) diff --git a/server/www/templates/posts/detail.html b/server/www/templates/posts/detail.html index b3e37a9ebb..02cfaaf47f 100644 --- a/server/www/templates/posts/detail.html +++ b/server/www/templates/posts/detail.html @@ -23,7 +23,6 @@

    Fields

    - -
    - +
    @@ -158,7 +158,7 @@

    Fields

    -
    + @@ -188,4 +188,3 @@

    {{ type.label }}

    - diff --git a/server/www/templates/settings/forms/forms.html b/server/www/templates/settings/forms/forms.html index 544adfd2d9..366b24ddef 100644 --- a/server/www/templates/settings/forms/forms.html +++ b/server/www/templates/settings/forms/forms.html @@ -22,7 +22,7 @@

    Post Types

    -->

    {{form.name}}

    - +
    From 1d4ce401b24a1b6f51fb207d790a5941ca498d9f Mon Sep 17 00:00:00 2001 From: will Date: Wed, 17 Feb 2016 13:13:11 -0500 Subject: [PATCH 115/135] fixed required step language and checkbox/date/datetime not being validated --- app/common/locales/en.json | 2 +- app/post/directives/post-editor-directive.js | 18 +++++++++++++++--- server/www/templates/posts/post-editor.html | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index f730aa40aa..f557f1670b 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -258,7 +258,7 @@ "add_a_post" : "Add a post", "edit_post" : "Edit {{title}}", "change_type" : "Change type", - "incomplete_step" : "The required step {{stage}} is not marked complete", + "incomplete_step" : "To publish a post all required steps must be marked as complete. The required step {{stage}} has not yet been marked complete", "save" : "Save", "save_post" : "Save Post", "publish" : "Publish to...", diff --git a/app/post/directives/post-editor-directive.js b/app/post/directives/post-editor-directive.js index 1476ebdfb5..cbd6688932 100644 --- a/app/post/directives/post-editor-directive.js +++ b/app/post/directives/post-editor-directive.js @@ -132,10 +132,22 @@ function ( return _.chain($scope.attributes) .where({form_stage_id : stageId, required: true}) .reduce(function (isValid, attr) { - if (_.isUndefined($scope.form['values_' + attr.key]) || $scope.form['values_' + attr.key].$invalid) { - return false; + // checkbox validity needs to be handled differently + // because it has multiple inputs identified via the options + if (attr.input === 'checkbox') { + var checkboxValidity = false; + _.each(attr.options, function (option) { + if (!_.isUndefined($scope.form['values_' + attr.key + '_' + option]) && !$scope.form['values_' + attr.key + '_' + option].$invalid) { + checkboxValidity = isValid; + } + }); + return checkboxValidity; + } else { + if (_.isUndefined($scope.form['values_' + attr.key]) || $scope.form['values_' + attr.key].$invalid) { + return false; + } + return isValid; } - return isValid; }, true) .value(); }; diff --git a/server/www/templates/posts/post-editor.html b/server/www/templates/posts/post-editor.html index ab31333193..969f02d764 100644 --- a/server/www/templates/posts/post-editor.html +++ b/server/www/templates/posts/post-editor.html @@ -132,6 +132,8 @@

    @@ -147,6 +149,8 @@

    Date: Wed, 17 Feb 2016 13:58:38 -0500 Subject: [PATCH 116/135] fixed page title --- app/setting/controllers/setting-roles-controller.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/setting/controllers/setting-roles-controller.js b/app/setting/controllers/setting-roles-controller.js index 2b6da52f5c..e84ea05f92 100644 --- a/app/setting/controllers/setting-roles-controller.js +++ b/app/setting/controllers/setting-roles-controller.js @@ -1,10 +1,17 @@ module.exports = [ '$scope', + '$translate', 'RoleEndpoint', 'PermissionEndpoint', function ( $scope, + $translate, RoleEndpoint, PermissionEndpoint ) { + $translate('tool.manage_roles').then(function (title) { + $scope.title = title; + $scope.$emit('setPageTitle', title); + }); + }]; From a5a1a898020ee633abeff1f292edfba09bdb1c84 Mon Sep 17 00:00:00 2001 From: will Date: Wed, 17 Feb 2016 14:09:46 -0500 Subject: [PATCH 117/135] fixed [object] display instead of string --- app/post/controllers/post-detail-controller.js | 2 +- app/post/directives/post-preview-directive.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/post/controllers/post-detail-controller.js b/app/post/controllers/post-detail-controller.js index 4169cca60e..496f3d0fcd 100644 --- a/app/post/controllers/post-detail-controller.js +++ b/app/post/controllers/post-detail-controller.js @@ -49,7 +49,7 @@ function ( return 'post.publish_for_you'; } if (!_.isEmpty($scope.post.published_to)) { - return $scope.post.published_to; + return $scope.post.published_to.join(', '); } return 'post.publish_for_everyone'; diff --git a/app/post/directives/post-preview-directive.js b/app/post/directives/post-preview-directive.js index 4f397d54bd..214de049c6 100644 --- a/app/post/directives/post-preview-directive.js +++ b/app/post/directives/post-preview-directive.js @@ -71,7 +71,7 @@ function ( } if (!_.isEmpty($scope.post.published_to)) { - return $scope.post.published_to; + return $scope.post.published_to.join(', '); } return 'post.publish_for_everyone'; From 1028a38de04bd30e6c9ecc790d5958973f0696ce Mon Sep 17 00:00:00 2001 From: Seth Hall Date: Wed, 17 Feb 2016 14:44:29 -0500 Subject: [PATCH 118/135] FIX: vertical tabs broken layout * the blank `
  • ` is a fix that prevents layout from breaking when adding infinite steps --- server/www/templates/posts/detail.html | 1 + server/www/templates/posts/post-editor.html | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server/www/templates/posts/detail.html b/server/www/templates/posts/detail.html index 02cfaaf47f..c7e8639543 100644 --- a/server/www/templates/posts/detail.html +++ b/server/www/templates/posts/detail.html @@ -52,6 +52,7 @@

  • +
  • // This prevents vertical tabs layout from breaking. leave this blank.
    diff --git a/server/www/templates/posts/post-editor.html b/server/www/templates/posts/post-editor.html index 969f02d764..dfdcb69d26 100644 --- a/server/www/templates/posts/post-editor.html +++ b/server/www/templates/posts/post-editor.html @@ -70,6 +70,7 @@

    +
  • // This prevents vertical tabs layout from breaking. leave this blank.
    @@ -128,17 +129,17 @@

    -
    From e24fc3eeaf2b596ba89cafaadec434b2e86a9083 Mon Sep 17 00:00:00 2001 From: will Date: Wed, 17 Feb 2016 14:57:21 -0500 Subject: [PATCH 119/135] changed comment style --- server/www/templates/posts/detail.html | 2 +- server/www/templates/posts/post-editor.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/www/templates/posts/detail.html b/server/www/templates/posts/detail.html index c7e8639543..85079120c7 100644 --- a/server/www/templates/posts/detail.html +++ b/server/www/templates/posts/detail.html @@ -52,7 +52,7 @@

    -
  • // This prevents vertical tabs layout from breaking. leave this blank. +
  • diff --git a/server/www/templates/posts/post-editor.html b/server/www/templates/posts/post-editor.html index dfdcb69d26..caeca75e69 100644 --- a/server/www/templates/posts/post-editor.html +++ b/server/www/templates/posts/post-editor.html @@ -70,7 +70,7 @@

    -
  • // This prevents vertical tabs layout from breaking. leave this blank. +
  • From 880fa6357d4cbe8f27ed6293070f4a6e152beef9 Mon Sep 17 00:00:00 2001 From: will Date: Wed, 17 Feb 2016 15:51:07 -0500 Subject: [PATCH 120/135] adding private deployment enabled check --- app/common/services/config.js | 3 +++ app/setting/directives/setting-editor-directive.js | 6 ++++++ server/www/templates/settings/settings-editor.html | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/common/services/config.js b/app/common/services/config.js index ef1907f017..3f824810bd 100644 --- a/app/common/services/config.js +++ b/app/common/services/config.js @@ -2,10 +2,12 @@ module.exports = [ 'ConfigEndpoint', 'Util', 'Notify', + 'BootstrapConfig', '_', function ( ConfigEndpoint, Util, + BootstrapConfig, Notify, _ ) { @@ -15,6 +17,7 @@ function ( var Config = { map : ConfigEndpoint.get({ id: 'map' }), site : ConfigEndpoint.get({ id: 'site' }), + features : ConfigEndpoint.getFresh({ id: 'features' }), saving: function (id) { return !!saving[id]; diff --git a/app/setting/directives/setting-editor-directive.js b/app/setting/directives/setting-editor-directive.js index c2fffdd4a4..2c3e7bab3e 100644 --- a/app/setting/directives/setting-editor-directive.js +++ b/app/setting/directives/setting-editor-directive.js @@ -4,6 +4,7 @@ module.exports = [ '$translate', '$rootScope', 'ConfigEndpoint', + 'Config', '_', 'Notify', 'Util', @@ -14,6 +15,7 @@ function ( $translate, $rootScope, ConfigEndpoint, + Config, _, Notify, Util, @@ -33,6 +35,10 @@ function ( file : null }; + $scope.isPrivateEnabled = function () { + return Config.features.private.enabled; + }; + $scope.site = ConfigEndpoint.get({ id: 'site' }); $scope.userSavedSettings = false; diff --git a/server/www/templates/settings/settings-editor.html b/server/www/templates/settings/settings-editor.html index b27401bb29..bcd88fc514 100644 --- a/server/www/templates/settings/settings-editor.html +++ b/server/www/templates/settings/settings-editor.html @@ -30,9 +30,9 @@
    -
    - - +
    + +
    From f8932f159e79c147cc73e923f702983d5597396a Mon Sep 17 00:00:00 2001 From: will Date: Wed, 17 Feb 2016 16:26:11 -0500 Subject: [PATCH 121/135] Adding missing activity translations --- app/common/locales/en.json | 5 +++++ server/www/templates/activity/activity-timeline.html | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index f557f1670b..89ba8dc908 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -6,6 +6,11 @@ "report_a_bug": "Report a bug", "forbidden": "Sorry, you're not allowed to do that." }, + "activity": { + "recent_activity_timeline" : "Recent Activity timeline", + "new_post" : "New Post", + "by" : "By", + }, "form": { "add_field" : "Add field", "add_field_instructions": "Add instructions to this field", diff --git a/server/www/templates/activity/activity-timeline.html b/server/www/templates/activity/activity-timeline.html index 70055863fd..bb56d03d93 100644 --- a/server/www/templates/activity/activity-timeline.html +++ b/server/www/templates/activity/activity-timeline.html @@ -1,19 +1,19 @@
    -

    Recent Activity Timeline

    +

    activity.recent_activity_timeline

    AGO
    -
    - New Post +
    + activity.new_post

    -

    By

    +

    activity.by

    From 06807317393a1a9f83e4a3e3b987dff66f9fb544 Mon Sep 17 00:00:00 2001 From: will Date: Wed, 17 Feb 2016 16:54:08 -0500 Subject: [PATCH 122/135] fixed featured option not appearing --- app/set/directives/collection-editor-directive.js | 4 ++++ server/www/templates/sets/collection-editor.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/set/directives/collection-editor-directive.js b/app/set/directives/collection-editor-directive.js index 71c8dbb589..64a3fad93e 100644 --- a/app/set/directives/collection-editor-directive.js +++ b/app/set/directives/collection-editor-directive.js @@ -36,6 +36,10 @@ function ( $scope.views = PostViewHelper.views(); + $scope.featuredEnabled = function () { + return $rootScope.hasPermission('Manage Posts'); + }; + // Set default view for Collection to be Map if (!$scope.collection) { $scope.collection = {}; diff --git a/server/www/templates/sets/collection-editor.html b/server/www/templates/sets/collection-editor.html index 56689cd8a1..2285483bf3 100644 --- a/server/www/templates/sets/collection-editor.html +++ b/server/www/templates/sets/collection-editor.html @@ -20,7 +20,7 @@
    -
    +
    -
    +

    - - From 00ad556c1f795dee95654baf8676732a74a79cca Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 18 Feb 2016 13:33:04 +1300 Subject: [PATCH 125/135] Fix services/config dependencies --- app/common/services/config.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/common/services/config.js b/app/common/services/config.js index 3f824810bd..ab3618b9ce 100644 --- a/app/common/services/config.js +++ b/app/common/services/config.js @@ -2,12 +2,11 @@ module.exports = [ 'ConfigEndpoint', 'Util', 'Notify', - 'BootstrapConfig', '_', function ( ConfigEndpoint, - Util, BootstrapConfig, + Util, Notify, _ ) { From 422da89db66ac10894e785cff9be5c9264a3a3c5 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 18 Feb 2016 13:33:17 +1300 Subject: [PATCH 126/135] Add/updates config mock backend --- app/mock-backend-config.js | 6 +- mocked_backend/api/v3/config.json | 76 ++++++++++++++++++++++ mocked_backend/api/v3/config/features.json | 47 +++++++++---- mocked_backend/api/v3/config/map.json | 21 +++--- 4 files changed, 125 insertions(+), 25 deletions(-) create mode 100644 mocked_backend/api/v3/config.json diff --git a/app/mock-backend-config.js b/app/mock-backend-config.js index 4bb23ac644..0677c9949a 100644 --- a/app/mock-backend-config.js +++ b/app/mock-backend-config.js @@ -10,13 +10,15 @@ angular.module('e2e-mocks', ['ngMockE2E']) 'forms/1/stages': require('../mocked_backend/api/v3/stages.json'), 'forms/1/stages/4': require('../mocked_backend/api/v3/stages/4.json'), 'forms/1/attributes': require('../mocked_backend/api/v3/attributes.json'), - 'config/map': require('../mocked_backend/api/v3/config/map.json'), 'sets': require('../mocked_backend/api/v3/sets.json'), 'collections': require('../mocked_backend/api/v3/collections.json'), 'roles': require('../mocked_backend/api/v3/roles.json'), 'users': require('../mocked_backend/api/v3/users.json'), 'users/me': require('../mocked_backend/api/v3/users/me.json'), - 'config/site': require('../mocked_backend/api/v3/config/site.json') + 'config/site': require('../mocked_backend/api/v3/config/site.json'), + 'config/map': require('../mocked_backend/api/v3/config/map.json'), + 'config/features': require('../mocked_backend/api/v3/config/features.json'), + 'config': require('../mocked_backend/api/v3/config.json') }, getResultForResource = function (resourceName, offset, limit) { diff --git a/mocked_backend/api/v3/config.json b/mocked_backend/api/v3/config.json new file mode 100644 index 0000000000..176dfb9a1b --- /dev/null +++ b/mocked_backend/api/v3/config.json @@ -0,0 +1,76 @@ +{ + "count": 3, + "results": [ + { + "id": "features", + "views": { + "map": true, + "list": true, + "chart": true, + "timeline": true, + "activity": true + }, + "data-providers": { + "smssync": true, + "twitter": true, + "frontlinesms": true, + "email": true, + "twilio": true, + "nexmo": true + }, + "limits": { + "posts": true, + "forms": true, + "admin_users": true + }, + "private": { + "enabled": true + }, + "roles": { + "enabled": true + }, + "data-import": { + "enabled": true + }, + "allowed_privileges": [ + "read", + "search" + ] + }, + { + "id": "site", + "name": "", + "description": "", + "email": "", + "timezone": "UTC", + "language": "en-US", + "date_format": "n/j/Y", + "client_url": false, + "first_login": true, + "tier": "free", + "private": false, + "allowed_privileges": [ + "read", + "search" + ] + }, + { + "id": "map", + "clustering": false, + "cluster_radius": 50, + "default_view": { + "lat": -1.3048035, + "lon": 36.8473969, + "zoom": 2, + "baselayer": "MapQuest", + "fit_map_boundaries": true, + "icon": "map-marker", + "color": "blue" + }, + "allowed_privileges": [ + "read", + "search" + ] + } + ] +} diff --git a/mocked_backend/api/v3/config/features.json b/mocked_backend/api/v3/config/features.json index a594f37728..95e4b096d6 100644 --- a/mocked_backend/api/v3/config/features.json +++ b/mocked_backend/api/v3/config/features.json @@ -1,16 +1,37 @@ + { "id": "features", - "api_explorer": false, - "data_provider": true, - "form_wizard": false, - "map_settings": true, - "media_uploads": false, - "post_export": true, - "sets_ui": false, - "allowed_methods": { - "get": true, - "post": true, - "put": true, - "delete": true - } + "views": { + "map": true, + "list": true, + "chart": true, + "timeline": true, + "activity": true + }, + "data-providers": { + "smssync": true, + "twitter": true, + "frontlinesms": true, + "email": true, + "twilio": true, + "nexmo": true + }, + "limits": { + "posts": true, + "forms": true, + "admin_users": true + }, + "private": { + "enabled": true + }, + "roles": { + "enabled": true + }, + "data-import": { + "enabled": true + }, + "allowed_privileges": [ + "read", + "search" + ] } diff --git a/mocked_backend/api/v3/config/map.json b/mocked_backend/api/v3/config/map.json index 0d7adcea8d..fa4b6f8415 100644 --- a/mocked_backend/api/v3/config/map.json +++ b/mocked_backend/api/v3/config/map.json @@ -1,17 +1,18 @@ { "id": "map", "clustering": false, - "maxClusterRadius": 50, + "cluster_radius": 50, "default_view": { - "baseLayer": "MapQuest", - "zoom": 2, "lat": -1.3048035, - "lon": 36.8473969 + "lon": 36.8473969, + "zoom": 2, + "baselayer": "MapQuest", + "fit_map_boundaries": true, + "icon": "map-marker", + "color": "blue" }, - "allowed_methods": { - "get": true, - "post": true, - "put": true, - "delete": true - } + "allowed_privileges": [ + "read", + "search" + ] } From ae875243f9cd492f40d7bc9d35a354d63bffe837 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 18 Feb 2016 21:37:25 +1300 Subject: [PATCH 127/135] Declare dependencies explicitly for data-mapper/ route resolve function. We use strict DI because otherwise dependencies break when compressing JS --- app/setting/setting-routes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/setting/setting-routes.js b/app/setting/setting-routes.js index d3cb969a20..713d8f98da 100644 --- a/app/setting/setting-routes.js +++ b/app/setting/setting-routes.js @@ -24,12 +24,12 @@ function ( controller: require('./controllers/setting-data-mapper-controller.js'), templateUrl: 'templates/settings/data-import/data-mapper.html', resolve: { - initialData: function ($route, DataRetriever) { + initialData: ['$route', 'DataRetriever', function ($route, DataRetriever) { return DataRetriever.dataMapperInitialData( $route.current.params.formId, $route.current.params.id ); - } + }] } }) .when('/settings/plugins', { From 8de85c55379a95094791b0183e355f069b554f12 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 18 Feb 2016 22:24:17 +1300 Subject: [PATCH 128/135] CSV: Add post content to mappable fields. --- app/common/services/data-retriever.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/common/services/data-retriever.js b/app/common/services/data-retriever.js index aa4713558f..cac1c2fe87 100644 --- a/app/common/services/data-retriever.js +++ b/app/common/services/data-retriever.js @@ -1,6 +1,7 @@ module.exports = [ '_', '$q', + '$translate', 'FormEndpoint', 'FormAttributeEndpoint', 'DataImportEndpoint', @@ -8,6 +9,7 @@ module.exports = [ function ( _, $q, + $translate, FormEndpoint, FormAttributeEndpoint, DataImportEndpoint, @@ -30,7 +32,11 @@ function ( form.attributes.push( { 'key': 'title', - 'label': 'title' + 'label': $translate.instant('post.modify.form.title') + }, + { + 'key': 'content', + 'label': $translate.instant('post.modify.form.description') } ); var csv = results[2]; From baedb162923235e8847daf9facfaf541261ab277 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 18 Feb 2016 22:45:24 +1300 Subject: [PATCH 129/135] Map CSV columns to lat or lon of a point field --- app/common/services/data-retriever.js | 42 ++++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/app/common/services/data-retriever.js b/app/common/services/data-retriever.js index cac1c2fe87..8687c1912c 100644 --- a/app/common/services/data-retriever.js +++ b/app/common/services/data-retriever.js @@ -24,21 +24,41 @@ function ( DataImportEndpoint.get({id: csvId}).$promise ]).then(function (results) { var form = results[0]; + // Split locations into lat/lon + var points = _.chain(results[1]) + .where({'type' : 'point'}) + .reduce(function (collection, item) { + return collection.concat( + { + key: item.key + '.lat', + label: item.label + ' (Latitude)', + priority: item.priority + }, { + key: item.key + '.lon', + label: item.label + ' (Longitude)', + priority: item.priority + } + ); + }, []) + .value(); + form.attributes = _.chain(results[1]) + .concat(points) + // Add in the Post specific mappable fields + .push({ + 'key': 'title', + 'label': $translate.instant('post.modify.form.title'), + 'priority': 0 + }, + { + 'key': 'content', + 'label': $translate.instant('post.modify.form.description'), + 'priority': 1 + } + ) .sortBy('priority') .value(); - // Add in the Post specific mappable fields - form.attributes.push( - { - 'key': 'title', - 'label': $translate.instant('post.modify.form.title') - }, - { - 'key': 'content', - 'label': $translate.instant('post.modify.form.description') - } - ); var csv = results[2]; csv.maps_to = Util.autoMap( csv.columns, From aeb314a10cc96bc37fdfac2fefe348d595a7ac09 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 18 Feb 2016 23:04:34 +1300 Subject: [PATCH 130/135] Update instructions for import locations --- app/common/locales/en.json | 10 ++++------ app/common/services/data-retriever.js | 1 + .../templates/settings/data-import/data-import.html | 2 -- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index bf386202b7..6419c9e7f9 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -461,12 +461,10 @@ }, "data_import" :{ "import" : "Import", - "import_explanation_csv" : "Import the data from a CSV spreadsheet into your deployment as posts belonging to a specific post type.", - "import_explanation_file_size" : " - The size for a single file is limited to 2 MB.", - "import_explanation_format_location_1" : " - In order to include location geographic points in your csv. That location should have the following format:", - "import_explanation_format_location_2" : "'{\"lat\": coordinate, \"lon\": coordinate}'", - "import_explanation_format_location_3" : "where coordinate is a point value, for example, 41.54332", - "import_explanation_required_fields" : " - All required post type fields must have an associated value set in the CSV. For example, if the field title is required then the field must be mapped to a CSV column where all rows of that column have a value set.", + "import_explanation_csv" : "Import the data from a CSV spreadsheet into your deployment as posts belonging to a specific post type", + "import_explanation_file_size" : " - The size for a single file is limited to 10 MB", + "import_explanation_format_location_1" : " - Geographic locations should be included as separate latitude and longitude columns in your CSV", + "import_explanation_required_fields" : " - All required post type fields must have an associated value set in the CSV. For example, if the field title is required then the field must be mapped to a CSV column where all rows of that column have a value set", "csv" : "CSV", "post_type" : "Import to which post type?", "file_csv" : "CSV file", diff --git a/app/common/services/data-retriever.js b/app/common/services/data-retriever.js index 8687c1912c..99ded67782 100644 --- a/app/common/services/data-retriever.js +++ b/app/common/services/data-retriever.js @@ -43,6 +43,7 @@ function ( .value(); form.attributes = _.chain(results[1]) + .reject({type : 'point'}) .concat(points) // Add in the Post specific mappable fields .push({ diff --git a/server/www/templates/settings/data-import/data-import.html b/server/www/templates/settings/data-import/data-import.html index 82555e0d51..2131de93d3 100644 --- a/server/www/templates/settings/data-import/data-import.html +++ b/server/www/templates/settings/data-import/data-import.html @@ -14,8 +14,6 @@

    data_import.csv

    data_import.import_explanation_file_size

    data_import.import_explanation_required_fields

    data_import.import_explanation_format_location_1

    -

    data_import.import_explanation_format_location_2

    -

    data_import.import_explanation_format_location_3

    From 107ab5fe91705ffc85b0d362dc585fe2216b3bdc Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 18 Feb 2016 23:37:46 +1300 Subject: [PATCH 131/135] Better reporting when data import is completed --- app/common/locales/en.json | 2 +- .../directives/setting-data-mapper-directive.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index bf386202b7..b796632964 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -563,7 +563,7 @@ }, "data_import" : { "csv_upload" : "File {{name}} successfully uploaded", - "csv_mappings_set" : "CSV mappings set successfully", + "csv_mappings_set" : "CSV imported. {{processed}} records imported, {{errors}} records failed.", "duplicate_fields" : "Columns must be mapped to unique post type fields. The following fields have more than 1 mapping: {{duplicates}}", "required_fields" : "Required fields must be set to a value. The following fields have not been set: {{required}}" }, diff --git a/app/setting/directives/setting-data-mapper-directive.js b/app/setting/directives/setting-data-mapper-directive.js index 0970e1bca5..4a868ac423 100644 --- a/app/setting/directives/setting-data-mapper-directive.js +++ b/app/setting/directives/setting-data-mapper-directive.js @@ -34,13 +34,16 @@ function ( DataImportEndpoint.import({id: $scope.csv.id, action: 'import'}) .$promise .then(function (response) { - $translate('notify.data_import.csv_mappings_set').then( - function (message) { - Notify.showNotificationSlider(message); - - $scope.deleteDataImport($scope.csv); - $location.url('/views/list'); - }); + $translate('notify.data_import.csv_mappings_set', { + processed: response.processed, + errors: response.errors + }).then( + function (message) { + Notify.showNotificationSlider(message); + + $scope.deleteDataImport($scope.csv); + $location.url('/views/list'); + }); }, function (errorResponse) { Notify.showApiErrors(errorResponse); }); From 6d21022ccfe3e6a446b7114238bdf2ecf32dbad2 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 18 Feb 2016 23:38:00 +1300 Subject: [PATCH 132/135] Add missing translation for csv_import_cancel --- app/common/locales/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/common/locales/en.json b/app/common/locales/en.json index b796632964..75db91125a 100644 --- a/app/common/locales/en.json +++ b/app/common/locales/en.json @@ -565,7 +565,8 @@ "csv_upload" : "File {{name}} successfully uploaded", "csv_mappings_set" : "CSV imported. {{processed}} records imported, {{errors}} records failed.", "duplicate_fields" : "Columns must be mapped to unique post type fields. The following fields have more than 1 mapping: {{duplicates}}", - "required_fields" : "Required fields must be set to a value. The following fields have not been set: {{required}}" + "required_fields" : "Required fields must be set to a value. The following fields have not been set: {{required}}", + "csv_import_cancel" : "CSV import cancelled" }, "general_settings" : { "save_success" : "General settings saved" From f04d89584c12385d65f71bb8d520dc2446095665 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Fri, 19 Feb 2016 00:19:22 +1300 Subject: [PATCH 133/135] Fix new collection button in main menu Fixes ushahidi/platform#867 --- app/set/directives/collection-editor-directive.js | 2 +- server/www/templates/partials/main-menu.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/set/directives/collection-editor-directive.js b/app/set/directives/collection-editor-directive.js index 64a3fad93e..dfed9d83e4 100644 --- a/app/set/directives/collection-editor-directive.js +++ b/app/set/directives/collection-editor-directive.js @@ -24,7 +24,7 @@ function ( replace: true, templateUrl: 'templates/sets/collection-editor.html', scope: { - collection: '=', + collection: '=?', isOpen: '=' }, link: function ($scope, $element, $attrs) { diff --git a/server/www/templates/partials/main-menu.html b/server/www/templates/partials/main-menu.html index c4bf43a231..26fd1c5b5f 100644 --- a/server/www/templates/partials/main-menu.html +++ b/server/www/templates/partials/main-menu.html @@ -34,8 +34,8 @@
    nav.saved_searches
    From 50fdbc716fbb5584af1d935d20288d94bfbd6a71 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Fri, 19 Feb 2016 00:51:02 +1300 Subject: [PATCH 134/135] Add minimal validation on CSV uploads --- app/common/directives/file-upload.js | 5 +++-- server/www/templates/file-upload/file-upload.html | 2 +- .../www/templates/settings/data-import/data-import.html | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/common/directives/file-upload.js b/app/common/directives/file-upload.js index 46eee1200a..d38361498c 100644 --- a/app/common/directives/file-upload.js +++ b/app/common/directives/file-upload.js @@ -9,10 +9,11 @@ angular.module('ushahidi.common.file-upload', []) }, controller: [ - '$scope', + '$scope', '$attrs', function ( - $scope + $scope, $attrs ) { + $scope.required = typeof $attrs.required !== 'undefined'; $scope.uploadFile = function ($event) { $scope.fileContainer.file = $event.target.files[0]; }; diff --git a/server/www/templates/file-upload/file-upload.html b/server/www/templates/file-upload/file-upload.html index f4ab82f6cd..3e5fa59082 100644 --- a/server/www/templates/file-upload/file-upload.html +++ b/server/www/templates/file-upload/file-upload.html @@ -1,2 +1,2 @@ - + diff --git a/server/www/templates/settings/data-import/data-import.html b/server/www/templates/settings/data-import/data-import.html index 2131de93d3..db74dda2bc 100644 --- a/server/www/templates/settings/data-import/data-import.html +++ b/server/www/templates/settings/data-import/data-import.html @@ -7,8 +7,9 @@

    data_import.import

    +
    -
    +

    data_import.csv

    data_import.import_explanation_csv

    data_import.import_explanation_file_size

    @@ -18,7 +19,7 @@

    data_import.csv

    -
    - +
    - +
    From 8b902b8580989bd16a303fc5931111b3c716d859 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Fri, 19 Feb 2016 01:26:55 +1300 Subject: [PATCH 135/135] Bump version to 3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b946b9fc5..87b4750023 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ushahidi-platform-client", - "version": "3.1.0", + "version": "3.2.0", "description": "Ushahidi Platform Official Web Client", "main": "gulpfile.js", "repository": {