Skip to content

Commit f83d012

Browse files
cloverheartsAhyoungRyu
authored andcommitted
[ZEPPELIN-1875] permission dialog code is not stable
### What is this PR for? The code for the notification pop-up is not stable. Sometime when response to slow for backend. Then the permission box and the dialogue open together. ### What type of PR is it? Bug Fix , Improvement ### Todos - [x] changed method name (getBlockNotAuthenticatedUserErrorMsg) - [x] permission dialog pop-up change logic. - [x] added check logic for anonymous user in checkIfUserIsAnon method ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-1875 ### How should this be tested? 1. when you do have turn on the shiro and login and click to note permission button. 2. or turn off the shiro. ### Screenshots (if appropriate) ![dialog](https://cloud.githubusercontent.com/assets/10525473/21549451/141cca5c-cda7-11e6-9c4b-94cbf882face.gif) ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: cloverhearts <cloverheartsdev@gmail.com> Closes apache#1821 from cloverhearts/ZEPPELIN-PERMMIT-FIX and squashes the following commits: 3d542f2 [cloverhearts] fixed bug isAnanimous 4248c0b [cloverhearts] refix
1 parent 355387a commit f83d012

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public NotebookRestApi(Notebook notebook, NotebookServer notebookServer, SearchS
9595
@ZeppelinApi
9696
public Response getNotePermissions(@PathParam("noteId") String noteId) throws IOException {
9797

98-
checkIfUserIsAnon(blockNotAuthenticatedUserError());
98+
checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
9999
checkIfUserCanRead(noteId,
100100
"Insufficient privileges you cannot get the list of permissions for this note");
101101
HashMap<String, Set<String>> permissionsMap = new HashMap<>();
@@ -113,8 +113,7 @@ private String ownerPermissionError(Set<String> current, Set<String> allowed) th
113113
"User belongs to: " + current.toString();
114114
}
115115

116-
private String blockNotAuthenticatedUserError() throws IOException {
117-
LOG.info("Anonymous user cannot set any permissions for this note.");
116+
private String getBlockNotAuthenticatedUserErrorMsg() throws IOException {
118117
return "Only authenticated user can set the permission.";
119118
}
120119

@@ -129,7 +128,8 @@ private String blockNotAuthenticatedUserError() throws IOException {
129128
*/
130129
private void checkIfUserIsAnon(String errorMsg) {
131130
boolean isAuthenticated = SecurityUtils.isAuthenticated();
132-
if (!isAuthenticated) {
131+
if (isAuthenticated && SecurityUtils.getPrincipal().equals("anonymous")) {
132+
LOG.info("Anonymous user cannot set any permissions for this note.");
133133
throw new ForbiddenException(errorMsg);
134134
}
135135
}
@@ -196,7 +196,7 @@ public Response putNotePermissions(@PathParam("noteId") String noteId, String re
196196
userAndRoles.add(principal);
197197
userAndRoles.addAll(roles);
198198

199-
checkIfUserIsAnon(blockNotAuthenticatedUserError());
199+
checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
200200
checkIfUserIsOwner(noteId,
201201
ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId)));
202202

zeppelin-web/src/app/notebook/notebook.controller.js

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,25 @@
9292
};
9393

9494
$scope.blockAnonUsers = function() {
95-
var principal = $rootScope.ticket.principal;
96-
if (principal) {
97-
$scope.isAnonymous = principal === 'anonymous' ? true : false;
98-
if ($scope.isAnonymous) {
99-
var zeppelinVersion = $rootScope.zeppelinVersion;
100-
var url = 'https://zeppelin.apache.org/docs/' + zeppelinVersion + '/security/notebook_authorization.html';
101-
var content = 'Only authenticated user can set the permission.' +
102-
'<a data-toggle="tooltip" data-placement="top" title="Learn more" target="_blank" href=' + url + '>' +
103-
'<i class="icon-question" />' +
104-
'</a>';
105-
BootstrapDialog.show({
106-
closable: false,
107-
closeByBackdrop: false,
108-
closeByKeyboard: false,
109-
title: 'No permission',
110-
message: content,
111-
buttons: [{
112-
label: 'Close',
113-
action: function(dialog) {
114-
dialog.close();
115-
}
116-
}]
117-
});
118-
}
119-
}
95+
var zeppelinVersion = $rootScope.zeppelinVersion;
96+
var url = 'https://zeppelin.apache.org/docs/' + zeppelinVersion + '/security/notebook_authorization.html';
97+
var content = 'Only authenticated user can set the permission.' +
98+
'<a data-toggle="tooltip" data-placement="top" title="Learn more" target="_blank" href=' + url + '>' +
99+
'<i class="icon-question" />' +
100+
'</a>';
101+
BootstrapDialog.show({
102+
closable: false,
103+
closeByBackdrop: false,
104+
closeByKeyboard: false,
105+
title: 'No permission',
106+
message: content,
107+
buttons: [{
108+
label: 'Close',
109+
action: function(dialog) {
110+
dialog.close();
111+
}
112+
}]
113+
});
120114
};
121115

122116
/** Init the new controller */
@@ -782,15 +776,20 @@
782776
};
783777

784778
$scope.togglePermissions = function() {
785-
$scope.blockAnonUsers();
786-
if ($scope.showPermissions) {
787-
$scope.closePermissions();
788-
angular.element('#selectOwners').select2({});
789-
angular.element('#selectReaders').select2({});
790-
angular.element('#selectWriters').select2({});
779+
var principal = $rootScope.ticket.principal;
780+
$scope.isAnonymous = principal === 'anonymous' ? true : false;
781+
if (!!principal && $scope.isAnonymous) {
782+
$scope.blockAnonUsers();
791783
} else {
792-
$scope.openPermissions();
793-
$scope.closeSetting();
784+
if ($scope.showPermissions) {
785+
$scope.closePermissions();
786+
angular.element('#selectOwners').select2({});
787+
angular.element('#selectReaders').select2({});
788+
angular.element('#selectWriters').select2({});
789+
} else {
790+
$scope.openPermissions();
791+
$scope.closeSetting();
792+
}
794793
}
795794
};
796795

0 commit comments

Comments
 (0)