bastion 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 215e758692928b45be50032619813c27e60d4f9a
4
- data.tar.gz: f94dde9b9f3a7c2b8f23f06d9d1535576460779c
3
+ metadata.gz: 2fcf73544fbe6e9a9e68742306223e6f36b82882
4
+ data.tar.gz: f3fdd0f88aee4adcdacfcc8c7c0bf7bc260694c6
5
5
  SHA512:
6
- metadata.gz: 1b1b70043f1d2dde8ef1f67fd73ef0a5f773fd2ec0787cb1cab5eccf41be2586e08fa88ee6703277afd5c0a517c9394732bb1325da531db3942bbc5a516c5e89
7
- data.tar.gz: 921f02922c74e79c88f84308195a6f01612a27d8faec0860bd2ae75d00b4842ec89cdfd35d0d25fd388b29dae549ebcf9c59b43ede36bced14565f8195e31cfd
6
+ metadata.gz: fa572a934c298e2a979aff62f00f27e12cd53098fcbe9f163542bee38de07cc63ef0cba468c941b022c4d2aff6d111198e6d63fa74311197e62cc985f687de27
7
+ data.tar.gz: 778313790e3ddd06bd55b1deb0d5ba2ea35627152235ee2f6787b165945e12ce8eeba1a76b6ce9126cd2e6da5eeea927f2d2b563ec60cb69cf3596f0db606649
@@ -25,4 +25,5 @@ BASTION_MODULES = [
25
25
  'Bastion.auth',
26
26
  'Bastion.menu',
27
27
  'Bastion.i18n',
28
+ 'Bastion.features'
28
29
  ];
@@ -43,4 +43,7 @@
43
43
  //= require "bastion/utils/utils.module"
44
44
  //= require_tree "./utils"
45
45
 
