Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into regr…
Browse files Browse the repository at this point in the history
…ession/status-color

* 'develop' of github.com:RocketChat/Rocket.Chat:
  [IMPROVE] Remove index files from action-links, accounts and assets (#17607)
  [FIX] Remove a non working setting "Notification Duration" (#15737)
  Update Apps-Engine version (#17706)
  Regression: Click to join button not working (#17705)
  [IMPROVE] Always shows the exact match first on user's and room's autocomplete for mentions and on sidebar search (#16394)
  [NEW] API endpoint to fetch Omnichannel's room transfer history (#17694)
  Fix typo "You aren't part of any channel yet" (#17498)
  [IMPROVE] Display status information in the Omnichannel Agents list (#17701)
  [NEW] Option to remove users from RocketChat if not found in Crowd (#17619)
  [FIX] Elements of  "Personal Access Tokens" section out of alignment and unusable on very small screens (#17129)
  Regression: Integrations edit/history crashing (#17702)
  [FIX] Allow owners to react inside broadcast channels (#17687)
  Regression: User edit form missing fields (#17699)
  [FIX] Default filters on Omnichannel Current Chats screen not showing on first load (#17522)
  Update Helper.js (#17700)
  [FIX] UI KIT Modal Width (#17697)
  Update Contributing Guide (#17653)
  • Loading branch information
ggazzo committed May 21, 2020
2 parents db48f7c + 6ed0e44 commit 3a81933
Show file tree
Hide file tree
Showing 123 changed files with 628 additions and 601 deletions.
239 changes: 225 additions & 14 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,253 @@
# Contributing to Rocket.Chat

:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
**First off, thanks for taking the time to contribute! :tada::+1:**

The following is a set of guidelines for contributing to Rocket.Chat and its packages, which are hosted in the [Rocket.Chat Organization](https://github.com/RocketChat) on GitHub.
> There are many ways to contribute to Rocket.Chat even if you're not technical or a developer:
>
> * Email us at [email protected] to tell us how much you love the project
> * Write about us in your blogs
> * Fix some small typos in our [documentation](https://docs.rocket.chat/contributing)
> * Become our [GitHub sponsor](https://github.com/sponsors/RocketChat)
> * Tell others about us and help us spread the word
>
> Every bit of contribution is appreciated 🙂 thank you!
The following is a set of guidelines for contributing to Rocket.Chat, which are hosted in the [Rocket.Chat Organization](https://github.com/RocketChat) on GitHub.

__Note:__ If there's a feature you'd like, there's a bug you'd like to fix, or you'd just like to get involved please raise an issue and start a conversation. We'll help as much as we can so you can get contributing - although we may not always be able to respond right away :)

## ECMAScript 2015 vs CoffeeScript
## Setup

Your development workstation needs to have at least 8GB or RAM to be able to build the Rocket.Chat's source code.

Rocket.Chat runs on top of [Meteor](https://www.meteor.com/). To run it on development mode you need to [install Meteor](https://www.meteor.com/install) and clone/download the Rocket.Chat's code, then just open the code folder and run:
```shell
meteor npm install && meteor
```
It should build and run the application and database for you, now you can access the UI on (http://localhost:3000)

It's not necessary to install Nodejs or NPM, every time you need to use them you can run `meteor node` or `meteor npm`.

It's important to always run the NPM commands using `meteor npm` to ensure that you are installing the modules using the right Nodejs version.

## Coding

We provide a [.editorconfig](../.editorconfig) file that will help you to keep some standards in place.

### ECMAScript vs TypeScript

We are currently adopting TypeScript as the default language on our projects, the current codebase will be migrated incrementally from JavaScript to TypeScript.

While we still have a lot of JavaScript files you should not create new ones. As much as possible new code contributions should be in **TypeScript**.

While we still have a lot of CoffeeScript files you should not create new ones. New code contributions should be in **ECMAScript 2015**.
### Blaze vs React

## Coding standards
We are currently adopting React over Blaze as our UI engine, the current codebase is under migration and will continue. You will still find Blaze templates in our code. Code changes or contributions may need to be made in Blaze while we continue to evolve our components library.

Most of the coding standards are covered by `.editorconfig` and `.eslintrc.js`.
[Fuselage](https://github.com/RocketChat/Rocket.Chat.Fuselage) is our component library based on React, check it out when contributing to the Rocket.Chat UI and feel free to contribute new components or fixes.

### Standards

Most of the coding standards are covered by ESLint configured at [.eslintrc](../.eslintrc), and most of them came from our own [ESLint Config Package](https://github.com/RocketChat/eslint-config-rocketchat).

Things not covered by `eslint`:

* `exports`/`module.exports` should be at the end of the file
* Longer, descriptive variable names are preferred, e.g. `error` vs `err`
* Prefer longer/descriptive variable names, e.g. `error` vs `err`, unless dealing with common record properties already shortened, e.g. `rid` and `uid`
* Use return early pattern. [See more](https://blog.timoxley.com/post/47041269194/avoid-else-return-early)
* Prefer `Promise` over `callbacks`
* Prefer `await` over `then/catch`
* Don't create queries outside models, the query description should be inside the model class.
* Don't hardcode fields inside models. Same method can be used for different purposes, using different fields.
* Prefer create REST endpoints over Meteor methods
* Prefer call REST endpoints over Meteor methods when both are available
* v1 REST endpoints should follow the following pattern: `/api/v1/dashed-namespace.camelCaseAction`
* Prefer TypeScript over JavaScript. Check [ECMAScript vs TypeScript](#ecmascript-vs-typescript)

We acknowledge all the code does not meet these standards but we are working to change this over time.
#### Blaze
* Import the HTML file from it's sibling JS/TS file

### Syntax check

Before submitting a PR you should get no errors on `eslint`.

To check your files, first install `eslint`:
To check your files run:

```shell
meteor npm run lint
```

## Tests

There are 2 types of tests we run on Rocket.Chat, **Unit** tests and **End to End** tests. The major difference is that End to End tests require a Rocket.Chat instance running to execute the API and UI checks.

### End to End Tests

First you need to run a Rocket.Chat server on **Test Mode** and on a **Empty Database**:
```shell
# Running with a local mongodb database
MONGO_URL=mongodb://localhost/empty MONGO_OPLOG_URL=mongodb://localhost/local TEST_MODE=true meteor
```
```shell
# Running with a local mongodb database but cleaning it before
mongo --eval "db.dropDatabase()" empty && MONGO_URL=mongodb://localhost/empty MONGO_OPLOG_URL=mongodb://localhost/local TEST_MODE=true meteor
```

Now you can run the tests:
```shell
meteor npm test
```

### Unit Tests

Unit tests are simpler to setup and run. They do not require a working Rocket.Chat instance.
```shell
meteor npm run testunit
```

It's possible to run on watch mode as well:
```shell
meteor npm run testunit-watch
```

<!-- ### Storybook -->

## Before Push your code

It's important to run the lint and tests before push your code or submit a Pull Request, otherwise your contribution may fail quickly on the CI. Reviewers are forced to demand fixes and the review of your contribution will be further delayed.

Rocket.Chat uses [husky](https://www.npmjs.com/package/husky) to run the **lint** and **unit tests** before proceed to the code push process, so you may notice a delay when pushing your code to your repository.

## Choosing a good PR title

It is very important to note that we use PR titles when creating our change log. Keep this in mind when you title your PR. Make sure the title makes sense to a person reading a releases' change log!

Keep your PR's title as short and concise as possible, use PR's description section, which you can find in the PR's template, to provide more details into the changelog.

Good titles require thinking from a user's point of view. Don't get technical and talk code or architecture. What is the actual user-facing feature or the bug fixed? For example:

```
[NEW] Allow search permissions and settings by name instead of only ID
```

Even it's being something new in the code the users already expect the filter to filter by what they see (translations), a better one would be:

```
[FIX] Permissions' search doesn't filter base on presented translation, only on internal ids
```

## Choosing the right PR tag

You can use several tags do describe your PR, i.e.: `[FIX]`, `[NEW]`, etc. You can use the descriptions below to better understand the meaning of each one, and decide which one you should use:

### `[NEW]`

#### When
- When adding a new feature that is important to the end user

#### How

Do not start repeating the section (`Add ...` or `New ...`)
Always describe what's being fixed, improved or added and not *how* it was fixed, improved or added.

Exemple of **bad** PR titles:

```
[NEW] Add ability to set tags in the Omnichannel room closing dialog
[NEW] Adds ability for Rocket.Chat Apps to create discussions
[NEW] Add MMS support to Voxtelesys
[NEW] Add Color variable to left sidebar
```

Exemple of **good** PR titles:

```
npm install -g eslint
[NEW] Ability to set tags in the Omnichannel room closing dialog
[NEW] Ability for Rocket.Chat Apps to create discussions
[NEW] MMS support to Voxtelesys
[NEW] Color variable to left sidebar
```

Then run:
### `[FIX]`

#### When
- When fixing something not working or behaving wrong from the end user perspective

#### How

Always describe what's being fixed and not *how* it was fixed.

Exemple of a **bad** PR title:

```
eslint .
[FIX] Add Content-Type for public files with JWT
```

# Contributor License Agreement
Exemple of a **good** PR title:

```
[FIX] Missing Content-Type header for public files with JWT
```

### `[IMPROVE]`

#### When
- When a change enhances a not buggy behavior. When in doubt if it's a Improve or Fix prefer to use as fix.

#### How
Always describe what's being improved and not *how* it was improved.

Exemple of **good** PR title:

```
[IMPROVE] Displays Nothing found on admin sidebar when search returns nothing
```

### `[BREAK]`

#### When
- When the changes affect a working feature

##### Back-End
- When the API contract (data structure and endpoints) are limited, expanded as required or removed
- When the business logic (permissions and roles) are limited, expanded (without migration) or removed

##### Front-End
- When the change limits (format, size, etc) or removes the ability of read or change the data (when the limitation was not caused by the back-end)

### Second tag e.g. `[NEW][ENTERPRISE]`

Use a second tag to group entries on the change log, we currently use it only for the Enterprise items but we are going to expand it's usage soon, please do not use it until we create a patter for it.

### Minor Changes

For those PRs that aren't important for the end user, we are working on a better pattern, but for now please use the same tags, use them without the brackets and in camel case:

```
Fix: Missing Content-Type header for public files with JWT
```

All those PRs will be grouped under the `Minor changes` section which is collapsed, so users can expand it to check for those minor things but they are not visible directly on changelog.

## Security Best Practices

- Never expose unnecessary data to the APIs' responses
- Always check for permissions or create new ones when you must expose sensitive data
- Never provide new APIs without rate limiters
- Always escape the user's input when rendering data
- Always limit the user's input size on server side
- Always execute the validations on the server side even when executing on the client side as well

## Performance Best Practices

- Prefer inform the fields you want, and only the necessary ones, when querying data from database over query the full documents
- Limit the number of returned records to a reasonable value
- Check if the query is using indexes, it it's not create new indexes
- Prefer queues over long executions
- Create new metrics to mesure things whenever possible
- Cache data and returns whenever possible

## Contributor License Agreement

To have your contribution accepted you must sign our [Contributor License Agreement](https://cla-assistant.io/RocketChat/Rocket.Chat). In case you submit a Pull Request before sign the CLA GitHub will alert you with a new comment asking you to sign and will block the Pull Request from be merged by us.

Please review and sign our CLA at https://cla-assistant.io/RocketChat/Rocket.Chat
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ jobs:
MONGO_URL: mongodb://localhost:27017/rocketchat
MONGO_OPLOG_URL: mongodb://localhost:27017/local
run: |
for i in $(seq 1 5); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && xvfb-run --auto-servernum npm test && s=0 && break || s=$? && sleep 1; done; (exit $s)
for i in $(seq 1 5); do (docker exec mongo mongo rocketchat --eval 'db.dropDatabase()') && xvfb-run --auto-servernum npm run testci && s=0 && break || s=$? && sleep 1; done; (exit $s)
# notification:
# runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function startChimp() {
startProcess({
name: 'Chimp',
command: 'npm',
params: ['run', 'testci'],
params: ['test'],
// command: 'exit',
// params: ['2'],
options: {
Expand Down
1 change: 0 additions & 1 deletion app/accounts/index.js

This file was deleted.

3 changes: 1 addition & 2 deletions app/action-links/client/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { actionLinks } from '../both/lib/actionLinks';
import './lib/actionLinks';
import { actionLinks } from './lib/actionLinks';
import './init';
import './stylesheets/actionLinks.css';

Expand Down
8 changes: 4 additions & 4 deletions app/action-links/client/init.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';

import { handleError } from '../../utils';
import { fireGlobalEvent, Layout } from '../../ui-utils';
import { handleError } from '../../utils/client';
import { fireGlobalEvent, Layout } from '../../ui-utils/client';
import { messageArgs } from '../../ui-utils/client/lib/messageArgs';
import { actionLinks } from '../both/lib/actionLinks';
import { actionLinks } from './lib/actionLinks';


Template.room.events({
'click .action-link'(event, instance) {
'click [data-actionlink]'(event, instance) {
event.preventDefault();
event.stopPropagation();

Expand Down
65 changes: 48 additions & 17 deletions app/action-links/client/lib/actionLinks.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
import { Meteor } from 'meteor/meteor';

import { handleError } from '../../../utils';
import { actionLinks } from '../../both/lib/actionLinks';
// Action Links Handler. This method will be called off the client.
import { handleError } from '../../../utils/client';
import { Messages, Subscriptions } from '../../../models/client';

actionLinks.run = (name, messageId, instance) => {
const message = actionLinks.getMessage(name, messageId);
// Action Links namespace creation.
export const actionLinks = {
actions: {},
register(name, funct) {
actionLinks.actions[name] = funct;
},
getMessage(name, messageId) {
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { function: 'actionLinks.getMessage' });
}

const message = Messages.findOne({ _id: messageId });
if (!message) {
throw new Meteor.Error('error-invalid-message', 'Invalid message', { function: 'actionLinks.getMessage' });
}

const subscription = Subscriptions.findOne({
rid: message.rid,
'u._id': userId,
});
if (!subscription) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { function: 'actionLinks.getMessage' });
}

if (!message.actionLinks || !message.actionLinks[name]) {
throw new Meteor.Error('error-invalid-actionlink', 'Invalid action link', { function: 'actionLinks.getMessage' });
}

const actionLink = message.actionLinks[name];
return message;
},
run(name, messageId, instance) {
const message = actionLinks.getMessage(name, messageId);

let ranClient = false;
const actionLink = message.actionLinks[name];

if (actionLinks && actionLinks.actions && actionLinks.actions[actionLink.method_id]) {
// run just on client side
actionLinks.actions[actionLink.method_id](message, actionLink.params, instance);
let ranClient = false;

ranClient = true;
}
if (actionLinks && actionLinks.actions && actionLinks.actions[actionLink.method_id]) {
// run just on client side
actionLinks.actions[actionLink.method_id](message, actionLink.params, instance);

// and run on server side
Meteor.call('actionLinkHandler', name, messageId, (err) => {
if (err && !ranClient) {
handleError(err);
ranClient = true;
}
});

// and run on server side
Meteor.call('actionLinkHandler', name, messageId, (err) => {
if (err && !ranClient) {
handleError(err);
}
});
},
};
8 changes: 0 additions & 8 deletions app/action-links/index.js

This file was deleted.

Loading

0 comments on commit 3a81933

Please sign in to comment.