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;
var canAddItems = !pandora.site.itemRequiresVideo && pandora.site.capabilities.canAddItems[pandora.user.level],
canUploadVideo = pandora.site.capabilities.canAddItems[pandora.user.level],
canAddDocuments = pandora.site.capabilities.canAddDocuments[pandora.user.level],
var canAddItems = !pandora.site.itemRequiresVideo && pandora.hasCapability('canAddItems'),
canUploadVideo = pandora.hasCapability('canAddItems'),
canAddDocuments = pandora.hasCapability('canAddDocuments'),
isSelected = pandora.user.ui._list || pandora.user.ui._collection,
that = Ox.Element()
.addClass('OxSelectableElement' + (isSelected ? '' : ' OxSelected'))

View file

@ -118,7 +118,7 @@ pandora.ui.mainMenu = function() {
], items: [
{ group: 'itemview', min: 1, max: 1, items: pandora.site.itemViews.filter(function(view) {
return view.id != 'data' && view.id != 'media' ||
pandora.site.capabilities.canSeeExtraItemViews[pandora.user.level];
pandora.hasCapability('canSeeExtraItemViews');
}).map(function(view) {
return Ox.extend({
checked: ui.itemView == view.id
@ -222,28 +222,28 @@ pandora.ui.mainMenu = function() {
getFindMenu(),
{ id: 'dataMenu', title: Ox._('Data'), items: [
!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
? [{ 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)
? [{}] : [],
{ id: 'titles', title: Ox._('Manage Titles...'), disabled: !pandora.site.capabilities.canManageTitlesAndNames[pandora.user.level] },
{ id: 'names', title: Ox._('Manage Names...'), 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.hasCapability('canManageTitlesAndNames') },
{},
{ id: 'places', title: Ox._('Manage Places...'), disabled: !pandora.site.capabilities.canManagePlacesAndEvents[pandora.user.level] },
{ id: 'events', title: Ox._('Manage Events...'), 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.hasCapability('canManagePlacesAndEvents') },
{},
{ id: 'users', title: Ox._('Manage Users...'), disabled: !pandora.site.capabilities.canManageUsers[pandora.user.level] },
{ id: 'statistics', title: Ox._('Statistics...'), 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.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: 'help', title: Ox._('Help...'), keyboard: '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: 'clearcache', title: Ox._('Clear Cache')},
@ -1001,7 +1001,7 @@ pandora.ui.mainMenu = function() {
if (ui.item) {
view = pandora.site.itemViews[i];
if (view && (view.id != 'data' && view.id != 'media' ||
pandora.site.capabilities.canSeeExtraItemViews[pandora.user.level])) {
pandora.hasCapability('canSeeExtraItemViews'))) {
pandora.UI.set({itemView: view.id});
}
} else {
@ -1117,7 +1117,7 @@ pandora.ui.mainMenu = function() {
canDelete = (
ui.document || ui.collectionSelection.length
) && (
pandora.site.capabilities.canRemoveDocuments[pandora.user.level] ||
pandora.hasCapability('canRemoveDocuments') ||
ui.collectionSelection.every(function(item) {
return pandora.$ui.list && pandora.$ui.list.value(item, 'editable');
})
@ -1131,7 +1131,7 @@ pandora.ui.mainMenu = function() {
undoText = pandora.history.undoText(),
redoText = pandora.history.redoText();
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: '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')
: ''
),
canEdit = pandora.site.capabilities.canEditMedia[pandora.user.level] || (
canEdit = pandora.hasCapability('canEditMedia') || (
ui.section == 'items' && (
ui.item || (
Ox.contains(['list', 'grid', 'clips', 'timelines'], ui.listView)
@ -1383,7 +1383,7 @@ pandora.ui.mainMenu = function() {
&& ui.listSelection.length
)
) && (
pandora.site.capabilities.canRemoveItems[pandora.user.level] ||
pandora.hasCapability('canRemoveItems') ||
ui.listSelection.every(function(item) {
return pandora.$ui.list && pandora.$ui.list.value(item, 'editable');
})
@ -1405,7 +1405,7 @@ pandora.ui.mainMenu = function() {
undoText = pandora.history.undoText(),
redoText = pandora.history.redoText();
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: '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) {
var torrent = pandora.site.video.torrent;
if (arguments.length == 2 && torrent &&
pandora.site.capabilities.canSeeItem.guest < rightslevel) {
pandora.hasCapability('canSeeItem', 'guest') < rightslevel) {
torrent = false;
}
return '/' + item + (torrent ? '/torrent/' : '/download/');
@ -1912,7 +1912,7 @@ pandora.getSortKeys = function() {
return pandora.site.itemKeys.filter(function(key) {
return key.sort && (
!key.capability
|| pandora.site.capabilities[key.capability][pandora.user.level]
|| pandora.hasCapability(key.capability)
);
}).map(function(key) {
return Ox.extend(key, {
@ -1932,7 +1932,7 @@ pandora.getDocumentSortKeys = function() {
return pandora.site.documentKeys.filter(function(key) {
return key.sort && (
!key.capability
|| pandora.site.capabilities[key.capability][pandora.user.level]
|| pandora.hasCapability(key.capability)
);
}).map(function(key) {
return Ox.extend(key, {
@ -2128,8 +2128,8 @@ pandora.getSpan = function(state, val, callback) {
pandora.getStatusText = function(data) {
var ui = pandora.user.ui,
canSeeMedia = pandora.site.capabilities.canSeeMedia[pandora.user.level],
canSeeSize = pandora.site.capabilities.canSeeSize[pandora.user.level],
canSeeMedia = pandora.hasCapability('canSeeMedia'),
canSeeSize = pandora.hasCapability('canSeeSize'),
itemName = ['clip', 'video'].indexOf(ui.listView) > -1
? (data.items == 1 ? Ox._('Clip') : Ox._('Clips'))
: Ox._(pandora.site.itemName[
@ -2272,10 +2272,10 @@ pandora.VIDEO_OPTIONS_KEYS = [
pandora.getVideoOptions = function(data) {
var canPlayClips = data.editable
|| pandora.site.capabilities.canPlayClips[pandora.user.level]
|| pandora.hasCapability('canPlayClips')
>= data.rightslevel,
canPlayVideo = data.editable
|| pandora.site.capabilities.canPlayVideo[pandora.user.level]
|| pandora.hasCapability('canPlayVideo')
>= data.rightslevel,
options = {};
options.subtitlesLayer = pandora.getSubtitlesLayer();
@ -2325,7 +2325,7 @@ pandora.getVideoOptions = function(data) {
annotation.duration = Math.abs(annotation.out - annotation['in']);
annotation.editable = annotation.editable
|| annotation.user == pandora.user.username
|| pandora.site.capabilities['canEditAnnotations'][pandora.user.level];
|| pandora.hasCapability('canEditAnnotations');
annotation.languages = (
annotation.languages || [pandora.site.language]
).map(function(language) {
@ -2363,6 +2363,11 @@ pandora.getVideoPartsAndPoints = function(durations, points) {
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() {
return !!$('.OxDialog:visible').length
|| !!$('.OxFullscreen').length