Skip to content

Commit

Permalink
add creating group
Browse files Browse the repository at this point in the history
  • Loading branch information
ScharfViktor committed Aug 1, 2022
1 parent c9a1af9 commit b924330
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 72 deletions.
43 changes: 43 additions & 0 deletions tests/e2e/cucumber/features/integrations/reshare.ocis.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Feature: reshare

Background:
And "Admin" disables share auto accepting

Scenario: folder
Given "Admin" creates following users
| id |
| Alice |
| Brian |
| Carol |
And "Admin" creates following group
| id |
| sales |
| finance |
When "Admin" adds user to the group
| user | group |
| Carol | sales |
When "Alice" logs in
And "Alice" creates the following resources
| resource | type |
| folder_to_shared | folder |
When "Alice" shares the following resource using the sidebar panel
| resource | user | role |
| folder_to_shared | Brian | editor |
And "Brian" logs in
And "Brian" opens the "files" app
And "Brian" navigates to the shared with me page
And "Brian" accepts the following share
| name |
| folder_to_shared |
And "Brian" reshares the following resource
| resource | user | role |
| folder_to_shared | Carol | viewer |
When "Carol" logs in
And "Carol" opens the "files" app
And "Carol" navigates to the shared with me page
And "Carol" accepts the following share
| name |
| folder_to_shared |
And "Alice" logs out
And "Brian" logs out
And "Carol" logs out
35 changes: 35 additions & 0 deletions tests/e2e/cucumber/steps/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,38 @@ Given(
})
}
)

Given(
'{string} creates following group(s)',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
const admin = this.usersEnvironment.getUser({ key: stepUser })

for (const info of stepTable.hashes()) {
const group = this.usersEnvironment.getGroup({ key: info.id })
if (config.ocis) {
await api.graph.deleteGroup({ group, admin })
await api.graph.createGroup({ group, admin })
} else {
await api.user.deleteGroup({ group, admin })
await api.user.createGroup({ group, admin })
}
}
}
)

Given(
'{string} adds user(s) to the group(s)',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
const admin = this.usersEnvironment.getUser({ key: stepUser })

for (const info of stepTable.hashes()) {
const group = this.usersEnvironment.getGroup({ key: info.group })
const user = this.usersEnvironment.getUser({ key: info.user })
if (config.ocis) {
await api.graph.addUserToGroup({ user, group, admin })
} else {
await api.user.addUserToGroup({ user, group, admin })
}
}
}
)
28 changes: 28 additions & 0 deletions tests/e2e/cucumber/steps/app-files/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ When(
}
)

When(
/^"([^"]*)" reshares the following (resource|resources)$/,
async function (this: World, stepUser: string, _: string, stepTable: DataTable) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const shareObject = new objects.applicationFiles.Share({ page })
const shareInfo = stepTable.hashes().reduce((acc, stepRow) => {
const { user, resource, role } = stepRow

if (!acc[resource]) {
acc[resource] = { users: [], role: '' }
}

acc[resource].users.push(this.usersEnvironment.getUser({ key: user }))
acc[resource].role = role

return acc
}, {})

for (const folder of Object.keys(shareInfo)) {
await shareObject.createReshare({
folder,
users: shareInfo[folder].users,
role: shareInfo[folder].role
})
}
}
)

