Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
02bd56b
Bump normalize-url from 4.5.0 to 4.5.1
dependabot[bot] Jun 11, 2021
a83b4c9
Bump dot-prop from 4.2.0 to 4.2.1
dependabot[bot] Aug 10, 2021
dba81aa
Bump path-parse from 1.0.6 to 1.0.7
dependabot[bot] Aug 10, 2021
f21ba06
Bump browserslist from 4.6.6 to 4.19.1
dependabot[bot] Jan 14, 2022
aa7367e
API changes for privacy policy
kamicut Jan 25, 2022
8e78c4c
Disable submits with consent box
kamicut Jan 25, 2022
63dcfaa
Styling
kamicut Jan 26, 2022
2bde780
styling
kamicut Jan 26, 2022
7323452
fix error handling in org model update
kamicut Jan 26, 2022
bf5cfb2
Bump cached-path-relative from 1.0.2 to 1.1.0
dependabot[bot] Jan 27, 2022
4d61b75
Bump undefsafe from 2.0.2 to 2.0.5
dependabot[bot] Feb 10, 2022
c94028d
Update development environment instructions
vgeorge Feb 15, 2022
c8081ff
Bump node-fetch from 2.6.6 to 2.6.7
dependabot[bot] Feb 15, 2022
8a78bb9
Bump trim-off-newlines from 1.0.1 to 1.0.3
dependabot[bot] Feb 15, 2022
48994c8
Bump ajv from 6.10.2 to 6.12.6
dependabot[bot] Feb 15, 2022
9eb6075
Use same PostgreSQL image on local dev and Circle CI
vgeorge Feb 16, 2022
6ee6a76
Upgrade Node.js version on CircleCI
vgeorge Feb 16, 2022
e1e591e
Always apply process.env.DATABASE_URL is present
vgeorge Feb 16, 2022
0690777
Merge pull request #244 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
7f3b3c5
Merge pull request #243 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
f7896fd
Merge pull request #242 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
8e7af3e
Merge pull request #239 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
b0dac3d
Merge pull request #235 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
8c8c515
Merge pull request #238 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
c01fe68
Merge pull request #224 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
7d743aa
Merge pull request #221 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
65dafb7
Bump ws from 6.2.1 to 6.2.2
dependabot[bot] Feb 17, 2022
a7aec22
Merge pull request #212 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
51a2140
Merge pull request #210 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 17, 2022
e3af0f3
Bump url-parse from 1.5.4 to 1.5.6
dependabot[bot] Feb 18, 2022
552c9fa
Merge pull request #246 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Feb 18, 2022
27a6a25
Merge branch 'develop' into fix/dev-instructions
vgeorge Feb 18, 2022
096c62f
Reintroduce DSN env var in knexfile
vgeorge Feb 18, 2022
d62d080
Revert changes to knexfile, fix hydra connection string
vgeorge Feb 18, 2022
02be2e6
Fix DATABASE_URL assignment
vgeorge Feb 18, 2022
275df13
User internal Docker network to connect Hydra to dev DB
vgeorge Feb 18, 2022
ee23017
Add badges migration and "create" route
vgeorge Feb 23, 2022
be2f5bf
Merge pull request #241 from developmentseed/fix/dev-instructions
vgeorge Feb 23, 2022
95ec074
Add patch route
vgeorge Mar 2, 2022
5fe4afa
Add patch route
vgeorge Mar 2, 2022
d8ccc70
Add delete and list routes
vgeorge Mar 2, 2022
fef23a4
Rename route
vgeorge Mar 2, 2022
21ef4e3
Add "assign badge" route
vgeorge Mar 2, 2022
2687ba1
Bump url-parse from 1.5.7 to 1.5.9
dependabot[bot] Mar 4, 2022
7f183a1
List user badges
vgeorge Mar 8, 2022
85aca1e
Update badge
vgeorge Mar 8, 2022
4f670d3
Remove user badge
vgeorge Mar 8, 2022
4dc498f
Drop tables and migrate before testing, not after
vgeorge Mar 8, 2022
cfc43a6
Merge pull request #251 from developmentseed/dependabot/npm_and_yarn/…
vgeorge Mar 8, 2022
befd0a5
Add badges table to organisation page
vgeorge Mar 11, 2022
e381c49
Add license
vgeorge Mar 11, 2022
346e861
Remove sandbox
vgeorge Mar 11, 2022
1b87113
Merge pull request #257 from developmentseed/enhance/add-license
kamicut Mar 11, 2022
9d82c27
Move route wrapper to utils file, add documentation header
vgeorge Mar 14, 2022
cc2fa4e
Merge pull request #247 from developmentseed/feature/badges
vgeorge Mar 14, 2022
1ae141d
Add badges page
vgeorge Mar 16, 2022
d88bd72
Add color input, cancel button to "add badge page
vgeorge Mar 17, 2022
a9d3e9c
Merge branch 'develop' into feature/badges-frontend
vgeorge Mar 17, 2022
365a26c
Add edit badge page
vgeorge Mar 17, 2022
9b85d07
Add initial key type for profile attributes
kamicut Mar 23, 2022
598978d
Add react toast
vgeorge Mar 23, 2022
bc953bf
Add delete badge button
vgeorge Mar 23, 2022
5707fa3
Render colors at badges table
vgeorge Mar 23, 2022
f805176
Add delete confirmation
vgeorge Mar 23, 2022
af8a283
Add attribute validation to form
kamicut Mar 23, 2022
25fc019
remove unnecessary import
kamicut Mar 23, 2022
2081aaa
Merge branch 'develop' into feature/form-validation
kamicut Mar 28, 2022
24015a5
fix integrity checksums
kamicut Mar 28, 2022
9e86ef5
Fix migration
vgeorge Mar 28, 2022
7f13b01
Add assignment section to badge page
vgeorge Mar 28, 2022
4274860
add gender select field
kamicut Mar 30, 2022
bdb8a23
Add descriptive label
kamicut Mar 30, 2022
33144dc
Fix redirection after org is created
vgeorge Apr 1, 2022
cb1b163
Connect assigned members at badge page
vgeorge Apr 1, 2022
dea2ac7
Do not change hover styles if table isn't clicable
vgeorge Apr 1, 2022
c03cd04
Check if user is part of organization before badge assignment
vgeorge Apr 1, 2022
01a477e
Use plural for consistency
vgeorge Apr 1, 2022
8e9f2ab
Fix test route
vgeorge Apr 1, 2022
7b57583
Make badges assignment unique
vgeorge Apr 1, 2022
ed4dbc7
fix spacing
vgeorge Apr 1, 2022
841fc72
Lint
vgeorge Apr 5, 2022
49f6737
Add type column to team profile
vgeorge Apr 5, 2022
f059ede
fix for null field value
kamicut Apr 5, 2022
7c4e7ed
Make loading div better positioned
vgeorge Apr 5, 2022
d69008d
Merge branch 'feature/form-validation' of github.com:developmentseed/…
kamicut Apr 5, 2022
bfc7245
Merge branch 'feature/form-validation' of github.com:developmentseed/…
kamicut Apr 5, 2022
a0366a3
Add empty state to table component
vgeorge Apr 5, 2022
b85cef2
better formatting
vgeorge Apr 5, 2022
de32b12
Display loading state on both tables in org page
vgeorge Apr 5, 2022
2c60733
Resolve display names from OSM API instead of users table
vgeorge Apr 7, 2022
5b3e0f0
Do not render badges section if user doesn't have privileges
vgeorge Apr 11, 2022
759c366
Merge pull request #256 from developmentseed/feature/badges-frontend
vgeorge Apr 11, 2022
1616770
Add badge assignenmnt page
vgeorge Apr 11, 2022
db29bc7
Fix cancel button
vgeorge Apr 11, 2022
6f7f557
Improve buttons, make table clickable
vgeorge Apr 11, 2022
08f6edf
Fix assignment for new members
vgeorge Apr 11, 2022
85f060e
Fix test
vgeorge Apr 12, 2022
0636c98
Update label, fix error message
vgeorge Apr 12, 2022
0051b7b
Merge pull request #263 from developmentseed/enhance/edit-badge-assig…
vgeorge Apr 12, 2022
bab05c3
Merge pull request #261 from developmentseed/enhance/table-empty-state
vgeorge Apr 12, 2022
b4de54f
change header key to match develop
kamicut Apr 14, 2022
5144a19
Merge branch 'develop' into feature/form-validation
kamicut Apr 14, 2022
1b7bd15
Merge pull request #259 from developmentseed/feature/form-validation
kamicut Apr 14, 2022
6066647
initial invite link structure
kamicut Apr 15, 2022
a69b6bf
Add "assign a badge" action to profile, allow badge unassignment
vgeorge Apr 20, 2022
05778ec
Allow add/remove badge from oneself
vgeorge Apr 20, 2022
e366227
Merge pull request #265 from developmentseed/enhance/badge-assignment
vgeorge Apr 21, 2022
c1512de
fix login profile bug
kamicut Apr 22, 2022
fdf8553
Lint
vgeorge Apr 27, 2022
ef0a1d7
more lint
vgeorge Apr 27, 2022
d9ddc32
Fetch and display badges in org profile modal
vgeorge Apr 28, 2022
4067a0c
Disable badge assignment by osm id
vgeorge Apr 29, 2022
75027de
Display empty table message when a badge has no members assigned.
vgeorge Apr 29, 2022
96639fe
Merge pull request #266 from developmentseed/feature/invite-links
kamicut Apr 29, 2022
a35cc1d
Merge pull request #267 from developmentseed/fix/profile-merge-bug
kamicut Apr 29, 2022
0eb74fb
Create separated pages for badge assignments actions (new/edit)
vgeorge Apr 29, 2022
48676e2
lint
vgeorge Apr 29, 2022
85ad8eb
Enforce server timezone to UTC
vgeorge Apr 29, 2022
04551c9
Display better error message when the user already has the badge
vgeorge Apr 29, 2022
b7cf630
Fix conditional
kamicut Apr 29, 2022
1406af4
Merge pull request #269 from developmentseed/enhance/display-profile-…
vgeorge Apr 29, 2022
ac9f4c0
remove stray console.log
vgeorge Apr 29, 2022
c74a646
Handle API and Web requests errors differently
vgeorge May 2, 2022
46b6be4
Merge branch 'develop' into feature/org-privacy-policy
kamicut May 5, 2022
26283a1
Fix profile form
kamicut May 5, 2022
c47459f
Remove create modal
kamicut May 5, 2022
8376995
Fix button on team page
kamicut May 5, 2022
fadeefe
Remove unnecessary imports
kamicut May 5, 2022
bcfe9a7
Fix UI for owner
kamicut May 5, 2022
ab2eb42
Fix for org/teams API permissions
kamicut May 5, 2022
325f1b5
Do not return JSON for webpage errors
vgeorge May 6, 2022
a4918dc
Make middleware to throw forbidden error
vgeorge May 6, 2022
fc9bd24
Merge pull request #276 from developmentseed/feature/org-privacy-policy
kamicut May 6, 2022
b41060b
Merge pull request #277 from developmentseed/fix/owner-team-ui
kamicut May 6, 2022
5b9298d
Merge pull request #278 from developmentseed/fix/org-team-api-permiss…
kamicut May 6, 2022
5f1ee0a
remove beta banner
kamicut May 6, 2022
13e2224
make session cookies last for browser session
kamicut May 6, 2022
efbe97e
Fix uh oh message
kamicut May 6, 2022
046c751
Merge pull request #272 from developmentseed/fix/error-handling-middl…
vgeorge May 6, 2022
b492869
lintfix
vgeorge May 6, 2022
5bbded2
Merge pull request #280 from developmentseed/feature/remove-beta-banner
vgeorge May 6, 2022
85c07c5
Fix owner of team able to view its members
kamicut May 6, 2022
a6ffc3c
Fix invitation link permission
kamicut May 6, 2022
4641dd4
Merge pull request #281 from developmentseed/fix/permissions-fixes
kamicut May 6, 2022
cad391d
Use '/profiles/keys/team/:id' instead of 'profiles/keys/organizations…
vgeorge Nov 7, 2022
bfdb84c
Add new permission
kamicut Nov 9, 2022
f06ebc8
change permission for orgTeamAttributes call
kamicut Nov 9, 2022
b95e96b
change editTeam form
kamicut Nov 9, 2022
d382fe1
Merge pull request #300 from developmentseed/fix/moderator-access-to-…
kamicut Nov 11, 2022
8f8b6f5
create code guard for empty data
kamicut Nov 11, 2022
69c21d5
Merge pull request #305 from developmentseed/fix/285-empty-data
kamicut Nov 14, 2022
fdd5ffd
1.7.0
kamicut Nov 15, 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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/node:12.16
- image: circleci/node:14

