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

Add pagination to organization page #353

Merged
merged 25 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
602ac4c
Add function to generate zero-padded numbers for consistent sorting
vgeorge Dec 19, 2022
8888968
Refactor and connect org team members table at org page
vgeorge Dec 19, 2022
873d6d9
Add log level instructions to README
vgeorge Dec 19, 2022
d7bb073
Populate staff table
vgeorge Dec 19, 2022
54c00dd
Simplify Organization.getOrgStaff() method
vgeorge Dec 20, 2022
86beef4
Populate staff table
vgeorge Dec 20, 2022
347cb4a
Merge branch 'develop' into add/user-tables
vgeorge Dec 21, 2022
ac1eb33
Fix seed data
vgeorge Dec 21, 2022
9cb5615
Create a folder for organizations-related Cypress specs
vgeorge Dec 21, 2022
bfe7a04
Add permissions spec
vgeorge Dec 21, 2022
c64ff9c
Fix staff spec
vgeorge Dec 21, 2022
9a0509d
Remove deprecated pagination buttons
vgeorge Dec 21, 2022
14a467a
Non-member cannot view private organization
vgeorge Dec 21, 2022
8fc5d2e
Remove deprecated dockerfile
vgeorge Dec 21, 2022
f703b08
Open Cypress e2e mode by default when running 'yarn e2e:dev'
vgeorge Dec 21, 2022
b4a9e03
Add canViewOrgTeams middleware, improve test coverage
vgeorge Dec 21, 2022
87bb35d
Fix docs
vgeorge Dec 21, 2022
53fa87b
Reinstate Team.list as in version1, add Team.paginatedList to avoid b…
vgeorge Dec 22, 2022
38567f2
Revert API changes in Organization Model, add pagination as separate …
vgeorge Dec 22, 2022
0498621
Lint fix
vgeorge Dec 22, 2022
dab95b2
Fix team page data loading
vgeorge Dec 22, 2022
c478435
Check if session is available before getting userId
vgeorge Dec 22, 2022
58d7a12
Fix org page actions
vgeorge Dec 22, 2022
542ca63
Fix webkit-specific overflow property
LanesGood Dec 22, 2022
bfe62c6
quick fix bug in badge page
kamicut Dec 23, 2022
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
18 changes: 0 additions & 18 deletions Dockerfile

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Start development server:
yarn dev

<!-- markdownlint-disable MD034 -->

✨ You can now login to the app at http://127.0.0.1:3000

<!-- markdownlint-enable MD034 -->

## Testing
Expand All @@ -59,6 +61,8 @@ To open Cypress dashboard for interactive development:

yarn e2e:dev