When(
'{string} accepts the following share(s)',
async function (this: World, stepUser: string, stepTable: DataTable) {
Expand Down
9 changes: 8 additions & 1 deletion tests/e2e/support/api/graph/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
export { me, createUser, deleteUser } from './user'
export {
me,
createUser,
deleteUser,
createGroup,
deleteGroup,
addUserToGroup
} from './userManagement'
42 changes: 0 additions & 42 deletions tests/e2e/support/api/graph/user.ts

This file was deleted.

131 changes: 131 additions & 0 deletions tests/e2e/support/api/graph/userManagement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { checkResponseStatus, request } from '../http'
import { Group, Me, User } from '../../types'
import join from 'join-path'
import { config } from '../../../config'

export const me = async ({ user }: { user: User }): Promise<Me> => {
const response = await request({
method: 'GET',
path: join('graph', 'v1.0', 'me'),
user
})

return await response.json()
}

export const createUser = async ({ user, admin }: { user: User; admin: User }): Promise<User> => {
const body = JSON.stringify({
displayName: user.displayName,
mail: user.email,
onPremisesSamAccountName: user.id,
passwordProfile: { password: user.password }
})

const response = await request({
method: 'POST',
path: join('graph', 'v1.0', 'users'),
body,
user: admin
})

checkResponseStatus(response, 'Failed while creating user')
return user
}

export const deleteUser = async ({ user, admin }: { user: User; admin: User }): Promise<User> => {
await request({
method: 'DELETE',
path: join('graph', 'v1.0', 'users', user.id),
user: admin
})

return user
}

const getUserId = async ({ user, admin }: { user: User; admin: User }): Promise<string> => {
let userId = ''
const response = await request({
method: 'GET',
path: join('graph', 'v1.0', 'users', user.id),
user: admin
})
if (response.ok) {
userId = (await response.json()).id
}
return userId
}

export const createGroup = async ({
group,
admin
}: {
group: Group
admin: User
}): Promise<Group> => {
const body = JSON.stringify({
displayName: group.displayName
})

const response = await request({
method: 'POST',
path: join('graph', 'v1.0', 'groups'),
body,
user: admin
})

checkResponseStatus(response, 'Failed while creating group')
return group
}

const getGroupId = async ({ group, admin }: { group: Group; admin: User }): Promise<string> => {
let groupId = ''
const response = await request({
method: 'GET',
path: join('graph', 'v1.0', 'groups', group.displayName),
user: admin
})
if (response.ok) {
groupId = (await response.json()).id
}
return groupId
}

export const deleteGroup = async ({
group,
admin
}: {
group: Group
admin: User
}): Promise<Group> => {
const groupId = await getGroupId({ group, admin })
await request({
method: 'DELETE',
path: join('graph', 'v1.0', 'groups', groupId),
user: admin
})
return group
}

export const addUserToGroup = async ({
user,
group,
admin
}: {
user: User
group: Group
admin: User
}): Promise<void> => {
const groupId = await getGroupId({ group, admin })
const userId = await getUserId({ user, admin })
const body = JSON.stringify({
'@odata.id': join(config.backendUrl, 'graph', 'v1.0', 'users', userId)
})

const response = await request({
method: 'POST',
path: join('graph', 'v1.0', 'groups', groupId, 'members', '$ref'),
body: body,
user: admin
})
checkResponseStatus(response, 'Failed while adding an user to the group')
}
2 changes: 1 addition & 1 deletion tests/e2e/support/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * as http from './http'
export * as user from './user'
export * as user from './userManagement'
export * as config from './config'
export * as settings from './settings'
export * as graph from './graph'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { checkResponseStatus, checkOCJsonStatus, request } from './http'
import { User } from '../types'
import { Group, User } from '../types'
import { URLSearchParams } from 'url'
import join from 'join-path'

Expand Down Expand Up @@ -68,3 +68,59 @@ export const getUser = async ({ user }: { user: User }): Promise<User> => {

return user
}

export const createGroup = async ({
group,
admin
}: {
group: Group
admin: User
}): Promise<Group> => {
const body = new URLSearchParams()
body.append('groupid', group.id)
const response = await request({
method: 'POST',
path: join('ocs', 'v2.php', 'cloud', 'groups'),
body: body,
user: admin
})
checkResponseStatus(response, 'Failed while creating group')
return group
}

export const deleteGroup = async ({
group,
admin
}: {
group: Group
admin: User
}): Promise<Group> => {
await request({
method: 'DELETE',
path: join('ocs', 'v2.php', 'cloud', 'groups', encodeURIComponent(group.id)),
user: admin
})

return group
}

export const addUserToGroup = async ({
user,
group,
admin
}: {
user: User
group: Group
admin: User
}): Promise<Group> => {
const body = new URLSearchParams()
body.append('groupid', group.id)
const response = await request({
method: 'POST',
path: join('ocs', 'v2.php', 'cloud', 'users', user.id, 'groups'),
body: body,
user: admin
})
checkResponseStatus(response, 'Failed while adding an user to the group')
return group
}
2 changes: 1 addition & 1 deletion tests/e2e/support/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export { ActorsEnvironment } from './actor'
export { FilesEnvironment } from './file'
export { LinksEnvironment } from './link'
export { SpacesEnvironment } from './space'
export { UsersEnvironment } from './user'
export { UsersEnvironment } from './userManagement'
Loading

0 comments on commit b924330

Please sign in to comment.