46
+ //= require "bastion/features/features.module"
47
+ //= require_tree "./features"
48
+
46
49
  //= require "bastion/bastion-bootstrap"
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Copyright 2014 Red Hat, Inc.
3
+ *
4
+ * This software is licensed to you under the GNU General Public
5
+ * License as published by the Free Software Foundation; either version
6
+ * 2 of the License (GPLv2) or (at your option) any later version.
7
+ * There is NO WARRANTY for this software, express or implied,
8
+ * including the implied warranties of MERCHANTABILITY,
9
+ * NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10
+ * have received a copy of GPLv2 along with this software; if not, see
11
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12
+ **/
13
+
14
+
15
+ (function () {
16
+ 'use strict';
17
+
18
+ /**
19
+ * @ngdoc directive
20
+ * @name Bastion.features.directive:FeatureFlag
21
+ *
22
+ * @description
23
+ * Handles checking if a given feature is enabled within HTML.
24
+ *
25
+ * @example
26
+ * HTML:
27
+ * <button class="btn btn-default"
28
+ * bst-feature-flag="custom_products"
29
+ * ui-sref="products.discovery.scan">
30
+ * <i class="icon-screenshot"></i>
31
+ * {{ "Repo Discovery" | translate }}
32
+ * </button>
33
+ *
34
+ * Routes:
35
+ */
36
+ function bstFeatureFlag(ngIfDirective, FeatureFlag) {
37
+ var ngIf = ngIfDirective[0];
38
+
39
+ return {
40
+ transclude: ngIf.transclude,
41
+ priority: ngIf.priority,
42
+ terminal: ngIf.terminal,
43
+ restrict: ngIf.restrict,
44
+ scope: true,
45
+ link: function (scope, element, attrs) {
46
+ attrs.ngIf = function () {
47
+ return FeatureFlag.featureEnabled(attrs['bstFeatureFlag']);
48
+ };
49
+
50
+ ngIf.link.apply(ngIf, arguments);
51
+ }
52
+ };
53
+ }
54
+
55
+ angular
56
+ .module('Bastion.features')
57
+ .directive('bstFeatureFlag', bstFeatureFlag);
58
+
59
+ bstFeatureFlag.$injector = ['ngIfDirective', 'FeatureFlag'];
60
+
61
+ })();
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright 2014 Red Hat, Inc.
3
+ *
4
+ * This software is licensed to you under the GNU General Public
5
+ * License as published by the Free Software Foundation; either version
6
+ * 2 of the License (GPLv2) or (at your option) any later version.
7
+ * There is NO WARRANTY for this software, express or implied,
8
+ * including the implied warranties of MERCHANTABILITY,
9
+ * NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10
+ * have received a copy of GPLv2 along with this software; if not, see
11
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12
+ **/
13
+
14
+
15
+ (function () {
16
+
17
+ /**
18
+ * @ngdoc service
19
+ * @name Bastion.run:FeatureFlag
20
+ *
21
+ * @description
22
+ * Handles checking if a state is enabled on state change. If the state is disabled, the user
23
+ * is redirected to a 404 page.
24
+ */
25
+ function FeaturesInit($rootScope, $window, FeatureFlag) {
26
+ $rootScope.$on('$stateChangeStart', function (event, toState) {
27
+ if (!FeatureFlag.stateEnabled(toState.name)) {
28
+ $window.location.href = '/404';
29
+ }
30
+ });
31
+ }
32
+
33
+ angular
34
+ .module('Bastion.features')
35
+ .run(FeaturesInit);
36
+
37
+ FeaturesInit.$inject = ['$rootScope', '$window', 'FeatureFlag'];
38
+
39
+ })();
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Copyright 2014 Red Hat, Inc.
3
+ *
4
+ * This software is licensed to you under the GNU General Public
5
+ * License as published by the Free Software Foundation; either version
6
+ * 2 of the License (GPLv2) or (at your option) any later version.
7
+ * There is NO WARRANTY for this software, express or implied,
8
+ * including the implied warranties of MERCHANTABILITY,
9
+ * NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10
+ * have received a copy of GPLv2 along with this software; if not, see
11
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12
+ **/
13
+
14
+
15
+ (function () {
16
+
17
+ /**
18
+ * @ngdoc service
19
+ * @name Bastion.features.service:FeatureFlag
20
+ *
21
+ * @description
22
+ * Provides a service for checking whether a given feature or state based on a feature
23
+ * is enabled. States may be added to a features state set via the service (see example).
24
+ *
25
+ * @example
26
+ * Add states:
27
+ * FeatureFlag.addStates('custom_products', ['products.new']);
28
+ *
29
+ * Check feature enabled:
30
+ * FeatureFlag.stateEnabled('custom_products');
31
+ *
32
+ * Check state enabled:
33
+ * FeatureFlag.stateEnabled('products.new');
34
+ *
35
+ */
36
+ function FeatureFlag(Features) {
37
+ var featureFlags = {};
38
+
39
+ angular.forEach(Features, function (enabled, feature) {
40
+ featureFlags[feature] = {states: [], enabled: enabled};
41
+ });
42
+
43
+ /**
44
+ * Returns whether a given feature is enabled or not
45
+ *
46
+ * @param {String} flag Name of a feature flag
47
+ *
48
+ * @returns {Boolean}
49
+ */
50
+ this.featureEnabled = function (flag) {
51
+ return (featureFlags[flag] === undefined) ? true : featureFlags[flag].enabled;
52
+ };
53
+
54
+ /**
55
+ * Returns whether a given state is enabled or not.
56
+ * If a state is defined for multiple flags, returns true if the
57
+ * flag is true for any state that is defined for that flag.
58
+ *
59
+ * @param {String} state ui-router state to check against
60
+ *
61
+ * @returns {Boolean}
62
+ */
63
+ this.stateEnabled = function (state) {
64
+ var enabled = [];
65
+
66
+ angular.forEach(featureFlags, function (feature) {
67
+ if (feature.states.indexOf(state) > -1) {
68
+ enabled.push(feature.enabled);
69
+ }
70
+ });
71
+
72
+ return ((enabled.length === 0) ? true : enabled.indexOf(true) > -1);
73
+ };
74
+
75
+ /**
76
+ * Add states to a feature flag
77
+ *
78
+ * @param {String} feature The feature to add states to
79
+ * @param {Array} states The set of states to add to the feature
80
+ *
81
+ * @returns {Object} Returns the service itself, can be chained
82
+ */
83
+ this.addStates = function (feature, states) {
84
+ feature = featureFlags[feature];
85
+
86
+ if (feature === undefined) {
87
+ feature = {states: []};
88
+ } else if (feature.states === undefined) {
89
+ feature.states = [];
90
+ }
91
+
92
+ feature.states = feature.states.concat(states);
93
+
94
+ return this;
95
+ };
96
+ }
97
+
98
+ angular
99
+ .module('Bastion.features')
100
+ .service('FeatureFlag', FeatureFlag);
101
+
102
+ FeatureFlag.$inject = ['Features'];
103
+
104
+ })();
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright 2014 Red Hat, Inc.
3
+ *
4
+ * This software is licensed to you under the GNU General Public
5
+ * License as published by the Free Software Foundation; either version
6
+ * 2 of the License (GPLv2) or (at your option) any later version.
7
+ * There is NO WARRANTY for this software, express or implied,
8
+ * including the implied warranties of MERCHANTABILITY,
9
+ * NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10
+ * have received a copy of GPLv2 along with this software; if not, see
11
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12
+ **/
13
+
14
+
15
+ (function () {
16
+
17
+ angular
18
+ .module('Bastion.features', []);
19
+
20
+ })();
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Copyright 2014 Red Hat, Inc.
3
+ *
4
+ * This software is licensed to you under the GNU General Public
5
+ * License as published by the Free Software Foundation; either version
6
+ * 2 of the License (GPLv2) or (at your option) any later version.
7
+ * There is NO WARRANTY for this software, express or implied,
8
+ * including the implied warranties of MERCHANTABILITY,
9
+ * NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10
+ * have received a copy of GPLv2 along with this software; if not, see
11
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12
+ **/
13
+
14
+
15
+ (function () {
16
+
17
+ /**
18
+ * @ngdoc factory
19
+ * @name Bastion.features.factory:Features
20
+ *
21
+ * @description
22
+ * Wraps the
23
+ */
24
+ function Features($injector) {
25
+ var features;
26
+
27
+ try {
28
+ features = $injector.get('FeatureSettings');
29
+ } catch (e) {
30
+ features = {};
31
+ }
32
+
33
+ return features;
34
+ }
35
+
36
+ angular
37
+ .module('Bastion.features')
38
+ .factory('Features', Features);
39
+
40
+ Features.$inject = ['$injector'];
41
+
42
+ })();
@@ -13,6 +13,9 @@
13
13
  <div class="row nutupane-bar">
