CapabilityHelper.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. /**
  3.  * Licensed Materials - Property of IBM
  4.  * IBM Cognos Products: Cognos Analytics
  5.  * Copyright IBM Corp. 2015, 2016
  6.  * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7.  */
  8. define(['underscore'], function (_) {
  9. 'use strict'; //NOSONAR: meant to be strict
  10. var _singletonInstance = null;
  11. var CapabilityHelper = function CapabilityHelper() {
  12. if (CapabilityHelper.prototype._singletonInstance) {
  13. return CapabilityHelper.prototype._singletonInstance;
  14. }
  15. };
  16. CapabilityHelper.prototype.checkCapabilities = function (capabilityName, glassContext) {
  17. if (glassContext) {
  18. return _.find(glassContext.services.userProfile.capabilities, function (capability) {
  19. return capability === capabilityName;
  20. });
  21. } else {
  22. return _.find(this.glassContext.services.userProfile.capabilities, function (capability) {
  23. return capability === capabilityName;
  24. });
  25. }
  26. };
  27. var _static = {
  28. getInstance: function getInstance() {
  29. if (!_singletonInstance) {
  30. _singletonInstance = new CapabilityHelper();
  31. }
  32. return _singletonInstance;
  33. }
  34. };
  35. return _static.getInstance();
  36. });