Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Hide download action when file does not provide download permissions #2482

Merged
merged 4 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion css/init-DVBqS-jx.chunk.css

This file was deleted.

4 changes: 4 additions & 0 deletions css/init-DjAoarD-.chunk.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions css/viewer-init.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* extracted by css-entry-points-plugin */
@import './init-DVBqS-jx.chunk.css';
@import './logger-B0wUvUiR.chunk.css';
@import './init-DjAoarD-.chunk.css';
@import './logger-BBud9Daj.chunk.css';
@import './NcActionButton-1r3w9zkv.chunk.css';
@import './NcActionLink-CRpLQTQ1.chunk.css';
4 changes: 2 additions & 2 deletions css/viewer-main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* extracted by css-entry-points-plugin */
@import './main-D7IKD3sM.chunk.css';
@import './logger-B0wUvUiR.chunk.css';
@import './main-C8UVjoKr.chunk.css';
@import './logger-BBud9Daj.chunk.css';
67 changes: 67 additions & 0 deletions cypress/e2e/download-forbidden.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* SPDX-License: AGPL-3.0-or-later
* SPDX-: Nextcloud GmbH and Nextcloud contributors
*/

import type { User } from '@nextcloud/cypress'
import { ShareType } from '@nextcloud/sharing'

describe('Disable download button if forbidden', { testIsolation: true }, () => {
let sharee: User

before(() => {
cy.createRandomUser().then((user) => { sharee = user })
cy.createRandomUser().then((user) => {
// Upload test files
cy.createFolder(user, '/Photos')
cy.uploadFile(user, 'image1.jpg', 'image/jpeg', '/Photos/image1.jpg')

cy.login(user)
cy.createShare('/Photos',
{ shareWith: sharee.userId, shareType: ShareType.User, attributes: [{ scope: 'permissions', key: 'download', value: false }] },
)
cy.logout()
})
})

beforeEach(() => {
cy.login(sharee)
cy.visit('/apps/files')
cy.openFile('Photos')
})

it('See the shared folder and images in files list', () => {
cy.getFile('image1.jpg', { timeout: 10000 })
.should('contain', 'image1 .jpg')
})

// TODO: Fix no-download files on server
it.skip('See the image can be shown', () => {
cy.getFile('image1.jpg').should('be.visible')
cy.openFile('image1.jpg')
cy.get('body > .viewer').should('be.visible')

cy.get('body > .viewer', { timeout: 10000 })
.should('be.visible')
.and('have.class', 'modal-mask')
.and('not.have.class', 'icon-loading')
})

it('See the title on the viewer header but not the Download nor the menu button', () => {
cy.getFile('image1.jpg').should('be.visible')
cy.openFile('image1.jpg')
cy.get('body > .viewer .modal-header__name').should('contain', 'image1.jpg')

cy.get('[role="dialog"]')
.should('be.visible')
.find('button[aria-label="Actions"]')
.click()

cy.get('[role="menu"]:visible')
.find('button')
.should('have.length', 2)
.each(($el) => {
expect($el.text()).to.match(/(Full screen|Open sidebar)/i)
})
})
})
61 changes: 39 additions & 22 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
*
*/

import { addCommands, User } from '@nextcloud/cypress'
import { basename } from 'path'
import axios from '@nextcloud/axios'
import { addCommands } from '@nextcloud/cypress'
import { Permission } from '@nextcloud/files'
import { ShareType } from '@nextcloud/sharing'
import { addCompareSnapshotCommand } from 'cypress-visual-regression/dist/command'
import { basename } from 'path'

addCommands()
addCompareSnapshotCommand()
Expand All @@ -34,7 +35,7 @@
/**
* cy.uploadedFile - uploads a file from the fixtures folder
*
* @param {User} user the owner of the file, e.g. admin

Check warning on line 38 in cypress/support/commands.ts

View workflow job for this annotation

GitHub Actions / NPM lint

The type 'User' is undefined
* @param {string} fixture the fixture file name, e.g. image1.jpg
* @param {string} mimeType e.g. image/png
* @param {string} [target] the target of the file relative to the user root
Expand Down Expand Up @@ -126,32 +127,48 @@
},
)

interface ShareOptions {
shareType: number
shareWith?: string
permissions: number
attributes?: { value: boolean, key: string, scope: string}[]
}

Cypress.Commands.add('createShare', (path: string, shareOptions?: ShareOptions) => {
return cy.request('/csrftoken').then(({ body }) => {
const requesttoken = body.token

return cy.request({
method: 'POST',
url: '../ocs/v2.php/apps/files_sharing/api/v1/shares?format=json',
headers: {
requesttoken,
},
body: {
path,
permissions: Permission.READ,
...shareOptions,
attributes: shareOptions?.attributes && JSON.stringify(shareOptions.attributes),
},
}).then(({ body }) => {
const shareToken = body.ocs?.data?.token
if (shareToken === undefined) {
throw new Error('Invalid OCS response')
}
cy.log('Share link created', shareToken)
return cy.wrap(shareToken)
})
})
})

/**
* Create a share link and return the share url
*
* @param {string} path the file/folder path
* @return {string} the share link url
*/
Cypress.Commands.add('createLinkShare', path => {
return cy.window().then(async window => {
try {
const request = await axios.post(`${Cypress.env('baseUrl')}/ocs/v2.php/apps/files_sharing/api/v1/shares`, {
path,
shareType: window.OC.Share.SHARE_TYPE_LINK,
}, {
headers: {
requesttoken: window.OC.requestToken,
},
})
if (!('ocs' in request.data) || !('token' in request.data.ocs.data && request.data.ocs.data.token.length > 0)) {
throw request
}
cy.log('Share link created', request.data.ocs.data.token)
return cy.wrap(request.data.ocs.data.token)
} catch (error) {
console.error(error)
}
}).should('have.length', 15)
return cy.createShare(path, { shareType: ShareType.Link })
})