environment:
DATABASE_URL: postgres://postgres@localhost/osm-teams-test
Expand Down
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OSM_CONSUMER_KEY=<osm-consumer-key>
OSM_CONSUMER_SECRET=<osm-consumer-secret>
DSN=postgres://postgres@host.docker.internal/osm-teams?sslmode=disable
DSN=postgres://postgres@dev-db/osm-teams?sslmode=disable
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ node_modules.nosync
.idea
hydra-config/prod/prod.yml
.nyc_output
coverage
coverage
docker-data/*
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v12.16
14
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:lts
FROM node:14

# Create app directory
WORKDIR /usr/src/app
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Development Seed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
61 changes: 27 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,30 @@
Check the beta 👉 <!-- markdownlint-disable MD034 -->https://mapping.team
<!-- markdownlint-enable MD034 -->

## Development

## Installation
Install requirements:

### Requirements
- [nvm](https://github.com/creationix/nvm)
- [Docker](https://www.docker.com)

- [PostgreSQL](https://www.postgresql.org). On OS X, the easiest is to install [Postgres.app](https://postgresapp.com/).
- [Node.js](https://nodejs.org) v12.16+
- [Docker](https://www.docker.com/) & Docker Compose
Visit your [OpenStreetMap settings](https://www.openstreetmap.org/account/edit) page and register an OAuth1 Client App:

### Setting up Hydra
![OSM Client App](oauth1-osm-client-app.png "OAuth1 page at OSM Website")

1. Create the database for tokens

```bash
createdb osm-teams
createdb osm-teams-test
```

For the rest of this documentation, we will assume that the database location is `postgres://postgres@localhost/osm-teams?sslmode=disable` on your local machine. Inside docker, that location is `postgres://postgres@host.docker.internal/osm-teams?sslmode=disable`

1. Create an `.env` file by copying `.env.sample` and replacing the values as needed. `OSM_CONSUMER_KEY` and `OSM_CONSUMER_SECRET` are values obtained by creating a new OAuth app on openstreetmap.org. The .env file can contain:
Create an `.env` file by copying `.env.sample` and replacing the values as needed. `OSM_CONSUMER_KEY` and `OSM_CONSUMER_SECRET` are values available at the OAuth app page on openstreetmap.org. The .env file should contain:

```bash
OSM_CONSUMER_KEY=<osm-teams-app>
OSM_CONSUMER_SECRET=<osm-teams-app-secret>
DSN=postgres://postgres@host.docker.internal/osm-teams?sslmode=disable
```

1. Build the docker images:

```bash
docker-compose -f compose.yml build
```

1. Start Hydra and the server

```bash
docker-compose -f compose.yml -f compose.dev.yml up
DSN=postgres://postgres@dev-db/osm-teams?sslmode=disable
```

⚠️ In development, `docker-compose -f compose.yml -f compose.dev.yml up` enables hot module reloading while you make modifications to the code. `docker-compose up` should be used for production/staging deployments.

This will start hydra where the token issuer is at `http://localhost:4444` and the admin interface is at `http://localhost:4445`. This also sets up the consent and login interface at `http://localhost:8989` (where we will create a first-party oauth app)
Start Hydra and PostgreSQL with Docker:

### Setting up the OSM-teams app
docker-compose -f compose.dev.yml up --build

Create the [first-party](https://auth0.com/docs/applications/concepts/app-types-first-third-party) "manage" app
On a separate terminal, create the [first-party](https://auth0.com/docs/applications/concepts/app-types-first-third-party) "manage" app:

```bash
docker-compose exec hydra hydra clients create --endpoint http://localhost:4445 \
Expand All @@ -74,6 +51,22 @@ docker-compose exec hydra hydra clients create --endpoint http://localhost:4445
--callbacks http://localhost:8989/login/accept
```

Install Node.js the required version (see [.nvmrc](.nvmrc) file):

nvm i

Install Node.js modules:

yarn

Migrate `dev-db` database:

yarn migrate

Start development server:

yarn dev

<!-- markdownlint-disable MD034 -->
✨ You can now login to the app at http://localhost:8989
<!-- markdownlint-enable MD034 -->
Expand Down
18 changes: 7 additions & 11 deletions app/db/knexfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
let DATABASE_URL
let DATABASE_URL = process.env.DSN || process.env.DATABASE_URL

if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'development'
}

if (process.env.DSN) {
DATABASE_URL = process.env.DSN
} else {
if (process.env.NODE_ENV === 'development') {
DATABASE_URL = 'postgres://postgres@localhost/osm-teams?sslmode=disable'
// Apply defaults if no connection string is passed
if (!DATABASE_URL) {
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
DATABASE_URL =
'postgres://postgres:postgres@localhost:5433/osm-teams?sslmode=disable'
} else if (process.env.NODE_ENV === 'test') {
DATABASE_URL = 'postgres://postgres@localhost/osm-teams-test?sslmode=disable'
DATABASE_URL = 'postgres://postgres:postgres@localhost:5434/osm-teams-test?sslmode=disable'
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/db/migrations/20220125220402_org-privacy-policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

exports.up = async function (knex) {
await knex.schema.alterTable('organization', table => {
table.json('privacy_policy')
})
}

exports.down = async function (knex) {
await knex.schema.alterTable('organization', table => {
table.dropColumn('privacy_policy')
})
}
16 changes: 16 additions & 0 deletions app/db/migrations/20220222155039_add_badges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exports.up = async function (knex) {
await knex.schema.createTable('organization_badge', (table) => {
table.increments('id')
table
.integer('organization_id')
.references('id')
.inTable('organization')
.onDelete('CASCADE')
table.string('name').notNullable()
table.string('color').notNullable()
})
}

exports.down = async function (knex) {
await knex.schema.dropTable('organization_badge')
}
17 changes: 17 additions & 0 deletions app/db/migrations/20220302104250_add_user_badges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
exports.up = async function (knex) {
await knex.schema.createTable('user_badges', (table) => {
table
.integer('badge_id')
.references('id')
.inTable('organization_badge')
.onDelete('CASCADE')
table.integer('user_id')
table.datetime('assigned_at').defaultTo(knex.fn.now())
table.datetime('valid_until')
table.unique(['badge_id', 'user_id'])
})
}

exports.down = async function (knex) {
await knex.schema.dropTable('user_badges')
}
11 changes: 11 additions & 0 deletions app/db/migrations/20220302135223_key-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.up = async (knex) => {
return knex.schema.alterTable('profile_keys', table => {
table.text('key_type').defaultTo('text')
})
}

exports.down = async (knex) => {
return knex.schema.alterTable('profile_keys', table => {
table.dropColumn('key_type')
})
}
13 changes: 13 additions & 0 deletions app/db/migrations/20220415114820_invitations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

exports.up = async function (knex) {
return knex.schema.createTable('invitations', table => {
table.string('id')
table.integer('team_id').references('id').inTable('team').onDelete('CASCADE')
table.timestamp('created_at').defaultTo(knex.fn.now())
table.timestamp('expires_at').nullable()
})
}

exports.down = async function (knex) {
return knex.schema.dropTable('invitations')
}
6 changes: 6 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Set server timezone to UTC to avoid issues with date parsing
process.env.TZ = 'UTC'

const path = require('path')
const express = require('express')
const bodyParser = require('body-parser')
Expand Down Expand Up @@ -55,6 +58,9 @@ async function init () {
* Error handler
*/
app.use(function (err, req, res, next) {
if (err.message === 'Forbidden') {
return nextApp.render(req, res, '/uh-oh')
}
res.status(err.status || 500)
console.error('error', err)
res.boom.internal('An internal error occurred.')
Expand Down
23 changes: 20 additions & 3 deletions app/lib/organization.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const db = require('../db')
const team = require('./team')
const { map, prop, includes } = require('ramda')
const { map, prop, includes, has, isNil } = require('ramda')
const { unpack, PropertyRequiredError } = require('./utils')

// Organization attributes (without profile)
Expand All @@ -10,6 +10,7 @@ const orgAttributes = [
'description',
'privacy',
'teams_can_be_public',
'privacy_policy',
'created_at',
'updated_at'
]
Expand Down Expand Up @@ -113,9 +114,10 @@ async function destroy (id) {
* @return {promise}
*/
async function update (id, data) {
if (!data.name) throw new Error('data.name property is required')

const conn = await db()
if (has('name', data) && isNil(prop('name', data))) {
throw new Error('data.name property is required')
}
return unpack(conn('organization').where('id', id).update(data).returning(orgAttributes))
}

Expand Down Expand Up @@ -263,6 +265,20 @@ async function isMemberOrStaff (organizationId, osmId) {
return result.length > 0
}

/**
* Checks if an osmId is a moderator of any team inside the org
* @param {int} organizationId - organization id
* @param {int} osmId - id of member we are testing
*/
async function isOrgTeamModerator (organizationId, osmId) {
if (!organizationId) throw new PropertyRequiredError('organization id')
if (!osmId) throw new PropertyRequiredError('osm id')
const conn = await db()
const subquery = conn('organization_team').select('team_id').where('organization_id', organizationId)
const isModeratorOfAny = await conn('moderator').whereIn('team_id', subquery).debug()
return isModeratorOfAny.length > 0
}

/**
* Checks if the osm user is an owner of a team
* @param {int} organizationId - organization id
Expand Down Expand Up @@ -348,6 +364,7 @@ module.exports = {
isOwner,
isManager,
isMember,
isOrgTeamModerator,
createOrgTeam,
listMyOrganizations,
getOrgStaff,
Expand Down
6 changes: 4 additions & 2 deletions app/lib/osm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Route middleware to interact with OSM OAuth
*/
const passport = require('passport-light')
const R = require('ramda')
const hydra = require('./hydra')
const url = require('url')
const db = require('../db')
Expand Down Expand Up @@ -55,11 +56,12 @@ function openstreetmap (req, res) {
let conn = await db()
let [user] = await conn('users').where('id', profile.id)
if (user) {
const newProfile = R.mergeDeepRight(user.profile, profile)
await conn('users').where('id', profile.id).update(
{
'osmToken': token,
'osmTokenSecret': tokenSecret,
'profile': JSON.stringify(profile)
'profile': JSON.stringify(newProfile)
}
)
} else {
Expand All @@ -83,7 +85,7 @@ function openstreetmap (req, res) {
hydra.acceptLoginRequest(challenge, {
subject: user.id,
remember: true,
remember_for: 9999
remember_for: 0
}).then(response => {
if (response.redirect_to) {
return res.redirect(response.redirect_to)
Expand Down
22 changes: 21 additions & 1 deletion app/lib/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,25 @@ async function getUserManageToken (id) {
return unpack(conn('users').select('manageToken').where('id', id).debug())
}

async function getUserBadges (id) {
const conn = await db()
return conn('user_badges')
.select([
'id',
'assigned_at',
'valid_until',
'organization_id',
'name',
'color'
])
.leftJoin(
'organization_badge',
'user_badges.badge_id',
'organization_badge.id'
)
.where('user_badges.user_id', id)
}

module.exports = {
addProfileKeys,
modifyProfileKey,
Expand All @@ -263,5 +282,6 @@ module.exports = {
setProfile,
getProfile,
getTableForProfileType,
getUserManageToken
getUserManageToken,
getUserBadges
}
Loading