14
14
  <div class="col-sm-3">
15
15
  <div class="input-group input-group">
16
+
17
+ <span data-block="search-filter"></span>
18
+
16
19
  <input type="text"
17
20
  class="form-control"
18
21
  placeholder="{{ 'Search...' | translate }}"
@@ -16,6 +16,7 @@
16
16
  <% content_for(:javascripts) do %>
17
17
  <%= javascript_include_tag 'bastion/bastion' %>
18
18
  <script type="text/javascript">
19
+ angular.module('Bastion.features').value('FeatureSettings', angular.fromJson(<%= SETTINGS[:features].nil? ? {} : SETTINGS[:features].to_json.html_safe %>));
19
20
  angular.module('Bastion').value('currentLocale', '<%= I18n.locale %>');
20
21
  angular.module('Bastion').value('CurrentOrganization', "<%= Organization.current.id if Organization.current %>");
21
22
  angular.module('Bastion').value('Permissions', angular.fromJson('<%= User.current.roles.collect { |role| role.permissions }.flatten.to_json.html_safe %>'));
data/grunt/karma.js CHANGED
@@ -30,7 +30,6 @@ module.exports = {
30
30
  basePath + 'vendor/assets/javascripts/bastion/ngUpload/ng-upload.js',
31
31
  basePath + '.tmp/bower_components/angular-mocks/angular-mocks.js',
32
32
 
33
- basePath + 'app/assets/javascripts/bastion/bastion-bootstrap.js',
34
33
  basePath + 'app/assets/javascripts/bastion/bastion.module.js',
35
34
  basePath + 'app/assets/javascripts/bastion/bastion-resource.factory.js',
36
35
  basePath + 'app/assets/javascripts/bastion/i18n/i18n.module.js',
@@ -41,6 +40,8 @@ module.exports = {
41
40
  basePath + 'app/assets/javascripts/bastion/utils/*.js',
42
41
  basePath + 'app/assets/javascripts/bastion/menu/menu.module.js',
43
42
  basePath + 'app/assets/javascripts/bastion/menu/*.js',
43
+ basePath + 'app/assets/javascripts/bastion/features/features.module.js',
44
+ basePath + 'app/assets/javascripts/bastion/features/*.js',
44
45
  basePath + 'app/assets/javascripts/bastion/components/components.module.js',
45
46
  basePath + 'app/assets/javascripts/bastion/components/*.js',
46
47
  basePath + 'app/assets/javascripts/bastion/components/formatters/components-formatters.module.js',
@@ -54,6 +55,8 @@ module.exports = {
54
55
  'app/assets/javascripts/' + pluginName + '/**/*.js',
55
56
  'app/assets/javascripts/' + pluginName + '/**/*.html',
56
57
 
58
+ basePath + 'app/assets/javascripts/bastion/bastion-bootstrap.js',
59
+
57
60
  basePath + 'test/test-mocks.module.js',
58
61
  'test/**/*test.js'
59
62
  ],
@@ -1,3 +1,3 @@
1
1
  module Bastion
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright 2014 Red Hat, Inc.
3
+ *
4
+ * This software is licensed to you under the GNU General Public
5
+ * License as published by the Free Software Foundation; either version
6
+ * 2 of the License (GPLv2) or (at your option) any later version.
7
+ * There is NO WARRANTY for this software, express or implied,
8
+ * including the implied warranties of MERCHANTABILITY,
9
+ * NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10
+ * have received a copy of GPLv2 along with this software; if not, see
11
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12
+ */
13
+
14
+ describe('Directive:bstFeatureFlag', function() {
15
+ var element, scope;
16
+
17
+ beforeEach(module('Bastion.features'));
18
+
19
+ beforeEach(module(function ($provide) {
20
+ $provide.value('FeatureSettings', {'custom_products': false});
21
+ }));
22
+
23
+ beforeEach(inject(function($injector) {
24
+ var compile = $injector.get('$compile');
25
+
26
+ element = angular.element('<div bst-feature-flag="custom_products"><button>New Product</button><span>Test</span></div>');
27
+ scope = $injector.get('$rootScope').$new();
28
+
29
+ compile(element)(scope);
30
+ scope.$digest();
31
+ }));
32
+
33
+ it("should remove the element if the feature is disabled", function () {
34
+ expect(element.find('button').length).toBe(0);
35
+ });
36
+
37
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright 2014 Red Hat, Inc.
3
+ *
4
+ * This software is licensed to you under the GNU General Public
5
+ * License as published by the Free Software Foundation; either version
6
+ * 2 of the License (GPLv2) or (at your option) any later version.
7
+ * There is NO WARRANTY for this software, express or implied,
8
+ * including the implied warranties of MERCHANTABILITY,
9
+ * NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
10
+ * have received a copy of GPLv2 along with this software; if not, see
11
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12
+ */
13
+
14
+ describe('Service:FeatureFlag', function() {
15
+ var FeatureFlag;
16
+
17
+ beforeEach(module('Bastion.features'));
18
+
19
+ beforeEach(module(function ($provide) {
20
+ $provide.value('FeatureSettings', {'custom_products': false});
21
+ }));
22
+
23
+ beforeEach(inject(function($injector) {
24
+ FeatureFlag = $injector.get('FeatureFlag');
25
+ FeatureFlag.addStates('custom_products', ['products', 'products.new']);
26
+ }));
27
+
28
+ it("should allow checking if a feature is enabled", function () {
29
+ expect(FeatureFlag.featureEnabled('custom_products')).toBe(false);
30
+ });
31
+
32
+ it("should default to true if a feature is undefined", function () {
33
+ expect(FeatureFlag.featureEnabled('fake_flag')).toBe(true);
34
+ });
35
+
36
+ it("should allow checking if a state is enabled", function () {
37
+ expect(FeatureFlag.stateEnabled('products')).toBe(false);
38
+ expect(FeatureFlag.stateEnabled('products.fake')).toBe(true);
39
+ });
40
+
41
+ it("should allow adding states to a feature", function () {
42
+ expect(FeatureFlag.addStates('custom_products', ['products.new.form'])).toBe(FeatureFlag);
43
+ expect(FeatureFlag.stateEnabled('products.new.form')).toBe(false);
44
+ });
45
+ });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bastion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katello
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2014-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: angular-rails-templates
@@ -118,6 +118,11 @@ files:
118
118
  - app/assets/javascripts/bastion/components/views/bst-save-control.html
119
119
  - app/assets/javascripts/bastion/components/views/current-tasks.html
120
120
  - app/assets/javascripts/bastion/components/views/path-selector.html
121
+ - app/assets/javascripts/bastion/features/bst-feature-flag.directive.js
122
+ - app/assets/javascripts/bastion/features/feature-flag.run.js
123
+ - app/assets/javascripts/bastion/features/feature-flag.service.js
124
+ - app/assets/javascripts/bastion/features/features.module.js
125
+ - app/assets/javascripts/bastion/features/features.service.js
121
126
  - app/assets/javascripts/bastion/i18n/README
122
127
  - app/assets/javascripts/bastion/i18n/i18n.module.js
123
128
  - app/assets/javascripts/bastion/i18n/katello.pot
@@ -184,6 +189,8 @@ files:
184
189
  - test/components/page-title.service.test.js
185
190
  - test/components/path-selector.directive.test.js
186
191
  - test/components/typeahead-empty.directive.test.js
192
+ - test/features/bst-feature-flag.directive.test.js
193
+ - test/features/feature-flag.service.test.js
187
194
  - test/i18n/translate.service.test.js
188
195
  - test/menu/menu-expander.service.test.js
189
196
  - test/test-mocks.module.js
@@ -380,5 +387,7 @@ test_files:
380
387
  - test/bastion/bastion-resource.factory.test.js
381
388
  - test/i18n/translate.service.test.js
382
389
  - test/auth/authorization.service.test.js
390
+ - test/features/bst-feature-flag.directive.test.js
391
+ - test/features/feature-flag.service.test.js
383
392
  - test/utils/form-utils.service.test.js
384
393
  - test/utils/as.filter.test.js