Cypress.Commands.overwrite('compareSnapshot', (originalFn, subject, name, options) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*! third party licenses: js/vendor.LICENSE.txt */
import{A as i,be as a}from"./logger-wTanTwQL.chunk.mjs";import{A as n}from"./actionText-fFcUPi2g-1UIVDoW6.chunk.mjs";const o={name:"CheckIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}};var l=function(){var t=this,e=t._self._c;return e("span",t._b({staticClass:"material-design-icon check-icon",attrs:{"aria-hidden":t.title?null:!0,"aria-label":t.title,role:"img"},on:{click:function(s){return t.$emit("click",s)}}},"span",t.$attrs,!1),[e("svg",{staticClass:"material-design-icon__svg",attrs:{fill:t.fillColor,width:t.size,height:t.size,viewBox:"0 0 24 24"}},[e("path",{attrs:{d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"}},[t.title?e("title",[t._v(t._s(t.title))]):t._e()])])])},c=[],u=i(o,l,c,!1,null,null);const r=u.exports,d={name:"NcActionButton",components:{CheckIcon:r,ChevronRightIcon:a},mixins:[n],inject:{isInSemanticMenu:{from:"NcActions:isSemanticMenu",default:!1}},props:{ariaHidden:{type:Boolean,default:null},disabled:{type:Boolean,default:!1},isMenu:{type:Boolean,default:!1},type:{type:String,default:"button",validator:t=>["button","checkbox","radio","reset","submit"].includes(t)},modelValue:{type:[Boolean,String],default:null},value:{type:String,default:null}},computed:{isFocusable(){return!this.disabled},isChecked(){return this.type==="radio"&&typeof this.modelValue!="boolean"?this.modelValue===this.value:this.modelValue},nativeType(){return this.type==="submit"||this.type==="reset"?this.type:"button"},buttonAttributes(){const t={};return this.isInSemanticMenu?(t.role="menuitem",this.type==="radio"?(t.role="menuitemradio",t["aria-checked"]=this.isChecked?"true":"false"):(this.type==="checkbox"||this.nativeType==="button"&&this.modelValue!==null)&&(t.role="menuitemcheckbox",t["aria-checked"]=this.modelValue===null?"mixed":this.modelValue?"true":"false")):this.modelValue!==null&&this.nativeType==="button"&&(t["aria-pressed"]=this.modelValue?"true":"false"),t}},methods:{handleClick(t){this.onClick(t),(this.modelValue!==null||this.type!=="button")&&(this.type==="radio"?typeof this.modelValue!="boolean"?this.isChecked||this.$emit("update:modelValue",this.value):this.$emit("update:modelValue",!this.isChecked):this.$emit("update:modelValue",!this.isChecked))}}};var h=function(){var t=this,e=t._self._c;return e("li",{staticClass:"action",class:{"action--disabled":t.disabled},attrs:{role:t.isInSemanticMenu&&"presentation"}},[e("button",t._b({class:["action-button button-vue",{"action-button--active":t.isChecked,focusable:t.isFocusable}],attrs:{"aria-label":t.ariaLabel,disabled:t.disabled,title:t.title,type:t.nativeType},on:{click:t.handleClick}},"button",t.buttonAttributes,!1),[t._t("icon",function(){return[e("span",{staticClass:"action-button__icon",class:[t.isIconUrl?"action-button__icon--url":t.icon],style:{backgroundImage:t.isIconUrl?"url(".concat(t.icon,")"):null},attrs:{"aria-hidden":"true"}})]}),t.name?e("span",{staticClass:"action-button__longtext-wrapper"},[e("strong",{staticClass:"action-button__name"},[t._v(" "+t._s(t.name)+" ")]),e("br"),e("span",{staticClass:"action-button__longtext",domProps:{textContent:t._s(t.text)}})]):t.isLongText?e("span",{staticClass:"action-button__longtext",domProps:{textContent:t._s(t.text)}}):e("span",{staticClass:"action-button__text"},[t._v(t._s(t.text))]),t.isMenu?e("ChevronRightIcon",{staticClass:"action-button__menu-icon",attrs:{size:20}}):t.isChecked===!0?e("CheckIcon",{staticClass:"action-button__pressed-icon",attrs:{size:20}}):t.isChecked===!1?e("span",{staticClass:"action-button__pressed-icon material-design-icon"}):t._e(),t._e()],2)])},p=[],m=i(d,h,p,!1,null,"dba65098");const b=m.exports,f=Object.freeze(Object.defineProperty({__proto__:null,default:b},Symbol.toStringTag,{value:"Module"}));export{r as C,b as N,f as a};
import{B as i,bh as a}from"./logger-Bp-YsDry.chunk.mjs";import{A as n}from"./actionText-fFcUPi2g-1UIVDoW6.chunk.mjs";const o={name:"CheckIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}};var l=function(){var t=this,e=t._self._c;return e("span",t._b({staticClass:"material-design-icon check-icon",attrs:{"aria-hidden":t.title?null:!0,"aria-label":t.title,role:"img"},on:{click:function(s){return t.$emit("click",s)}}},"span",t.$attrs,!1),[e("svg",{staticClass:"material-design-icon__svg",attrs:{fill:t.fillColor,width:t.size,height:t.size,viewBox:"0 0 24 24"}},[e("path",{attrs:{d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"}},[t.title?e("title",[t._v(t._s(t.title))]):t._e()])])])},c=[],u=i(o,l,c,!1,null,null);const r=u.exports,d={name:"NcActionButton",components:{CheckIcon:r,ChevronRightIcon:a},mixins:[n],inject:{isInSemanticMenu:{from:"NcActions:isSemanticMenu",default:!1}},props:{ariaHidden:{type:Boolean,default:null},disabled:{type:Boolean,default:!1},isMenu:{type:Boolean,default:!1},type:{type:String,default:"button",validator:t=>["button","checkbox","radio","reset","submit"].includes(t)},modelValue:{type:[Boolean,String],default:null},value:{type:String,default:null}},computed:{isFocusable(){return!this.disabled},isChecked(){return this.type==="radio"&&typeof this.modelValue!="boolean"?this.modelValue===this.value:this.modelValue},nativeType(){return this.type==="submit"||this.type==="reset"?this.type:"button"},buttonAttributes(){const t={};return this.isInSemanticMenu?(t.role="menuitem",this.type==="radio"?(t.role="menuitemradio",t["aria-checked"]=this.isChecked?"true":"false"):(this.type==="checkbox"||this.nativeType==="button"&&this.modelValue!==null)&&(t.role="menuitemcheckbox",t["aria-checked"]=this.modelValue===null?"mixed":this.modelValue?"true":"false")):this.modelValue!==null&&this.nativeType==="button"&&(t["aria-pressed"]=this.modelValue?"true":"false"),t}},methods:{handleClick(t){this.onClick(t),(this.modelValue!==null||this.type!=="button")&&(this.type==="radio"?typeof this.modelValue!="boolean"?this.isChecked||this.$emit("update:modelValue",this.value):this.$emit("update:modelValue",!this.isChecked):this.$emit("update:modelValue",!this.isChecked))}}};var h=function(){var t=this,e=t._self._c;return e("li",{staticClass:"action",class:{"action--disabled":t.disabled},attrs:{role:t.isInSemanticMenu&&"presentation"}},[e("button",t._b({class:["action-button button-vue",{"action-button--active":t.isChecked,focusable:t.isFocusable}],attrs:{"aria-label":t.ariaLabel,disabled:t.disabled,title:t.title,type:t.nativeType},on:{click:t.handleClick}},"button",t.buttonAttributes,!1),[t._t("icon",function(){return[e("span",{staticClass:"action-button__icon",class:[t.isIconUrl?"action-button__icon--url":t.icon],style:{backgroundImage:t.isIconUrl?"url(".concat(t.icon,")"):null},attrs:{"aria-hidden":"true"}})]}),t.name?e("span",{staticClass:"action-button__longtext-wrapper"},[e("strong",{staticClass:"action-button__name"},[t._v(" "+t._s(t.name)+" ")]),e("br"),e("span",{staticClass:"action-button__longtext",domProps:{textContent:t._s(t.text)}})]):t.isLongText?e("span",{staticClass:"action-button__longtext",domProps:{textContent:t._s(t.text)}}):e("span",{staticClass:"action-button__text"},[t._v(t._s(t.text))]),t.isMenu?e("ChevronRightIcon",{staticClass:"action-button__menu-icon",attrs:{size:20}}):t.isChecked===!0?e("CheckIcon",{staticClass:"action-button__pressed-icon",attrs:{size:20}}):t.isChecked===!1?e("span",{staticClass:"action-button__pressed-icon material-design-icon"}):t._e(),t._e()],2)])},p=[],m=i(d,h,p,!1,null,"dba65098");const b=m.exports,f=Object.freeze(Object.defineProperty({__proto__:null,default:b},Symbol.toStringTag,{value:"Module"}));export{r as C,b as N,f as a};
Loading
Loading