Skip to content

Commit

Permalink
enh(api): permissions and page mode
Browse files Browse the repository at this point in the history
Add the following functions to the js api:
* `updateCollectiveEditPermissions`
* `updateCollectiveSharePermissions`
* `updateCollectiveEditMode`

These wrap the corresponding API endpoints.

Use them from the store and the cypress tests.

Also extract `collective-edit-mode.spec.js` from `pages.spec.js`.
It requires a different beforeEach function
to seed the edit mode before visiting the collective.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Nov 28, 2023
1 parent fbc37fc commit c7cc37a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 47 deletions.
61 changes: 61 additions & 0 deletions cypress/e2e/collective-page-mode.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @copyright Copyright (c) 2021 Azul <[email protected]>
*
* @author Azul <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

describe('Collective page mode', function() {

before(function() {
cy.loginAs('bob')
cy.deleteAndSeedCollective('Our Garden')
.seedPage('Day 1', '', 'Readme.md')
.seedPage('Day 2', '', 'Readme.md')
})

beforeEach(function() {
cy.loginAs('bob')
})

describe('Changing page mode', function() {
it('Opens edit mode per default', function() {
cy.seedCollectivePageMode('Our Garden', 1)
cy.visit('/apps/collectives/Our Garden')
// make sure the page list loaded properly
cy.contains('.app-content-list-item a', 'Day 1')
cy.openPage('Day 2')
cy.getEditor()
.should('be.visible')
cy.getReadOnlyEditor()
.should('not.be.visible')
})

it('Opens view mode per default', function() {
cy.seedCollectivePageMode('Our Garden', 0)
cy.visit('/apps/collectives/Our Garden')
// make sure the page list loaded properly
cy.contains('.app-content-list-item a', 'Day 1')
cy.openPage('Day 2')
cy.getReadOnlyEditor()
.should('be.visible')
cy.getEditor()
.should('not.be.visible')
})
})
})
1 change: 0 additions & 1 deletion cypress/e2e/collective-readonly.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('Read-only collective', function() {
.seedPage('SecondPage')
cy.circleFind('PermissionCollective')
.circleAddMember('bob')
cy.visit('apps/collectives/PermissionCollective')
cy.seedCollectivePermissions('PermissionCollective', 'edit', 4)
})

Expand Down
21 changes: 1 addition & 20 deletions cypress/e2e/pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

describe('Page', function() {

before(function() {
cy.loginAs('bob')
cy.deleteAndSeedCollective('Our Garden').as('garden')
Expand Down Expand Up @@ -264,26 +265,6 @@ describe('Page', function() {
})
}

describe('Changing page mode', function() {
it('Opens edit mode per default', function() {
cy.seedCollectivePageMode('Our Garden', 1)
cy.openPage('Day 2')
cy.getEditor()
.should('be.visible')
cy.getReadOnlyEditor()
.should('not.be.visible')
})

it('Opens view mode per default', function() {
cy.seedCollectivePageMode('Our Garden', 0)
cy.openPage('Day 2')
cy.getReadOnlyEditor()
.should('be.visible')
cy.getEditor()
.should('not.be.visible')
})
})

describe('Full width view', function() {
it('Allows to toggle persistent full-width view', function() {
cy.openPage('Day 2')
Expand Down
20 changes: 6 additions & 14 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { login, logout } from '@nextcloud/cypress/commands'
import { User } from '@nextcloud/cypress'

import {
UPDATE_COLLECTIVE_EDIT_PERMISSIONS,
UPDATE_COLLECTIVE_SHARE_PERMISSIONS,
UPDATE_COLLECTIVE_PAGE_MODE,
GET_CIRCLES,
} from '../../src/store/actions.js'

import * as api from '../../src/api.js'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
Expand Down Expand Up @@ -254,21 +247,21 @@ Cypress.Commands.add('deleteCollectiveFromTrash', (name) => {
Cypress.Commands.add('seedCollectivePermissions', (name, type, level) => {
Cypress.log()
const action = (type === 'edit')
? UPDATE_COLLECTIVE_EDIT_PERMISSIONS
: UPDATE_COLLECTIVE_SHARE_PERMISSIONS
cy.store('state.collectives.collectives')
? api.updateCollectiveEditPermissions
: api.updateCollectiveSharePermissions
cy.getCollectives()
.findBy({ name })
.dispatch(action, { level })
.then((found) => action(found.id, level))
})

/**
* Change default page mode for a collective
*/
Cypress.Commands.add('seedCollectivePageMode', (name, mode) => {
Cypress.log()
cy.store('state.collectives.collectives')
cy.getCollectives()
.findBy({ name })
.dispatch(UPDATE_COLLECTIVE_PAGE_MODE, { mode })
.then((found) => api.updateCollectivePageMode(found.id, mode))
})

function collectiveContext(collective) {
Expand Down Expand Up @@ -330,7 +323,6 @@ Cypress.Commands.add('uploadFile', (path, mimeType, remotePath = '') => {
})
})


/**
* Generic upload of content - used by seedPageContent and uploadPage
*/
Expand Down
12 changes: 12 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export function deleteCollective(id, circle) {
return axios.delete(url('/trash/' + id + doCircle))
}

export function updateCollectiveEditPermissions(id, level) {
return axios.put(url(`/${id}/editLevel`), { level })
}

export function updateCollectiveSharePermissions(id, level) {
return axios.put(url(`/${id}/shareLevel`), { level })
}

export function updateCollectivePageMode(id, mode) {
return axios.put(url(`/${id}/pageMode`), { mode })
}

export function getPages(context) {
return axios.get(pagesUrl(context))
}
Expand Down
15 changes: 3 additions & 12 deletions src/store/collectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,7 @@ export default {
* @param {number} data.level new minimum level for sharing
*/
async [UPDATE_COLLECTIVE_EDIT_PERMISSIONS]({ commit }, { id, level }) {
const response = await axios.put(
generateUrl('/apps/collectives/_api/' + id + '/editLevel'),
{ level },
)
const response = await api.updateCollectiveEditPermissions(id, level)
commit(ADD_OR_UPDATE_COLLECTIVE, response.data.data)
},

Expand All @@ -409,10 +406,7 @@ export default {
* @param {number} data.level new minimum level for sharing
*/
async [UPDATE_COLLECTIVE_SHARE_PERMISSIONS]({ commit }, { id, level }) {
const response = await axios.put(
generateUrl('/apps/collectives/_api/' + id + '/shareLevel'),
{ level },
)
const response = await api.updateCollectiveSharePermissions(id, level)
commit(ADD_OR_UPDATE_COLLECTIVE, response.data.data)
},

Expand All @@ -424,10 +418,7 @@ export default {
* @param {number} data.mode page mode
*/
async [UPDATE_COLLECTIVE_PAGE_MODE]({ commit }, { id, mode }) {
const response = await axios.put(
generateUrl('/apps/collectives/_api/' + id + '/pageMode'),
{ mode },
)
const response = await api.updateCollectivePageMode(id, mode)
commit(ADD_OR_UPDATE_COLLECTIVE, response.data.data)
},

Expand Down

0 comments on commit c7cc37a

Please sign in to comment.