Giter VIP home page Giter VIP logo

cboard-api's Introduction

Cboard API - REST API for Cboard application

cboard-org

Cboard is an augmentative and alternative communication (AAC) web application, allowing users with speech and language impairments (autism, cerebral palsy) to communicate by symbols and text-to-speech. This repo supports the Cboard front-end, providing backend functionality and persistence.

Learn more about the Cboard project.

Pre-requisites

Before installing and running the Cboard API, be sure you have locally installed the following tools:

  • Node.js: see the .nvmrc file for the exact version.
  • MongoDB > 4.0.0 (download here)

To make sure that the Node version you use for local development is the same the deployed server uses, we recommend using the nvm tool, which simplifies version management. It automatically installs the version listed in the .nvmrc file when you do nvm install.

Use the following commands to check that you have them successfully installed, and/or to double-check your versions:

  • node -v
  • mongo --version

Install

Clone the repository and install dependencies:

$ git clone https://github.com/cboard-org/cboard-api.git
$ cd cboard-api
$ nvm install
$ npm install -g yarn
$ yarn install

Start the database

Start MongoDB. (See MongoDB docs, if needed).

$ mongod

Configure environment variables

The Cboard API is a cloud service, and it needs access to several cloud services as well, like user authentication, email sending, etc. This is all configured using environment variables on the platform the API is running. Following are the mandatory variables to be defined:

  • AZURE_STORAGE_CONNECTION_STRING
  • FACEBOOK_APP_ID
  • FACEBOOK_APP_SECRET
  • FACEBOOK_CALLBACK_URL
  • GCLOUD_PROJECT
  • GOOGLE_APP_ID
  • GOOGLE_APP_SECRET
  • GOOGLE_APPLICATION_CREDENTIALS
  • GOOGLE_CALLBACK_URL
  • JWT_SECRET
  • MONGO_URL
  • REACT_APP_DEV_API_URL
  • SENDGRID_API_KEY

Run the API Server

In a separate terminal tab/window, run the project server.

$ npm run dev 

For automatically restarting the server when file changes in the directory are detected

or

$ npm run start

Both of them start a server process listening on port 10010. You will now be able to make calls to the API.

(If you are having trouble, make sure you have successfully installed the pre-requisites -- see "Pre-requisites" section above.)

See API Paths

Swagger provides an interactive, browser-based editor. To visualize available API endpoints:

$ localhost:10010/docs/

That show API swagger editor (as shown below):

Cboard API Swagger

Mailing system configuration

When a new user is created using the API, some verification emails are generated. To use a specific SMPT server, locally edit the following file to use values for an SMTP server you own: config/env/development.js And look for following config block:

    emailTransport: {
        from: '[email protected]',
        host: 'smtp.sendgrid.net',
        port: 465,
        secure: true,
        service: 'Sendgrid',
        auth: {
            user: 'apikey',
            pass: process.env.SENDGRID_API_KEY
        }
    }

Testing

There are two types of tests in the repository, that can help you with the development and the debugging of the api service:

  • Postman tests
  • Mocha tests

Postman tests

Postman is a scalable API testing tool, and we mainly use it for debugging and testing during the development process. These tests are loocated under the following folder:

cboard-api/test/postman

There, you can find a postman collection file. This file can be imported as a new collection into Postman and you will see a list of requests and tests that you can use to exercise the cboard API. Note: you will need a deployed and well configured cboard-api instance running on your server to execute the tests against to.

Cboard API Postman

Mocha Tests

Mocha is a javascript framework for Node.js which allows Asynchronous testing. We have developed a few Mocha test suites that are running everytime a new Pull Request is created / updated. The goal of these tests is to verify that all of the api calls are functional and you are not introducing regression bugs into the code base. The command to run the Mocha tests is simply:

npm test 

License

Code - GPLv3
Symbols - CC BY-SA

cboard-api's People

Contributors

arthurdenner avatar dependabot[bot] avatar karenhaag avatar lutangar avatar martinbedouret avatar maxicapodacqua avatar nous- avatar rodrisanchez1 avatar shayc avatar snyk-bot avatar sylvansson avatar tinchodipalma avatar tomivm avatar zachi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cboard-api's Issues

Obtain the geolocation of users

Get geolocation of users and send it to cboard API.

RESOURCES

based on these Articles:
https://www.softwaretestinghelp.com/best-ip-geolocation-api/
https://stackoverflow.com/a/35123097
Consider the uses of the following resources:

  1. https://www.geoplugin.com
    prices to get SSL: https://www.geoplugin.com/webservices/ssl

