Commit aa7deb2f3e4efac1933b65a6e84df0918e950cd1

Authored by Volodymyr Babak
1 parent ced63c4e

Make entity view public again:

@@ -333,4 +333,28 @@ public class EntityViewController extends BaseController { @@ -333,4 +333,28 @@ public class EntityViewController extends BaseController {
333 throw handleException(e); 333 throw handleException(e);
334 } 334 }
335 } 335 }
  336 +
  337 + @PreAuthorize("hasAuthority('TENANT_ADMIN')")
  338 + @RequestMapping(value = "/customer/public/entityView/{entityViewId}", method = RequestMethod.POST)
  339 + @ResponseBody
  340 + public EntityView assignEntityViewToPublicCustomer(@PathVariable(ENTITY_VIEW_ID) String strEntityViewId) throws ThingsboardException {
  341 + checkParameter(ENTITY_VIEW_ID, strEntityViewId);
  342 + try {
  343 + EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
  344 + EntityView entityView = checkEntityViewId(entityViewId);
  345 + Customer publicCustomer = customerService.findOrCreatePublicCustomer(entityView.getTenantId());
  346 + EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToCustomer(getCurrentUser().getTenantId(), entityViewId, publicCustomer.getId()));
  347 +
  348 + logEntityAction(entityViewId, savedEntityView,
  349 + savedEntityView.getCustomerId(),
  350 + ActionType.ASSIGNED_TO_CUSTOMER, null, strEntityViewId, publicCustomer.getId().toString(), publicCustomer.getName());
  351 +
  352 + return savedEntityView;
  353 + } catch (Exception e) {
  354 + logEntityAction(emptyId(EntityType.ENTITY_VIEW), null,
  355 + null,
  356 + ActionType.ASSIGNED_TO_CUSTOMER, e, strEntityViewId);
  357 + throw handleException(e);
  358 + }
  359 + }
336 } 360 }
@@ -34,7 +34,8 @@ function EntityViewService($http, $q, $window, userService, attributeService, cu @@ -34,7 +34,8 @@ function EntityViewService($http, $q, $window, userService, attributeService, cu
34 subscribeForEntityViewAttributes: subscribeForEntityViewAttributes, 34 subscribeForEntityViewAttributes: subscribeForEntityViewAttributes,
35 unsubscribeForEntityViewAttributes: unsubscribeForEntityViewAttributes, 35 unsubscribeForEntityViewAttributes: unsubscribeForEntityViewAttributes,
36 findByQuery: findByQuery, 36 findByQuery: findByQuery,
37 - getEntityViewTypes: getEntityViewTypes 37 + getEntityViewTypes: getEntityViewTypes,
  38 + makeEntityViewPublic: makeEntityViewPublic
38 } 39 }
39 40
40 return service; 41 return service;
@@ -208,4 +209,16 @@ function EntityViewService($http, $q, $window, userService, attributeService, cu @@ -208,4 +209,16 @@ function EntityViewService($http, $q, $window, userService, attributeService, cu
208 return deferred.promise; 209 return deferred.promise;
209 } 210 }
210 211
  212 + function makeEntityViewPublic(entityViewId) {
  213 + var deferred = $q.defer();
  214 + var url = '/api/customer/public/entityView/' + entityViewId;
  215 + $http.post(url, null).then(function success(response) {
  216 + deferred.resolve(response.data);
  217 + }, function fail() {
  218 + deferred.reject();
  219 + });
  220 + return deferred.promise;
  221 + }
  222 +
  223 +
211 } 224 }
@@ -140,6 +140,18 @@ export function EntityViewController($rootScope, userService, entityViewService, @@ -140,6 +140,18 @@ export function EntityViewController($rootScope, userService, entityViewService,
140 return {"topIndex": vm.topIndex}; 140 return {"topIndex": vm.topIndex};
141 }; 141 };
142 142
  143 + entityViewActionsList.push({
  144 + onAction: function ($event, item) {
  145 + makePublic($event, item);
  146 + },
  147 + name: function() { return $translate.instant('action.share') },
  148 + details: function() { return $translate.instant('entity-view.make-public') },
  149 + icon: "share",
  150 + isEnabled: function(entityView) {
  151 + return entityView && (!entityView.customerId || entityView.customerId.id === types.id.nullUid);
  152 + }
  153 + });
  154 +
143 entityViewActionsList.push( 155 entityViewActionsList.push(
144 { 156 {
145 onAction: function ($event, item) { 157 onAction: function ($event, item) {
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
  16 +
16 /* 17 /*
17 .tb-entity-list { 18 .tb-entity-list {
18 #entity_list_chips { 19 #entity_list_chips {
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
  16 +
16 /* 17 /*
17 .tb-entity-select { 18 .tb-entity-select {
18 } 19 }
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
  16 +
16 /* 17 /*
17 .tb-entity-subtype-list { 18 .tb-entity-subtype-list {
18 #entity_subtype_list_chips { 19 #entity_subtype_list_chips {
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
  16 +
16 /* 17 /*
17 .tb-entity-type-list { 18 .tb-entity-type-list {
18 #entity_type_list_chips { 19 #entity_type_list_chips {
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
  16 +
16 /* 17 /*
17 md-select.tb-entity-type-select { 18 md-select.tb-entity-type-select {
18 } 19 }
@@ -844,6 +844,7 @@ @@ -844,6 +844,7 @@
844 "unable-entity-view-device-alias-text": "Device alias '{{entityViewAlias}}' can't be deleted as it used by the following widget(s):<br/>{{widgetsList}}", 844 "unable-entity-view-device-alias-text": "Device alias '{{entityViewAlias}}' can't be deleted as it used by the following widget(s):<br/>{{widgetsList}}",
845 "select-entity-view": "Select entity view", 845 "select-entity-view": "Select entity view",
846 "make-public": "Make entity view public", 846 "make-public": "Make entity view public",
  847 + "make-private": "Make entity view private",
847 "start-date": "Start date", 848 "start-date": "Start date",
848 "start-ts": "Start time", 849 "start-ts": "Start time",
849 "end-date": "End date", 850 "end-date": "End date",
@@ -861,7 +862,11 @@ @@ -861,7 +862,11 @@
861 "attributes-propagation": "Attributes propagation", 862 "attributes-propagation": "Attributes propagation",
862 "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.", 863 "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.",
863 "timeseries-data": "Timeseries data", 864 "timeseries-data": "Timeseries data",
864 - "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." 865 + "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.",
  866 + "make-public-entity-view-title": "Are you sure you want to make the entity view '{{entityViewName}}' public?",
  867 + "make-public-entity-view-text": "After the confirmation the entity view and all its data will be made public and accessible by others.",
  868 + "make-private-entity-view-title": "Are you sure you want to make the entity view '{{entityViewName}}' private?",
  869 + "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."
865 }, 870 },
866 "event": { 871 "event": {
867 "event-type": "Event type", 872 "event-type": "Event type",