Skip to content

Commit

Permalink
Merge pull request #35095 from owncloud/release-10.2.0-share_attribut…
Browse files Browse the repository at this point in the history
…e_required_feature

[10.2.0] share attribute required feature
  • Loading branch information
Vincent Petry authored Apr 30, 2019
2 parents 38bf52c + 98e77f0 commit 5c9e26c
Show file tree
Hide file tree
Showing 4 changed files with 621 additions and 47 deletions.
12 changes: 8 additions & 4 deletions core/js/sharedialogshareelistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
'<div class="shareAttributes"">' +
'{{#each shareAttributes}}' +
'<span class="shareOption">' +
'<input id="can-{{name}}-{{cid}}-{{shareWith}}" type="checkbox" name="{{name}}" class="attributes checkbox" {{#if enabled}}checked="checked"{{/if}} data-scope="{{scope}}" data-enabled="{{enabled}}""/>' +
'<input id="can-{{name}}-{{cid}}-{{shareWith}}" type="checkbox" name="{{name}}" class="attributes checkbox" {{#if isReshare}}disabled{{/if}} {{#if enabled}}checked="checked"{{/if}} data-scope="{{scope}}" data-enabled="{{enabled}}""/>' +
'<label for="can-{{name}}-{{cid}}-{{shareWith}}">{{label}}</label>' +
'</span>' +
'{{/each}}' +
Expand Down Expand Up @@ -129,6 +129,9 @@
var cid = this.cid;
var shareWith = model.getShareWith(shareIndex);

// Check if reshare, and if so disable the checkboxes
var isReshare = model.hasReshare();

