Skip to content

Commit

Permalink
fix: prevent creation of schemas in readonly mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fstaudt committed Jun 14, 2019
1 parent bf3844a commit f96b864
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docker/run.sh
Expand Up @@ -73,7 +73,7 @@ var clusters = [
$GLOBAL_SETTING
$TRANSITIVE_SETTING
$DELETION_SETTING
$READONLY_SETTTING
$READONLY_SETTING
}
]
EOF
Expand Down
1 change: 1 addition & 0 deletions src/schema-registry/home/home.controller.js
Expand Up @@ -3,6 +3,7 @@ var angularAPP = angular.module('angularAPP');

var HomeCtrl = function ($log, SchemaRegistryFactory, toastFactory, $scope, env) {
$log.info("Starting schema-registry controller - home");
$scope.readonlyMode = env.readonlyMode();
toastFactory.hideToast();

$scope.$watch(function () {
Expand Down
2 changes: 1 addition & 1 deletion src/schema-registry/home/home.html
Expand Up @@ -2,7 +2,7 @@
<div class="row-fluid">
<div >
<p> Welcome to the <b>schema registry ui</b></p><br/>
<p> select a schema or <a ng-href="#/cluster/{{cluster}}/schema/new">create a new one</a></p><br/>
<p> select a schema<span ng-hide="readonlyMode"> or <a ng-href="#/cluster/{{cluster}}/schema/new">create a new one</a></span></p><br/>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions src/schema-registry/list/list.controller.js
Expand Up @@ -4,6 +4,7 @@ var angularAPP = angular.module('angularAPP');
var SubjectListCtrl = function ($scope, $rootScope, $log, $mdMedia, SchemaRegistryFactory, env) {

$log.info("Starting schema-registry controller : list ( initializing subject cache )");
$scope.readonlyMode = env.readonlyMode();

function addCompatibilityValue() {
angular.forEach($rootScope.allSchemas, function (schema) {
Expand Down Expand Up @@ -38,6 +39,7 @@ var SubjectListCtrl = function ($scope, $rootScope, $log, $mdMedia, SchemaRegist
return env.getSelectedCluster().NAME;
}, function (a) {
$scope.cluster = env.getSelectedCluster().NAME;
$scope.readonlyMode = env.readonlyMode();
loadCache(); //When cluster change, reload the list
}, true);
/**
Expand Down
2 changes: 1 addition & 1 deletion src/schema-registry/list/list.html
Expand Up @@ -5,7 +5,7 @@ <h3>
<span>{{allSchemas.length}} Schemas</span>
</h3>
<span flex></span>
<a md-ink-ripple ng-show="true" ng-href="#/cluster/{{cluster}}/schema/new"
<a md-ink-ripple ng-hide="readonlyMode" ng-href="#/cluster/{{cluster}}/schema/new"
class="md-raised md-primary md-button md-ink-ripple blue"
type="button"
aria-label="new connector">New</a>
Expand Down
10 changes: 9 additions & 1 deletion src/schema-registry/new/new.controller.js
Expand Up @@ -59,6 +59,13 @@ var NewSubjectCtrl = function ($scope, $route, $rootScope, $http, $log, $q, $loc
var primitiveTypes = ["null", "boolean", "int", "long", "float", "double", "bytes", "string"];

function testCompatibility(subject, newAvroString) {
if (env.readonlyMode()) {
var deferred = $q.defer();
$scope.showSimpleToastToTop("Creation is not allowed in readonly mode");
deferred.resolve("readonly");
return deferred.promise;
}

$scope.notValidType = false;

if (newAvroString === "null") {
Expand Down Expand Up @@ -271,13 +278,14 @@ var NewSubjectCtrl = function ($scope, $route, $rootScope, $http, $log, $q, $loc
var subject = $scope.text;
testCompatibility(subject, $scope.newAvroString).then(
function success(response) {
// no-subject-name | not-json | new-schema | compatible | non-compatible | failure
// no-subject-name | not-json | new-schema | compatible | non-compatible | failure | readonly
switch (response) {
case "no-subject-name":
case "not-json":
case "not-valid-type":
case "failure":
case "non-compatible":
case "readonly":
$log.debug("registerNewSchema - cannot do anything more with [ " + response + " ]");
break;
case 'new-schema':
Expand Down

0 comments on commit f96b864

Please sign in to comment.