Fixed some minor bugs within the permission editor

canary
WolverinDEV 2019-11-24 13:59:07 +01:00
parent 2f7b52d3f8
commit c7fc058135
5 changed files with 134 additions and 50 deletions

View File

@ -200,6 +200,12 @@ class GroupManager extends connection.AbstractCommandHandler {
req.promise.resolved([]); req.promise.resolved([]);
else else
req.promise.rejected(error); req.promise.rejected(error);
}).then(() => {
//No notify handler
setTimeout(() => {
if(this.requests_group_permissions.remove(req))
req.promise.rejected(tr("no response"));
}, 1000);
}); });
return req.promise; return req.promise;
} }

View File

@ -562,6 +562,9 @@ class PermissionManager extends connection.AbstractCommandHandler {
case "notifyclientpermlist": case "notifyclientpermlist":
this.onClientPermList(command.arguments); this.onClientPermList(command.arguments);
return true; return true;
case "notifyclientchannelpermlist":
this.onChannelClientPermList(command.arguments);
return true;
case "notifyplaylistpermlist": case "notifyplaylistpermlist":
this.onPlaylistPermList(command.arguments); this.onPlaylistPermList(command.arguments);
return true; return true;
@ -698,22 +701,6 @@ class PermissionManager extends connection.AbstractCommandHandler {
this.needed_permission_change_listener[key] = array.length > 0 ? array : undefined; this.needed_permission_change_listener[key] = array.length > 0 ? array : undefined;
} }
private onChannelPermList(json) {
let channelId: number = parseInt(json[0]["cid"]);
let permissions = PermissionManager.parse_permission_bulk(json, this.handle.permissions);
log.debug(LogCategory.PERMISSIONS, tr("Got channel permissions for channel %o"), channelId);
for(let element of this.requests_channel_permissions) {
if(element.channel_id == channelId) {
for(let l of element.callback_success)
l(permissions);
this.requests_channel_permissions.remove(element);
return;
}
}
log.debug(LogCategory.PERMISSIONS, tr("Missing channel permission handle for requested channel id %o"), channelId);
}
resolveInfo?(key: number | string | PermissionType) : PermissionInfo { resolveInfo?(key: number | string | PermissionType) : PermissionInfo {
for(let perm of this.permissionList) for(let perm of this.permissionList)
if(perm.id == key || perm.name == key) if(perm.id == key || perm.name == key)
@ -723,24 +710,85 @@ class PermissionManager extends connection.AbstractCommandHandler {
requestChannelPermissions(channelId: number) : Promise<PermissionValue[]> { requestChannelPermissions(channelId: number) : Promise<PermissionValue[]> {
return new Promise<PermissionValue[]>((resolve, reject) => { return new Promise<PermissionValue[]>((resolve, reject) => {
let request: ChannelPermissionRequest; let request: ChannelPermissionRequest;
for(let element of this.requests_channel_permissions) for(let element of this.requests_channel_permissions)
if(element.requested + 1000 < Date.now() && element.channel_id == channelId) { if(element.requested + 1000 < Date.now() && element.channel_id == channelId) {
request = element; request = element;
break; break;
} }
if(!request) { if(!request) {
request = new ChannelPermissionRequest(); request = new ChannelPermissionRequest();
request.requested = Date.now(); request.requested = Date.now();
request.channel_id = channelId; request.channel_id = channelId;
this.handle.serverConnection.send_command("channelpermlist", {"cid": channelId}); this.handle.serverConnection.send_command("channelpermlist", {"cid": channelId}).catch(error => {
this.requests_channel_permissions.push(request); this.requests_channel_permissions.remove(request);
}
request.callback_error.push(reject); if(error instanceof CommandResult) {
request.callback_success.push(resolve); if(error.id == ErrorID.EMPTY_RESULT) {
request.callback_success.forEach(e => e([]));
return;
}
}
request.callback_error.forEach(e => e(error));
}).then(() => {
//Error handler if we've not received an notify
setTimeout(() => {
if(this.requests_channel_permissions.remove(request)) {
request.callback_error.forEach(e => e(tr("missing notify")));
}
}, 1000);
});
this.requests_channel_permissions.push(request);
}
request.callback_error.push(reject);
request.callback_success.push(resolve);
}); });
} }
private onChannelPermList(json) {
let channelId: number = parseInt(json[0]["cid"]);
let permissions = PermissionManager.parse_permission_bulk(json, this.handle.permissions);
log.debug(LogCategory.PERMISSIONS, tr("Got channel permissions for channel %o"), channelId);
for(let element of this.requests_channel_permissions) {
if(element.channel_id == channelId) {
for(let l of element.callback_success)
l(permissions);
this.requests_channel_permissions.remove(element);
return;
}
}
log.debug(LogCategory.PERMISSIONS, tr("Missing channel permission handle for requested channel id %o"), channelId);
}
requestClientPermissions(client_id: number) : Promise<PermissionValue[]> {
for(let request of this.requests_client_permissions)
if(request.client_id == client_id && request.promise.time() + 1000 > Date.now())
return request.promise;
let request: TeaPermissionRequest = {} as any;
request.client_id = client_id;
request.promise = new LaterPromise<PermissionValue[]>();
this.handle.serverConnection.send_command("clientpermlist", {cldbid: client_id}).catch(error => {
this.requests_client_permissions.remove(request);
if(error instanceof CommandResult && error.id == ErrorID.EMPTY_RESULT)
request.promise.resolved([]);
else
request.promise.rejected(error);
}).then(() => {
//Error handler if we've not received an notify
setTimeout(() => {
if(this.requests_client_permissions.remove(request)) {
request.promise.rejected(tr("missing notify"));
}
}, 1000);
});
this.requests_client_permissions.push(request);
return request.promise;
}
private onClientPermList(json: any[]) { private onClientPermList(json: any[]) {
let client = parseInt(json[0]["cldbid"]); let client = parseInt(json[0]["cldbid"]);
let permissions = PermissionManager.parse_permission_bulk(json, this); let permissions = PermissionManager.parse_permission_bulk(json, this);
@ -752,26 +800,6 @@ class PermissionManager extends connection.AbstractCommandHandler {
} }
} }
requestClientPermissions(client_id: number) : Promise<PermissionValue[]> {
for(let request of this.requests_client_permissions)
if(request.client_id == client_id && request.promise.time() + 1000 > Date.now())
return request.promise;
let request: TeaPermissionRequest = {} as any;
request.client_id = client_id;
request.promise = new LaterPromise<PermissionValue[]>();
this.handle.serverConnection.send_command("clientpermlist", {cldbid: client_id}).catch(error => {
if(error instanceof CommandResult && error.id == ErrorID.EMPTY_RESULT)
request.promise.resolved([]);
else
request.promise.rejected(error);
});
this.requests_client_permissions.push(request);
return request.promise;
}
requestClientChannelPermissions(client_id: number, channel_id: number) : Promise<PermissionValue[]> { requestClientChannelPermissions(client_id: number, channel_id: number) : Promise<PermissionValue[]> {
for(let request of this.requests_client_channel_permissions) for(let request of this.requests_client_channel_permissions)
if(request.client_id == client_id && request.channel_id == channel_id && request.promise.time() + 1000 > Date.now()) if(request.client_id == client_id && request.channel_id == channel_id && request.promise.time() + 1000 > Date.now())
@ -783,16 +811,37 @@ class PermissionManager extends connection.AbstractCommandHandler {
request.promise = new LaterPromise<PermissionValue[]>(); request.promise = new LaterPromise<PermissionValue[]>();
this.handle.serverConnection.send_command("channelclientpermlist", {cldbid: client_id, cid: channel_id}).catch(error => { this.handle.serverConnection.send_command("channelclientpermlist", {cldbid: client_id, cid: channel_id}).catch(error => {
this.requests_client_channel_permissions.remove(request);
if(error instanceof CommandResult && error.id == ErrorID.EMPTY_RESULT) if(error instanceof CommandResult && error.id == ErrorID.EMPTY_RESULT)
request.promise.resolved([]); request.promise.resolved([]);
else else
request.promise.rejected(error); request.promise.rejected(error);
}).then(() => {
//Error handler if we've not received an notify
setTimeout(() => {
if(this.requests_client_channel_permissions.remove(request)) {
request.promise.rejected(tr("missing notify"));
}
}, 1000);
}); });
this.requests_client_channel_permissions.push(request); this.requests_client_channel_permissions.push(request);
return request.promise; return request.promise;
} }
private onChannelClientPermList(json: any[]) {
let client_id = parseInt(json[0]["cldbid"]);
let channel_id = parseInt(json[0]["cid"]);
let permissions = PermissionManager.parse_permission_bulk(json, this);
for(let req of this.requests_client_channel_permissions.slice(0)) {
if(req.client_id == client_id && req.channel_id == channel_id) {
this.requests_client_channel_permissions.remove(req);
req.promise.resolved(permissions);
}
}
}
private onPlaylistPermList(json: any[]) { private onPlaylistPermList(json: any[]) {
@ -816,6 +865,7 @@ class PermissionManager extends connection.AbstractCommandHandler {
request.promise = new LaterPromise<PermissionValue[]>(); request.promise = new LaterPromise<PermissionValue[]>();
this.handle.serverConnection.send_command("playlistpermlist", {playlist_id: playlist_id}).catch(error => { this.handle.serverConnection.send_command("playlistpermlist", {playlist_id: playlist_id}).catch(error => {
this.requests_playlist_permissions.remove(request);
if(error instanceof CommandResult && error.id == ErrorID.EMPTY_RESULT) if(error instanceof CommandResult && error.id == ErrorID.EMPTY_RESULT)
request.promise.resolved([]); request.promise.resolved([]);
else else

View File

@ -0,0 +1,21 @@
/// <reference path="../../ui/elements/modal.ts" />
/// <reference path="../../ConnectionHandler.ts" />
/// <reference path="../../proto.ts" />
namespace Modals {
export function openModalNewcomer() {
let modal = createModal({
header: tr("Select a key"),
body: () => $("#tmpl_newcomer").renderTag().children(),
footer: null,
width: "",
closeable: false
});
modal.open();
}
}

View File

@ -620,6 +620,8 @@ namespace pe {
private mode_container_error_permission: JQuery; private mode_container_error_permission: JQuery;
private mode_container_unset: JQuery; private mode_container_unset: JQuery;
private icon_shown: boolean;
private filter_input: JQuery; private filter_input: JQuery;
private filter_grant: JQuery; private filter_grant: JQuery;
@ -684,7 +686,7 @@ namespace pe {
} }
private update_icon() { private update_icon() {
const permission = this.permission_map.find(e => e && e.permission.name === "i_icon_id"); const permission = this.icon_shown ? this.permission_map.find(e => e && e.permission.name === "i_icon_id") : undefined;
const icon_id = permission ? permission.get_value() : 0; const icon_id = permission ? permission.get_value() : 0;
const icon_node = this.container.find(".container-icon-select .icon-preview"); const icon_node = this.container.find(".container-icon-select .icon-preview");
@ -895,6 +897,10 @@ namespace pe {
this.mode_container_permissions.css('display', mode == Modals.PermissionEditorMode.VISIBLE ? 'flex' : 'none'); this.mode_container_permissions.css('display', mode == Modals.PermissionEditorMode.VISIBLE ? 'flex' : 'none');
this.mode_container_error_permission.css('display', mode == Modals.PermissionEditorMode.NO_PERMISSION ? 'flex' : 'none'); this.mode_container_error_permission.css('display', mode == Modals.PermissionEditorMode.NO_PERMISSION ? 'flex' : 'none');
this.mode_container_unset.css('display', mode == Modals.PermissionEditorMode.UNSET ? 'block' : 'none'); this.mode_container_unset.css('display', mode == Modals.PermissionEditorMode.UNSET ? 'block' : 'none');
if(this.icon_shown != (mode == Modals.PermissionEditorMode.VISIBLE)) {
this.icon_shown = mode == Modals.PermissionEditorMode.VISIBLE;
this.update_icon();
}
} }
trigger_change(permission: PermissionInfo, value?: Modals.PermissionEditor.PermissionValue, update_icon?: boolean) : Promise<void> { trigger_change(permission: PermissionInfo, value?: Modals.PermissionEditor.PermissionValue, update_icon?: boolean) : Promise<void> {

View File

@ -570,6 +570,7 @@ namespace Modals {
if(!current_channel) return; if(!current_channel) return;
connection.permissions.requestChannelPermissions(current_channel.channelId).then(result => editor.set_permissions(result)).catch(error => { connection.permissions.requestChannelPermissions(current_channel.channelId).then(result => editor.set_permissions(result)).catch(error => {
editor.set_permissions([]);
console.log(error); //TODO handling? console.log(error); //TODO handling?
}); });
}); });