By default, logging level in testing environment is set to 'silent'. Please refer to pino docs for the full [list of log levels](https://getpino.io/#/docs/api?id=level-string).

## API

The API docs can be accessed at <http://127.0.0.1:3000/docs/api>.
Expand Down
12 changes: 0 additions & 12 deletions app/manage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const {
removeOwner,
addManager,
removeManager,
getOrgMembers,
listMyOrgs,
getOrgStaff,
} = require('./organizations')

const {
Expand Down Expand Up @@ -123,16 +121,6 @@ function manageRouter(handler) {
handler.get('/api/organizations/:id', can('public:authenticated'), getOrg)
handler.put('/api/organizations/:id', can('organization:edit'), updateOrg)
handler.delete('/api/organizations/:id', can('organization:edit'), destroyOrg)
handler.get(
'/api/organizations/:id/staff',
can('organization:view-members'),
getOrgStaff
)
handler.get(
'/api/organizations/:id/members',
can('organization:view-members'),
getOrgMembers
)

handler.put(
'/api/organizations/:id/addOwner/:osmId',
Expand Down
67 changes: 8 additions & 59 deletions app/manage/organizations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const organization = require('../../src/models/organization')
const team = require('../../src/models/team')
const { map, prop } = require('ramda')
const Boom = require('@hapi/boom')

/**
Expand Down Expand Up @@ -47,65 +45,18 @@ async function getOrg(req, reply) {
throw Boom.badRequest('organization id is required')
}

let [data, isMemberOfOrg] = await Promise.all([
let [data, isMember, isManager, isOwner] = await Promise.all([
organization.get(id),
organization.isMember(id, user_id),
organization.isManager(id, user_id),
organization.isOwner(id, user_id),
])
reply.send({ ...data, isMemberOfOrg })
}

/**
* Get an organization's staff
* Requires id of organization
*/
async function getOrgStaff(req, reply) {
const { id } = req.params

if (!id) {
throw Boom.badRequest('organization id is required')
}

try {
let [owners, managers] = await Promise.all([
organization.getOwners(id),
organization.getManagers(id),
])
const ownerIds = map(prop('osm_id'), owners)
const managerIds = map(prop('osm_id'), managers)
if (ownerIds.length > 0) {
owners = await team.resolveMemberNames(ownerIds)
}
if (managerIds.length > 0) {
managers = await team.resolveMemberNames(managerIds)
}

reply.send({ owners, managers })
} catch (err) {
console.log(err)
throw Boom.badRequest(err.message)
}
}

async function getOrgMembers(req, reply) {
const { id } = req.params

if (!id) {
throw Boom.badRequest('organization id is required')
}

let { page } = req.query

try {
let members = await organization.getMembers(id, page)
const memberIds = map(prop('osm_id'), members)
if (memberIds.length > 0) {
members = await team.resolveMemberNames(memberIds)
}

reply.send({ members, page })
} catch (err) {
console.log(err)
throw Boom.badRequest(err.message)
// User needs to be member or staff to access a private org
if (data?.privacy === 'private' && !isMember && !isManager && !isOwner) {
throw Boom.unauthorized()
} else {
reply.send({ ...data, isMember, isManager, isOwner })
}
}

Expand Down Expand Up @@ -246,6 +197,4 @@ module.exports = {
addManager,
removeManager,
listMyOrgs,
getOrgStaff,
getOrgMembers,
}
1 change: 0 additions & 1 deletion app/manage/permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const teamPermissions = {
const organizationPermissions = {
'organization:edit': require('./edit-org'),
'organization:member': require('./member-org'),
'organization:view-members': require('./view-org-members'),
'organization:view-team-keys': require('./view-org-team-keys'),
}

Expand Down
27 changes: 0 additions & 27 deletions app/manage/permissions/view-org-members.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/manage/profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async function getTeamProfile(req, reply) {
const { user_id: requesterId } = req.session

if (!teamId) {
reply.boom.badRequest('teamId is required parameter')
return reply.boom.badRequest('teamId is required parameter')
}

// try {
Expand Down
1 change: 0 additions & 1 deletion app/manage/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async function listTeams(req, reply) {
const data = await team.list({
osmId,
bbox: bounds,
disablePagination: true,
})
const enhancedData = await teamsMembersModeratorsHelper(data)
reply.send(enhancedData)
Expand Down
47 changes: 37 additions & 10 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = defineConfig({
'db:reset': async () => {
await db.raw('TRUNCATE TABLE team RESTART IDENTITY CASCADE')
await db.raw('TRUNCATE TABLE organization RESTART IDENTITY CASCADE')
await db.raw('TRUNCATE TABLE users RESTART IDENTITY CASCADE')
await db.raw('TRUNCATE TABLE osm_users RESTART IDENTITY CASCADE')
return null
},
'db:seed': async () => {
Expand Down Expand Up @@ -52,22 +54,47 @@ module.exports = defineConfig({
}
return null
},
'db:seed:add-members-to-team': async ({ teamId, members }) => {
for (let i = 0; i < members.length; i++) {
const member = members[i]
await Team.addMember(teamId, member.id)
}
return null
},
'db:seed:team-invitations': async (teamInvitations) => {
return Promise.all(teamInvitations.map(TeamInvitation.create))
},
'db:seed:organizations': async (orgs) => {
return Promise.all(
orgs.map((org) =>
Organization.create(pick(['name'], org), org.ownerId)
'db:seed:add-organizations': async (orgs) => {
for (let i = 0; i < orgs.length; i++) {
const org = orgs[i]
await Organization.create(
pick(['name', 'privacy'], org),
org.ownerId
)
)
}
return null
},
'db:seed:organization-teams': async ({ orgId, teams, managerId }) => {
return Promise.all(
teams.map((team) =>
Organization.createOrgTeam(orgId, pick(['name'], team), managerId)
'db:seed:add-organization-teams': async ({
orgId,
teams,
managerId,
}) => {
for (let i = 0; i < teams.length; i++) {
const team = teams[i]
await Organization.createOrgTeam(
orgId,
pick(['id', 'name', 'privacy'], team),
managerId
)
)
}
return null
},
'db:seed:add-organization-managers': async ({ orgId, managerIds }) => {
for (let i = 0; i < managerIds.length; i++) {
const managerId = managerIds[i]
await Organization.addManager(orgId, managerId)
}
return null
},
})
},
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/auth.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Check protected routes', () => {
// Authorized visit, should redirect to sign in
cy.login({
id: 1,
display_name: 'User 1',
display_name: 'User 001',
})
cy.visit(testRoute)
cy.get('body').should('not.contain', 'Sign in')
Expand Down
85 changes: 0 additions & 85 deletions cypress/e2e/organizations.cy.js

This file was deleted.

Loading