Skip to content

Commit

Permalink
Merge pull request #4175 from keystonejs/cloudinary-respect-secure-in…
Browse files Browse the repository at this point in the history
…-admin

Cloudinary admin url update: fixes #2724
  • Loading branch information
Noviny authored Sep 25, 2017
2 parents d7789b3 + ea3d35a commit c9f5bc1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
3 changes: 2 additions & 1 deletion fields/components/columns/CloudinaryImageSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var CloudinaryImageSummary = React.createClass({
},
renderImageThumbnail () {
if (!this.props.image) return;
const url = this.props.image.url.replace(/image\/upload/, `image/upload/c_thumb,g_face,h_${IMAGE_SIZE},w_${IMAGE_SIZE}`);
const startingUrl = this.props.secure ? this.props.image.secure_url : this.props.image.url;
const url = startingUrl.replace(/image\/upload/, `image/upload/c_thumb,g_face,h_${IMAGE_SIZE},w_${IMAGE_SIZE}`);
return <img src={url} style={imageStyle} className="img-load" />;
},
render () {
Expand Down
2 changes: 1 addition & 1 deletion fields/types/cloudinaryimage/CloudinaryImageColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var CloudinaryImageColumn = React.createClass({

return (
<ItemsTableValue field={this.props.col.type}>
<CloudinaryImageSummary label="dimensions" image={value} />
<CloudinaryImageSummary label="dimensions" image={value} secure={this.props.col.field.secure} />
</ItemsTableValue>
);

Expand Down
1 change: 1 addition & 0 deletions fields/types/cloudinaryimage/CloudinaryImageField.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ module.exports = Field.create({
crop: 'fit',
height: height,
format: 'jpg',
secure: this.props.secure,
});
}

Expand Down
15 changes: 15 additions & 0 deletions fields/types/cloudinaryimage/CloudinaryImageType.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ cloudinaryimage.prototype.getData = function (item) {
return typeof value === 'object' ? value : {};
};

cloudinaryimage.prototype._originalGetOptions = cloudinaryimage.prototype.getOptions;

cloudinaryimage.prototype.getOptions = function () {
this._originalGetOptions();
// We are performing the check here, so that if cloudinary secure is added
// to keystone after the model is registered, it will still be respected.
// Setting secure overrides default `cloudinary secure`
if ('secure' in this.options) {
this.__options.secure = this.options.secure;
} else if (keystone.get('cloudinary secure')) {
this.__options.secure = keystone.get('cloudinary secure');
}
return this.__options;
};

/**
* Detects whether the field has been modified
*/
Expand Down
4 changes: 2 additions & 2 deletions fields/types/cloudinaryimages/CloudinaryImagesColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var CloudinaryImagesColumn = React.createClass({
const items = [];
for (let i = 0; i < 3; i++) {
if (!value[i]) break;
items.push(<CloudinaryImageSummary key={'image' + i} image={value[i]} />);
items.push(<CloudinaryImageSummary key={'image' + i} image={value[i]} secure={this.props.col.field.secure} />);
}
if (value.length > 3) {
items.push(<span key="more" style={moreIndicatorStyle}>[...{value.length - 3} more]</span>);
Expand All @@ -29,7 +29,7 @@ var CloudinaryImagesColumn = React.createClass({
renderValue (value) {
if (!value || !Object.keys(value).length) return;

return <CloudinaryImageSummary image={value} />;
return <CloudinaryImageSummary image={value} secure={this.props.col.field.secure} />;

},
render () {
Expand Down
5 changes: 4 additions & 1 deletion fields/types/cloudinaryimages/CloudinaryImagesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ module.exports = Field.create({
imageSourceSmall: cloudinaryResize(img.public_id, {
...RESIZE_DEFAULTS,
height: 90,
secure: props.secure,
}),
imageSourceLarge: cloudinaryResize(img.public_id, {
...RESIZE_DEFAULTS,
height: 600,
width: 900,
secure: props.secure,
}),
}, index);
}) : [];
Expand Down Expand Up @@ -215,14 +217,15 @@ module.exports = Field.create({
}
},
renderLightbox () {
const { value } = this.props;
const { value, secure } = this.props;
if (!value || !value.length) return;

const images = value.map(image => ({
src: cloudinaryResize(image.public_id, {
...RESIZE_DEFAULTS,
height: 600,
width: 900,
secure,
}),
}));

Expand Down
16 changes: 16 additions & 0 deletions fields/types/cloudinaryimages/CloudinaryImagesType.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ cloudinaryimages.prototype.inputIsValid = function (data) { // eslint-disable-li
return true;
};


cloudinaryimages.prototype._originalGetOptions = cloudinaryimages.prototype.getOptions;

cloudinaryimages.prototype.getOptions = function () {
this._originalGetOptions();
// We are performing the check here, so that if cloudinary secure is added
// to keystone after the model is registered, it will still be respected.
// Setting secure overrides default `cloudinary secure`
if ('secure' in this.options) {
this.__options.secure = this.options.secure;
} else if (keystone.get('cloudinary secure')) {
this.__options.secure = keystone.get('cloudinary secure');
}
return this.__options;
};

/**
* Updates the value for this field in the item from a data object
*/
Expand Down

0 comments on commit c9f5bc1

Please sign in to comment.