thingsboard-aplcache

Details

diff --git a/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java b/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java
index 1c508ca..65df81f 100644
--- a/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java
+++ b/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java
@@ -333,4 +333,28 @@ public class EntityViewController extends BaseController {
             throw handleException(e);
         }
     }
+
+    @PreAuthorize("hasAuthority('TENANT_ADMIN')")
+    @RequestMapping(value = "/customer/public/entityView/{entityViewId}", method = RequestMethod.POST)
+    @ResponseBody
+    public EntityView assignEntityViewToPublicCustomer(@PathVariable(ENTITY_VIEW_ID) String strEntityViewId) throws ThingsboardException {
+        checkParameter(ENTITY_VIEW_ID, strEntityViewId);
+        try {
+            EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
+            EntityView entityView = checkEntityViewId(entityViewId);
+            Customer publicCustomer = customerService.findOrCreatePublicCustomer(entityView.getTenantId());
+            EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToCustomer(getCurrentUser().getTenantId(), entityViewId, publicCustomer.getId()));
+
+            logEntityAction(entityViewId, savedEntityView,
+                    savedEntityView.getCustomerId(),
+                    ActionType.ASSIGNED_TO_CUSTOMER, null, strEntityViewId, publicCustomer.getId().toString(), publicCustomer.getName());
+
+            return savedEntityView;
+        } catch (Exception e) {
+            logEntityAction(emptyId(EntityType.ENTITY_VIEW), null,
+                    null,
+                    ActionType.ASSIGNED_TO_CUSTOMER, e, strEntityViewId);
+            throw handleException(e);
+        }
+    }
 }
diff --git a/ui/src/app/api/entity-view.service.js b/ui/src/app/api/entity-view.service.js
index ca665cd..257e3dd 100644
--- a/ui/src/app/api/entity-view.service.js
+++ b/ui/src/app/api/entity-view.service.js
@@ -34,7 +34,8 @@ function EntityViewService($http, $q, $window, userService, attributeService, cu
         subscribeForEntityViewAttributes: subscribeForEntityViewAttributes,
         unsubscribeForEntityViewAttributes: unsubscribeForEntityViewAttributes,
         findByQuery: findByQuery,
-        getEntityViewTypes: getEntityViewTypes
+        getEntityViewTypes: getEntityViewTypes,
+        makeEntityViewPublic: makeEntityViewPublic
     }
 
     return service;
@@ -208,4 +209,16 @@ function EntityViewService($http, $q, $window, userService, attributeService, cu
         return deferred.promise;
     }
 
+    function makeEntityViewPublic(entityViewId) {
+        var deferred = $q.defer();
+        var url = '/api/customer/public/entityView/' + entityViewId;
+        $http.post(url, null).then(function success(response) {
+            deferred.resolve(response.data);
+        }, function fail() {
+            deferred.reject();
+        });
+        return deferred.promise;
+    }
+
+
 }
diff --git a/ui/src/app/entity/entity-list.scss b/ui/src/app/entity/entity-list.scss
index f8b8c4c..2ac0918 100644
--- a/ui/src/app/entity/entity-list.scss
+++ b/ui/src/app/entity/entity-list.scss
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 /*
 .tb-entity-list {
   #entity_list_chips {
diff --git a/ui/src/app/entity/entity-select.scss b/ui/src/app/entity/entity-select.scss
index 4216d3f..8a1d36d 100644
--- a/ui/src/app/entity/entity-select.scss
+++ b/ui/src/app/entity/entity-select.scss
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 /*
 .tb-entity-select {
 }
diff --git a/ui/src/app/entity/entity-subtype-list.scss b/ui/src/app/entity/entity-subtype-list.scss
index b4aef5f..967d9a3 100644
--- a/ui/src/app/entity/entity-subtype-list.scss
+++ b/ui/src/app/entity/entity-subtype-list.scss
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 /*
 .tb-entity-subtype-list {
   #entity_subtype_list_chips {
diff --git a/ui/src/app/entity/entity-type-list.scss b/ui/src/app/entity/entity-type-list.scss
index 76d66d1..a0e51af 100644
--- a/ui/src/app/entity/entity-type-list.scss
+++ b/ui/src/app/entity/entity-type-list.scss
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 /*
 .tb-entity-type-list {
   #entity_type_list_chips {
diff --git a/ui/src/app/entity/entity-type-select.scss b/ui/src/app/entity/entity-type-select.scss
index 738f0c7..b9a5c8a 100644
--- a/ui/src/app/entity/entity-type-select.scss
+++ b/ui/src/app/entity/entity-type-select.scss
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 /*
 md-select.tb-entity-type-select {
 }
diff --git a/ui/src/app/entity-view/entity-view.controller.js b/ui/src/app/entity-view/entity-view.controller.js
index 6bead36..1cdc35c 100644
--- a/ui/src/app/entity-view/entity-view.controller.js
+++ b/ui/src/app/entity-view/entity-view.controller.js
@@ -140,6 +140,18 @@ export function EntityViewController($rootScope, userService, entityViewService,
                 return {"topIndex": vm.topIndex};
             };
 
+            entityViewActionsList.push({
+                onAction: function ($event, item) {
+                    makePublic($event, item);
+                },
+                name: function() { return $translate.instant('action.share') },
+                details: function() { return $translate.instant('entity-view.make-public') },
+                icon: "share",
+                isEnabled: function(entityView) {
+                    return entityView && (!entityView.customerId || entityView.customerId.id === types.id.nullUid);
+                }
+            });
+
             entityViewActionsList.push(
                 {
                     onAction: function ($event, item) {
diff --git a/ui/src/app/locale/locale.constant-en_US.json b/ui/src/app/locale/locale.constant-en_US.json
index eba880d..f8b4b3d 100644
--- a/ui/src/app/locale/locale.constant-en_US.json
+++ b/ui/src/app/locale/locale.constant-en_US.json
@@ -844,6 +844,7 @@
         "unable-entity-view-device-alias-text": "Device alias '{{entityViewAlias}}' can't be deleted as it used by the following widget(s):<br/>{{widgetsList}}",
         "select-entity-view": "Select entity view",
         "make-public": "Make entity view public",
+        "make-private": "Make entity view private",
         "start-date": "Start date",
         "start-ts": "Start time",
         "end-date": "End date",
@@ -861,7 +862,11 @@
         "attributes-propagation": "Attributes propagation",
         "attributes-propagation-hint": "Entity View will automatically copy specified attributes from Target Entity each time you save or update this entity view. For performance reasons target entity attributes are not propagated to entity view on each attribute change. You can enable automatic propagation by configuring \"copy to view\" rule node in your rule chain and linking \"Post attributes\" and \"Attributes Updated\" messages to the new rule node.",
         "timeseries-data": "Timeseries data",
-        "timeseries-data-hint": "Configure timeseries data keys of the target entity that will be accessible to the entity view. This timeseries data is read-only."
+        "timeseries-data-hint": "Configure timeseries data keys of the target entity that will be accessible to the entity view. This timeseries data is read-only.",
+        "make-public-entity-view-title": "Are you sure you want to make the entity view '{{entityViewName}}' public?",
+        "make-public-entity-view-text": "After the confirmation the entity view and all its data will be made public and accessible by others.",
+        "make-private-entity-view-title": "Are you sure you want to make the entity view '{{entityViewName}}' private?",
+        "make-private-entity-view-text": "After the confirmation the entity view and all its data will be made private and won't be accessible by others."
     },
     "event": {
         "event-type": "Event type",