wrap capabilities check to avoid errors for out of sync clients

This commit is contained in:
j 2017-02-17 19:25:20 +01:00
parent ebea3b8e11
commit dceee58638
3 changed files with 33 additions and 28 deletions

View file

@ -6,9 +6,9 @@ pandora.ui.allItems = function(section) {
section = section || pandora.user.ui.section; section = section || pandora.user.ui.section;
var canAddItems = !pandora.site.itemRequiresVideo && pandora.site.capabilities.canAddItems[pandora.user.level], var canAddItems = !pandora.site.itemRequiresVideo && pandora.hasCapability('canAddItems'),
canUploadVideo = pandora.site.capabilities.canAddItems[pandora.user.level], canUploadVideo = pandora.hasCapability('canAddItems'),
canAddDocuments = pandora.site.capabilities.canAddDocuments[pandora.user.level], canAddDocuments = pandora.hasCapability('canAddDocuments'),
isSelected = pandora.user.ui._list || pandora.user.ui._collection, isSelected = pandora.user.ui._list || pandora.user.ui._collection,
that = Ox.Element() that = Ox.Element()
.addClass('OxSelectableElement' + (isSelected ? '' : ' OxSelected')) .addClass('OxSelectableElement' + (isSelected ? '' : ' OxSelected'))

View file

@ -118,7 +118,7 @@ pandora.ui.mainMenu = function() {
], items: [ ], items: [
{ group: 'itemview', min: 1, max: 1, items: pandora.site.itemViews.filter(function(view) { { group: 'itemview', min: 1, max: 1, items: pandora.site.itemViews.filter(function(view) {
return view.id != 'data' && view.id != 'media' || return view.id != 'data' && view.id != 'media' ||
pandora.site.capabilities.canSeeExtraItemViews[pandora.user.level]; pandora.hasCapability('canSeeExtraItemViews');
}).map(function(view) { }).map(function(view) {
return Ox.extend({ return Ox.extend({
checked: ui.itemView == view.id checked: ui.itemView == view.id
@ -222,28 +222,28 @@ pandora.ui.mainMenu = function() {
getFindMenu(), getFindMenu(),
{ id: 'dataMenu', title: Ox._('Data'), items: [ { id: 'dataMenu', title: Ox._('Data'), items: [
!Ox.isEmpty(pandora.site.capabilities.canManageHome) !Ox.isEmpty(pandora.site.capabilities.canManageHome)
? [{ id: 'managehome', title: Ox._('Manage Home...'), disabled: !pandora.site.capabilities.canManageHome[pandora.user.level] }] : [], ? [{ id: 'managehome', title: Ox._('Manage Home...'), disabled: !pandora.hasCapability('canManageHome') }] : [],
pandora.site.entities.length pandora.site.entities.length
? [{ id: 'entities', title: Ox._('Manage Entities...'), disabled: !pandora.site.entities.length || !pandora.site.capabilities.canManageEntities[pandora.user.level] }] : [], ? [{ id: 'entities', title: Ox._('Manage Entities...'), disabled: !pandora.site.entities.length || !pandora.hasCapability('canManageEntities') }] : [],
(!Ox.isEmpty(pandora.site.capabilities.canManageHome) || pandora.site.entities.length) (!Ox.isEmpty(pandora.site.capabilities.canManageHome) || pandora.site.entities.length)
? [{}] : [], ? [{}] : [],
{ id: 'titles', title: Ox._('Manage Titles...'), disabled: !pandora.site.capabilities.canManageTitlesAndNames[pandora.user.level] }, { id: 'titles', title: Ox._('Manage Titles...'), disabled: !pandora.hasCapability('canManageTitlesAndNames') },
{ id: 'names', title: Ox._('Manage Names...'), disabled: !pandora.site.capabilities.canManageTitlesAndNames[pandora.user.level] }, { id: 'names', title: Ox._('Manage Names...'), disabled: !pandora.hasCapability('canManageTitlesAndNames') },
{}, {},
{ id: 'places', title: Ox._('Manage Places...'), disabled: !pandora.site.capabilities.canManagePlacesAndEvents[pandora.user.level] }, { id: 'places', title: Ox._('Manage Places...'), disabled: !pandora.hasCapability('canManagePlacesAndEvents') },
{ id: 'events', title: Ox._('Manage Events...'), disabled: !pandora.site.capabilities.canManagePlacesAndEvents[pandora.user.level] }, { id: 'events', title: Ox._('Manage Events...'), disabled: !pandora.hasCapability('canManagePlacesAndEvents') },
{}, {},
{ id: 'users', title: Ox._('Manage Users...'), disabled: !pandora.site.capabilities.canManageUsers[pandora.user.level] }, { id: 'users', title: Ox._('Manage Users...'), disabled: !pandora.hasCapability('canManageUsers') },
{ id: 'statistics', title: Ox._('Statistics...'), disabled: !pandora.site.capabilities.canManageUsers[pandora.user.level] }, { id: 'statistics', title: Ox._('Statistics...'), disabled: !pandora.hasCapability('canManageUsers') },
{}, {},
{ id: 'changelog', title: Ox._('Changelog...'), disabled: !pandora.site.capabilities.canManageUsers[pandora.user.level] } { id: 'changelog', title: Ox._('Changelog...'), disabled: !pandora.hasCapability('canManageUsers') }
] }, ] },
{ id: 'helpMenu', title: Ox._('Help'), items: [ { id: 'helpMenu', title: Ox._('Help'), items: [
{ id: 'help', title: Ox._('Help...'), keyboard: 'control ?' }, { id: 'help', title: Ox._('Help...'), keyboard: 'control ?' },
{ id: 'api', title: Ox._('API Documentation...'), keyboard: 'shift control ?' } { id: 'api', title: Ox._('API Documentation...'), keyboard: 'shift control ?' }
] } ] }
], ],
pandora.site.capabilities.canSeeDebugMenu[pandora.user.level] pandora.hasCapability('canSeeDebugMenu')
? [ ? [
{ id: 'debugMenu', title: Ox._('Debug'), items: [ { id: 'debugMenu', title: Ox._('Debug'), items: [
{ id: 'clearcache', title: Ox._('Clear Cache')}, { id: 'clearcache', title: Ox._('Clear Cache')},
@ -1001,7 +1001,7 @@ pandora.ui.mainMenu = function() {
if (ui.item) { if (ui.item) {
view = pandora.site.itemViews[i]; view = pandora.site.itemViews[i];
if (view && (view.id != 'data' && view.id != 'media' || if (view && (view.id != 'data' && view.id != 'media' ||
pandora.site.capabilities.canSeeExtraItemViews[pandora.user.level])) { pandora.hasCapability('canSeeExtraItemViews'))) {
pandora.UI.set({itemView: view.id}); pandora.UI.set({itemView: view.id});
} }
} else { } else {
@ -1117,7 +1117,7 @@ pandora.ui.mainMenu = function() {
canDelete = ( canDelete = (
ui.document || ui.collectionSelection.length ui.document || ui.collectionSelection.length
) && ( ) && (
pandora.site.capabilities.canRemoveDocuments[pandora.user.level] || pandora.hasCapability('canRemoveDocuments') ||
ui.collectionSelection.every(function(item) { ui.collectionSelection.every(function(item) {
return pandora.$ui.list && pandora.$ui.list.value(item, 'editable'); return pandora.$ui.list && pandora.$ui.list.value(item, 'editable');
}) })
@ -1131,7 +1131,7 @@ pandora.ui.mainMenu = function() {
undoText = pandora.history.undoText(), undoText = pandora.history.undoText(),
redoText = pandora.history.redoText(); redoText = pandora.history.redoText();
return { id: 'itemMenu', title: Ox._('Item'), items: [ return { id: 'itemMenu', title: Ox._('Item'), items: [
{ id: 'add', title: Ox._('Add {0}...', [Ox._('Document')]), disabled: !pandora.site.capabilities.canAddItems[pandora.user.level] }, { id: 'add', title: Ox._('Add {0}...', [Ox._('Document')]), disabled: !pandora.hasCapability('canAddItems') },
{ id: 'edit', title: Ox._('Edit {0}...', [Ox._('Document')]), disabled: true /*fixme: !canEdit */ }, { id: 'edit', title: Ox._('Edit {0}...', [Ox._('Document')]), disabled: true /*fixme: !canEdit */ },
{}, {},
{ id: 'selectall', title: Ox._('Select All {0}', [listItemsName]), disabled: !canSelect, keyboard: 'control a' }, { id: 'selectall', title: Ox._('Select All {0}', [listItemsName]), disabled: !canSelect, keyboard: 'control a' },
@ -1368,7 +1368,7 @@ pandora.ui.mainMenu = function() {
: clipboardType == 'clip' ? (clipboardItems == 1 ? 'Clip' : 'Clips') : clipboardType == 'clip' ? (clipboardItems == 1 ? 'Clip' : 'Clips')
: '' : ''
), ),
canEdit = pandora.site.capabilities.canEditMedia[pandora.user.level] || ( canEdit = pandora.hasCapability('canEditMedia') || (
ui.section == 'items' && ( ui.section == 'items' && (
ui.item || ( ui.item || (
Ox.contains(['list', 'grid', 'clips', 'timelines'], ui.listView) Ox.contains(['list', 'grid', 'clips', 'timelines'], ui.listView)
@ -1383,7 +1383,7 @@ pandora.ui.mainMenu = function() {
&& ui.listSelection.length && ui.listSelection.length
) )
) && ( ) && (
pandora.site.capabilities.canRemoveItems[pandora.user.level] || pandora.hasCapability('canRemoveItems') ||
ui.listSelection.every(function(item) { ui.listSelection.every(function(item) {
return pandora.$ui.list && pandora.$ui.list.value(item, 'editable'); return pandora.$ui.list && pandora.$ui.list.value(item, 'editable');
}) })
@ -1405,7 +1405,7 @@ pandora.ui.mainMenu = function() {
undoText = pandora.history.undoText(), undoText = pandora.history.undoText(),
redoText = pandora.history.redoText(); redoText = pandora.history.redoText();
return { id: 'itemMenu', title: Ox._('Item'), items: [ return { id: 'itemMenu', title: Ox._('Item'), items: [
{ id: 'add', title: Ox._('Add {0}...', [Ox._(pandora.site.itemName.singular)]), disabled: !pandora.site.capabilities.canAddItems[pandora.user.level] }, { id: 'add', title: Ox._('Add {0}...', [Ox._(pandora.site.itemName.singular)]), disabled: !pandora.hasCapability('canAddItems') },
{ id: 'edit', title: Ox._('Edit {0}...', [Ox._(pandora.site.itemName.singular)]), disabled: true /*fixme: !canEdit */ }, { id: 'edit', title: Ox._('Edit {0}...', [Ox._(pandora.site.itemName.singular)]), disabled: true /*fixme: !canEdit */ },
{}, {},
{ id: 'selectall', title: Ox._('Select All {0}', [listItemsName]), disabled: !canSelect, keyboard: 'control a' }, { id: 'selectall', title: Ox._('Select All {0}', [listItemsName]), disabled: !canSelect, keyboard: 'control a' },

View file

@ -1295,7 +1295,7 @@ pandora.getClipVideos = function(clip, resolution) {
pandora.getDownloadLink = function(item, rightslevel) { pandora.getDownloadLink = function(item, rightslevel) {
var torrent = pandora.site.video.torrent; var torrent = pandora.site.video.torrent;
if (arguments.length == 2 && torrent && if (arguments.length == 2 && torrent &&
pandora.site.capabilities.canSeeItem.guest < rightslevel) { pandora.hasCapability('canSeeItem', 'guest') < rightslevel) {
torrent = false; torrent = false;
} }
return '/' + item + (torrent ? '/torrent/' : '/download/'); return '/' + item + (torrent ? '/torrent/' : '/download/');
@ -1912,7 +1912,7 @@ pandora.getSortKeys = function() {
return pandora.site.itemKeys.filter(function(key) { return pandora.site.itemKeys.filter(function(key) {
return key.sort && ( return key.sort && (
!key.capability !key.capability
|| pandora.site.capabilities[key.capability][pandora.user.level] || pandora.hasCapability(key.capability)
); );
}).map(function(key) { }).map(function(key) {
return Ox.extend(key, { return Ox.extend(key, {
@ -1932,7 +1932,7 @@ pandora.getDocumentSortKeys = function() {
return pandora.site.documentKeys.filter(function(key) { return pandora.site.documentKeys.filter(function(key) {
return key.sort && ( return key.sort && (
!key.capability !key.capability
|| pandora.site.capabilities[key.capability][pandora.user.level] || pandora.hasCapability(key.capability)
); );
}).map(function(key) { }).map(function(key) {
return Ox.extend(key, { return Ox.extend(key, {
@ -2128,8 +2128,8 @@ pandora.getSpan = function(state, val, callback) {
pandora.getStatusText = function(data) { pandora.getStatusText = function(data) {
var ui = pandora.user.ui, var ui = pandora.user.ui,
canSeeMedia = pandora.site.capabilities.canSeeMedia[pandora.user.level], canSeeMedia = pandora.hasCapability('canSeeMedia'),
canSeeSize = pandora.site.capabilities.canSeeSize[pandora.user.level], canSeeSize = pandora.hasCapability('canSeeSize'),
itemName = ['clip', 'video'].indexOf(ui.listView) > -1 itemName = ['clip', 'video'].indexOf(ui.listView) > -1
? (data.items == 1 ? Ox._('Clip') : Ox._('Clips')) ? (data.items == 1 ? Ox._('Clip') : Ox._('Clips'))
: Ox._(pandora.site.itemName[ : Ox._(pandora.site.itemName[
@ -2272,10 +2272,10 @@ pandora.VIDEO_OPTIONS_KEYS = [
pandora.getVideoOptions = function(data) { pandora.getVideoOptions = function(data) {
var canPlayClips = data.editable var canPlayClips = data.editable
|| pandora.site.capabilities.canPlayClips[pandora.user.level] || pandora.hasCapability('canPlayClips')
>= data.rightslevel, >= data.rightslevel,
canPlayVideo = data.editable canPlayVideo = data.editable
|| pandora.site.capabilities.canPlayVideo[pandora.user.level] || pandora.hasCapability('canPlayVideo')
>= data.rightslevel, >= data.rightslevel,
options = {}; options = {};
options.subtitlesLayer = pandora.getSubtitlesLayer(); options.subtitlesLayer = pandora.getSubtitlesLayer();
@ -2325,7 +2325,7 @@ pandora.getVideoOptions = function(data) {
annotation.duration = Math.abs(annotation.out - annotation['in']); annotation.duration = Math.abs(annotation.out - annotation['in']);
annotation.editable = annotation.editable annotation.editable = annotation.editable
|| annotation.user == pandora.user.username || annotation.user == pandora.user.username
|| pandora.site.capabilities['canEditAnnotations'][pandora.user.level]; || pandora.hasCapability('canEditAnnotations');
annotation.languages = ( annotation.languages = (
annotation.languages || [pandora.site.language] annotation.languages || [pandora.site.language]
).map(function(language) { ).map(function(language) {
@ -2363,6 +2363,11 @@ pandora.getVideoPartsAndPoints = function(durations, points) {
return ret; return ret;
}; };
pandora.hasCapability = function(capability, level) {
level = level || pandora.user.level;
return pandora.site.capabilities[capability] && pandora.site.capabilities[capability][level];
}
pandora.hasDialogOrScreen = function() { pandora.hasDialogOrScreen = function() {
return !!$('.OxDialog:visible').length return !!$('.OxDialog:visible').length
|| !!$('.OxFullscreen').length || !!$('.OxFullscreen').length