diff --git a/shared/js/permission/GroupManager.ts b/shared/js/permission/GroupManager.ts index 236c4abe..c781f468 100644 --- a/shared/js/permission/GroupManager.ts +++ b/shared/js/permission/GroupManager.ts @@ -200,6 +200,12 @@ class GroupManager extends connection.AbstractCommandHandler { req.promise.resolved([]); else 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; } diff --git a/shared/js/permission/PermissionManager.ts b/shared/js/permission/PermissionManager.ts index 8e3fc690..916e1a95 100644 --- a/shared/js/permission/PermissionManager.ts +++ b/shared/js/permission/PermissionManager.ts @@ -562,6 +562,9 @@ class PermissionManager extends connection.AbstractCommandHandler { case "notifyclientpermlist": this.onClientPermList(command.arguments); return true; + case "notifyclientchannelpermlist": + this.onChannelClientPermList(command.arguments); + return true; case "notifyplaylistpermlist": this.onPlaylistPermList(command.arguments); return true; @@ -698,22 +701,6 @@ class PermissionManager extends connection.AbstractCommandHandler { 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 { for(let perm of this.permissionList) if(perm.id == key || perm.name == key) @@ -723,24 +710,85 @@ class PermissionManager extends connection.AbstractCommandHandler { requestChannelPermissions(channelId: number) : Promise { return new Promise((resolve, reject) => { - let request: ChannelPermissionRequest; - for(let element of this.requests_channel_permissions) - if(element.requested + 1000 < Date.now() && element.channel_id == channelId) { + let request: ChannelPermissionRequest; + for(let element of this.requests_channel_permissions) + if(element.requested + 1000 < Date.now() && element.channel_id == channelId) { request = element; break; - } - if(!request) { - request = new ChannelPermissionRequest(); - request.requested = Date.now(); - request.channel_id = channelId; - this.handle.serverConnection.send_command("channelpermlist", {"cid": channelId}); - this.requests_channel_permissions.push(request); - } - request.callback_error.push(reject); - request.callback_success.push(resolve); + } + if(!request) { + request = new ChannelPermissionRequest(); + request.requested = Date.now(); + request.channel_id = channelId; + this.handle.serverConnection.send_command("channelpermlist", {"cid": channelId}).catch(error => { + this.requests_channel_permissions.remove(request); + + if(error instanceof CommandResult) { + 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 { + 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(); + + 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[]) { let client = parseInt(json[0]["cldbid"]); let permissions = PermissionManager.parse_permission_bulk(json, this); @@ -752,26 +800,6 @@ class PermissionManager extends connection.AbstractCommandHandler { } } - requestClientPermissions(client_id: number) : Promise { - 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(); - - 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 { 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()) @@ -783,16 +811,37 @@ class PermissionManager extends connection.AbstractCommandHandler { request.promise = new LaterPromise(); 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) request.promise.resolved([]); else 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); 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[]) { @@ -816,6 +865,7 @@ class PermissionManager extends connection.AbstractCommandHandler { request.promise = new LaterPromise(); 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) request.promise.resolved([]); else diff --git a/shared/js/ui/modal/ModalNewcomer.ts b/shared/js/ui/modal/ModalNewcomer.ts new file mode 100644 index 00000000..c356b68b --- /dev/null +++ b/shared/js/ui/modal/ModalNewcomer.ts @@ -0,0 +1,21 @@ +/// +/// +/// + +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(); + + } +} \ No newline at end of file diff --git a/shared/js/ui/modal/permission/HTMLPermissionEditor.ts b/shared/js/ui/modal/permission/HTMLPermissionEditor.ts index 9e380abd..bf3692ee 100644 --- a/shared/js/ui/modal/permission/HTMLPermissionEditor.ts +++ b/shared/js/ui/modal/permission/HTMLPermissionEditor.ts @@ -620,6 +620,8 @@ namespace pe { private mode_container_error_permission: JQuery; private mode_container_unset: JQuery; + private icon_shown: boolean; + private filter_input: JQuery; private filter_grant: JQuery; @@ -684,7 +686,7 @@ namespace pe { } 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_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_error_permission.css('display', mode == Modals.PermissionEditorMode.NO_PERMISSION ? 'flex' : '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 { diff --git a/shared/js/ui/modal/permission/ModalPermissionEdit.ts b/shared/js/ui/modal/permission/ModalPermissionEdit.ts index 31b37618..71b85b1e 100644 --- a/shared/js/ui/modal/permission/ModalPermissionEdit.ts +++ b/shared/js/ui/modal/permission/ModalPermissionEdit.ts @@ -570,6 +570,7 @@ namespace Modals { if(!current_channel) return; connection.permissions.requestChannelPermissions(current_channel.channelId).then(result => editor.set_permissions(result)).catch(error => { + editor.set_permissions([]); console.log(error); //TODO handling? }); });