๐Ÿ‘

  • Free Acces without a token.
  • High precision of city.

๐Ÿ‘Ž

  • No SSL connection without a paid account
  1. https://geolocation-db.com

๐Ÿ‘

  • Free Acces without a token.
  • SSL connection without a paid account

๐Ÿ‘Ž

  • Low precision of city.
  1. https://ipdata.co/
    prices: https://ipdata.co/pricing.html

๐Ÿ‘

  • 1500 free requests daily with a token. (should be stored on API)
  • SSL connection with a free account
  • High precision of city.

๐Ÿ‘Ž

  • is necessary a token that should be stored on our API.
  1. https://ip-api.com/
    Commercial use prices https://members.ip-api.com/#pricing

๐Ÿ‘

  • 1500 free requests daily with a token. (should be stored on API)
  • SSL connection with a free account
  • High precision of city.

๐Ÿ‘Ž

  • Non-commercial use for free.
  • No SSL connection without a paid account.

When should store data?

-Should store the location when a Cboard user creates a new account.
-In the case that users that already have accounts should evaluate when make the requests.
Consider checking if the location is available at a login moment. Compare if it is available to make the request or not

Development of unit tests for the user controller

The goal is to develop a new suite of unit tests to check the following controller:
cboard-api\api\controllers\user.js
Use the following test suite as an example of what we have to do:
cboard-api\test\controllers\board.js

Check the Readme file to understand how to run the unit tests.
Here you have a tutorial on how to develop nodejs and express unit tests: https://medium.com/@ehtemam/writing-test-with-supertest-and-mocha-for-expressjs-routes-555d2910d2c2

As a non-admin user, I shouldn't be able to delete another user's board

The deleteBoard route currently allows callers to delete boards owned by another user, even if the caller is not an admin.

Acceptance criteria

  • A non-admin user gets a 404 if they try to delete another user's board.
  • An admin can delete any board.
  • The tests added in #174 are not skipped and are passing.

Update status attribute on subscriber

When a subscription is validated, the status attribute on subscriber controller is not beeing updated. The value, that status will have its the same than transaction.subscriptionState

image

As a non-admin user, I shouldn't be able to update another user

The updateUser route is available to both admin and regular users. However, regular users are able to update any user and any field. This means that they can give themselves the admin role, take away another admin's privileges, change someone's email address, etc. This is a critical issue.

Acceptance criteria

  • A non-admin user gets a 403 if they try to update another user.
  • We can only update a subset of fields. Additional properties are simply ignored. Currently, the frontend only supports updating name, email, and birthdate.

Logger for cboard-api

I don't have enough knowledge in order to provide details here. Open to suggestions for everyone that wants to collaborate.

Session secret hard-coded into app.js?

Hi! I was just looking throughapp.js and noticed the following in it, around line 29:

  //use sessions for tracking logins
  app.use(
    session({
      secret: 'work hard',
      resave: true,
      saveUninitialized: false,
      store: new MongoStore({
        mongooseConnection: db
      })
    })
  );

The session secret is hard-coded to 'work hard'... I'm not sure what the full scope of your user sessions is, but I'm curious if this could lead to any kind of security vulnerabilities. Either way, it might be useful to either change (e.g. by pulling the secret from an environment variable) or document in a comment!

Update code to write all config info under env/ path

We want to have following structure for config:

-- config
---- env
--------development.js
--------production.js
--------xxxx.js
---- index.js

Any env value should be available in code by doing:

var config = require('./config');
var value = config.anyConfigValue

And server must be run using the right env variable:

NODE_ENV=production swagger project start

I should be able to change my email without losing access to my data

The schemas for communicators and boards currently use the email field to identify the owner. This is problematic because a user loses access to their communicators and boards if they change their email address. A simple solution would be to update the documents when needed, but it would be preferable to use a stable identifier like the user id.

Suggested approach

  • Add a userId field to the Communicator and Board schemas. Migrate existing documents.
  • Update the listCommunicators and listBoards routes to only return the caller's communicators and boards. The user id should be taken from the token rather than passed explicitly by the caller. The frontend would need to be updated to use these routes instead of the /byemail versions.
  • Update the getCommunicatorsEmail and getBoardsEmail routes to return a 403 if a non-admin user sends the wrong email address. There would be no restriction for admins. Ideally we would only let admins call the routes, but we need to do this so that users with an older version of the app don't have to update.

@martinbedouret Does this make sense?

it's possible change a password without owning the account.

it's possible to change the password of any account only with post an email on user/forgot and using the id of the user on user/store-password
image
Not only that, when post to /user/forgot endpoint is sending the private token in the response.
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.