// Returns OC.Share.Types.ShareAttribute[] which were set for this
// share (and stored in DB)
var attributes = model.getShareAttributes(shareIndex);
Expand All @@ -137,19 +140,20 @@
attributes.map(function(attribute) {
// Check if the share attribute set for this file is still in
// registered share attributes and get its label
var label = model.getRegisteredShareAttributeLabel(
var regAttr = model.getRegisteredShareAttribute(
attribute.scope,
attribute.key
);

if (label) {
if (regAttr && regAttr.label) {
list.push({
cid: cid,
isReshare: isReshare,
shareWith: shareWith,
enabled: attribute.enabled,
scope: attribute.scope,
name: attribute.key,
label: label
label: regAttr.label
});
} else {
OC.Notification.showTemporary(t('core', 'Share with ' +
Expand Down
91 changes: 55 additions & 36 deletions core/js/shareitemmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @typedef {object} OC.Share.Types.ShareInfo
* @property {number} share_type
* @property {number} permissions
* @property {string} attributes
* @property {OC.Share.Types.ShareAttribute[]} attributes
* @property {number} file_source optional
* @property {number} item_source
* @property {string} token
Expand Down Expand Up @@ -73,6 +73,7 @@
* @property {string} description
* @property {number[]} shareType
* @property {number[]} incompatiblePermissions
* @property {number[]} requiredPermissions
* @property {OC.Share.Types.ShareAttribute[]} incompatibleAttributes
*/

Expand All @@ -85,6 +86,13 @@
'storage', 'share_type', 'parent', 'stime'
];

/**
* Properties which are json and need to be parsed
*/
var SHARE_RESPONSE_JSON_PROPS = [
'attributes'
];

/**
* @class OCA.Share.ShareItemModel
* @classdesc
Expand Down Expand Up @@ -171,10 +179,11 @@
}
properties.permissions = defaultPermissions & possiblePermissions;

// FIXME: simplify the logic by merging and then filtering
// Set default attributes for this share based on registered
// attributes (filtered by their incompatible permissions)
var newShareAttributes = [];
var filteredRegisteredAttributes = this.filterRegisteredAttributes(properties.permissions);
var filteredRegisteredAttributes = this._filterRegisteredAttributes(properties.permissions);
_.map(filteredRegisteredAttributes, function(filteredRegisteredAttribute) {
var isCompatible = true;
// Check if this attribute can be added due to its incompatible attributes
Expand Down Expand Up @@ -233,12 +242,13 @@
var self = this;
options = options || {};

// FIXME: simplify the logic by merging and then filtering
// Set share attributes for this share based on registered
// attributes (filtered by their incompatible permissions
// and incompatible attributes)
var newShareAttributes = [];
var filteredAttributes = [];
var filteredRegisteredAttributes = this.filterRegisteredAttributes(properties.permissions);
var filteredRegisteredAttributes = this._filterRegisteredAttributes(properties.permissions);
_.map(filteredRegisteredAttributes, function(filteredRegisteredAttribute) {
// Check if this allowed registered attribute
// is on the list of currently set properties,
Expand Down Expand Up @@ -785,9 +795,15 @@
// returns integers as string...
var i;
for (i = 0; i < SHARE_RESPONSE_INT_PROPS.length; i++) {
var prop = SHARE_RESPONSE_INT_PROPS[i];
if (!_.isUndefined(share[prop])) {
share[prop] = parseInt(share[prop], 10);
var propInt = SHARE_RESPONSE_INT_PROPS[i];
if (!_.isUndefined(share[propInt])) {
share[propInt] = parseInt(share[propInt], 10);
}
}
for (i = 0; i < SHARE_RESPONSE_JSON_PROPS.length; i++) {
var propJson = SHARE_RESPONSE_JSON_PROPS[i];
if (!_.isUndefined(share[propJson])) {
share[propJson] = JSON.parse(share.attributes);
}
}
return share;
Expand Down Expand Up @@ -868,14 +884,33 @@
return _.uniq(result);
},

/**
* Returns share attributes for given share index
*
* @param shareIndex
* @returns OC.Share.Types.ShareAttribute[]
*/
getShareAttributes: function(shareIndex) {
/** @type OC.Share.Types.ShareInfo **/
var share = this.get('shares')[shareIndex];
if(!_.isObject(share)) {
throw "Unknown Share";
}

if (_.isNull(share.attributes) || _.isUndefined(share.attributes)) {
return [];
}
return share.attributes;
},

/**
* Filter registered attributes by current share permissions
*
* @param {number} permissions
* @returns {OC.Share.Types.RegisteredShareAttribute[]}
* @private
*/
filterRegisteredAttributes: function(permissions) {
_filterRegisteredAttributes: function(permissions) {
var filteredByPermissions = [];
for(var i in this._registeredAttributes) {
var compatible = true;
Expand All @@ -885,6 +920,11 @@
compatible = false;
}
}
for(var ii in attr.requiredPermissions) {
if (!this._hasPermission(permissions, attr.requiredPermissions[ii])) {
compatible = false;
}
}

if (compatible) {
filteredByPermissions.push(attr);
Expand All @@ -894,51 +934,30 @@
return filteredByPermissions;
},

/**
* Returns share attributes for given share index
*
* @param shareIndex
* @returns OC.Share.Types.ShareAttribute[]
*/
getShareAttributes: function(shareIndex) {
/** @type OC.Share.Types.ShareInfo **/
var share = this.get('shares')[shareIndex];
if(!_.isObject(share)) {
throw "Unknown Share";
}

if (_.isUndefined(share.attributes) || _.isUndefined(share.permissions)) {
return [];
}

// Add attributes for this share
var currentAttributes = JSON.parse(share.attributes);
if (currentAttributes) {
return currentAttributes;
}
return [];
},

/**
* Returns share attribute label for given attribute scope and name. If
* attribute does not exist, null is returned.
*
* @param scope
* @param key
* @returns string|null
* @returns {OC.Share.Types.RegisteredShareAttribute}
*/
getRegisteredShareAttributeLabel: function(scope, key) {
getRegisteredShareAttribute: function(scope, key) {
for(var i in this._registeredAttributes) {
if (this._registeredAttributes[i].scope === scope
&& this._registeredAttributes[i].key === key) {
return this._registeredAttributes[i].label;
return this._registeredAttributes[i];
}
}
return null;
},

/**
* Apps can register default share attributes
* Apps can register default share attributes. The applications
* registering share attributes are required to follow the rules:
* attribute enabled -> functionality is added (e.g. can download)
* attribute disabled -> functionality is restricted
* incompatible attribute -> functionality is ignored
*
* @param {OC.Share.Types.RegisteredShareAttribute} $shareAttribute
*/
Expand Down
Loading

0 comments on commit 5c9e26c

Please sign in to comment.