Skip to content

Commit

Permalink
Merge branch 'develop' into chore/create-setAvatarFromService-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Sep 21, 2022
2 parents 39e7142 + 3023022 commit ce2e59f
Show file tree
Hide file tree
Showing 307 changed files with 5,784 additions and 1,928 deletions.
67 changes: 44 additions & 23 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,38 @@ jobs:
tar xzf Rocket.Chat.tar.gz
rm Rocket.Chat.tar.gz
- name: Start containers
env:
MONGO_URL: 'mongodb://host.docker.internal:27017/rocketchat?replicaSet=rs0&directConnection=true'
MONGO_OPLOG_URL: 'mongodb://mongodb:27017/local?replicaSet=rs0&directConnection=true'
- name: Docker env vars
id: docker-env
run: |
export LOWERCASE_REPOSITORY=$(echo "${{ github.repository_owner }}" | tr "[:upper:]" "[:lower:]")
LOWERCASE_REPOSITORY=$(echo "${{ github.repository_owner }}" | tr "[:upper:]" "[:lower:]")
echo "LOWERCASE_REPOSITORY: ${LOWERCASE_REPOSITORY}"
echo "::set-output name=lowercase-repo::${LOWERCASE_REPOSITORY}"
# test alpine image on mongo 5.0 (no special reason to be mongo 5.0 but we need to test alpine at least once)
if [[ '${{ matrix.mongodb-version }}' = '5.0' ]]; then
export RC_DOCKERFILE="${{ github.workspace }}/apps/meteor/.docker/Dockerfile.alpine"
export RC_DOCKER_TAG="${{ needs.release-versions.outputs.gh-docker-tag }}.alpine"
RC_DOCKERFILE="${{ github.workspace }}/apps/meteor/.docker/Dockerfile.alpine"
RC_DOCKER_TAG="${{ needs.release-versions.outputs.gh-docker-tag }}.alpine"
else
export RC_DOCKERFILE="${{ github.workspace }}/apps/meteor/.docker/Dockerfile"
export RC_DOCKER_TAG="${{ needs.release-versions.outputs.gh-docker-tag }}.official"
RC_DOCKERFILE="${{ github.workspace }}/apps/meteor/.docker/Dockerfile"
RC_DOCKER_TAG="${{ needs.release-versions.outputs.gh-docker-tag }}.official"
fi;
echo "RC_DOCKERFILE: ${RC_DOCKERFILE}"
echo "::set-output name=rc-dockerfile::${RC_DOCKERFILE}"
echo "RC_DOCKER_TAG: ${RC_DOCKER_TAG}"
echo "::set-output name=rc-docker-tag::${RC_DOCKER_TAG}"
- name: Start containers
env:
MONGO_URL: 'mongodb://host.docker.internal:27017/rocketchat?replicaSet=rs0&directConnection=true'
MONGO_OPLOG_URL: 'mongodb://mongodb:27017/local?replicaSet=rs0&directConnection=true'
LOWERCASE_REPOSITORY: ${{ steps.docker-env.outputs.lowercase-repo }}
RC_DOCKERFILE: ${{ steps.docker-env.outputs.rc-dockerfile }}
RC_DOCKER_TAG: ${{ steps.docker-env.outputs.rc-docker-tag }}
DOCKER_TAG: ${{ needs.release-versions.outputs.gh-docker-tag }}
run: |
docker compose -f docker-compose-ci.yml up -d --build rocketchat
sleep 10
Expand All @@ -299,17 +315,13 @@ jobs:
password: ${{ secrets.CR_PAT }}

- name: Publish Docker images to GitHub Container Registry
env:
LOWERCASE_REPOSITORY: ${{ steps.docker-env.outputs.lowercase-repo }}
RC_DOCKERFILE: ${{ steps.docker-env.outputs.rc-dockerfile }}
RC_DOCKER_TAG: ${{ steps.docker-env.outputs.rc-docker-tag }}
DOCKER_TAG: ${{ needs.release-versions.outputs.gh-docker-tag }}
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'release' || github.ref == 'refs/heads/develop'
run: |
export LOWERCASE_REPOSITORY=$(echo "${{ github.repository_owner }}" | tr "[:upper:]" "[:lower:]")
# test alpine image on mongo 5.0 (no special reason to be mongo 5.0 but we need to test alpine at least once)
if [[ '${{ matrix.mongodb-version }}' = '5.0' ]]; then
export RC_DOCKER_TAG="${{ needs.release-versions.outputs.gh-docker-tag }}.alpine"
else
export RC_DOCKER_TAG="${{ needs.release-versions.outputs.gh-docker-tag }}.official"
fi;
docker compose -f docker-compose-ci.yml push rocketchat
if [[ '${{ matrix.mongodb-version }}' = '4.4' ]]; then
Expand All @@ -322,6 +334,11 @@ jobs:
fi;
- name: E2E Test API
env:
LOWERCASE_REPOSITORY: ${{ steps.docker-env.outputs.lowercase-repo }}
RC_DOCKERFILE: ${{ steps.docker-env.outputs.rc-dockerfile }}
RC_DOCKER_TAG: ${{ steps.docker-env.outputs.rc-docker-tag }}
DOCKER_TAG: ${{ needs.release-versions.outputs.gh-docker-tag }}
run: |
docker ps
docker compose -f docker-compose-ci.yml logs rocketchat --tail=50
Expand All @@ -336,9 +353,9 @@ jobs:
docker exec mongodb mongo rocketchat --eval 'db.dropDatabase()'
NOW=$(date "+%Y-%m-%dT%H:%M:%SZ")
NOW=$(date "+%Y-%m-%dT%H:%M:%S.000Z")
docker compose -f ../../docker-compose-ci.yml start rocketchat
docker compose -f ../../docker-compose-ci.yml restart rocketchat
until echo "$(docker compose -f ../../docker-compose-ci.yml logs rocketchat --since $NOW)" | grep -q "SERVER RUNNING"; do
echo "Waiting Rocket.Chat to start up"
Expand All @@ -364,13 +381,17 @@ jobs:
npx playwright install --with-deps
- name: E2E Test UI
env:
LOWERCASE_REPOSITORY: ${{ steps.docker-env.outputs.lowercase-repo }}
RC_DOCKERFILE: ${{ steps.docker-env.outputs.rc-dockerfile }}
RC_DOCKER_TAG: ${{ steps.docker-env.outputs.rc-docker-tag }}
run: |
docker ps
docker compose -f docker-compose-ci.yml logs rocketchat --tail=50
docker exec mongodb mongo rocketchat --eval 'db.dropDatabase()'
NOW=$(date "+%Y-%m-%dT%H:%M:%SZ")
NOW=$(date "+%Y-%m-%dT%H:%M:%S.000Z")
docker compose -f docker-compose-ci.yml restart rocketchat
Expand Down Expand Up @@ -502,7 +523,7 @@ jobs:
docker exec mongodb mongo rocketchat --eval 'db.dropDatabase()'
NOW=$(date "+%Y-%m-%dT%H:%M:%SZ")
NOW=$(date "+%Y-%m-%dT%H:%M:%S.000Z")
docker compose -f ../../docker-compose-ci.yml start
Expand Down Expand Up @@ -535,7 +556,7 @@ jobs:
docker exec mongodb mongo rocketchat --eval 'db.dropDatabase()'
NOW=$(date "+%Y-%m-%dT%H:%M:%SZ")
NOW=$(date "+%Y-%m-%dT%H:%M:%S.000Z")
docker compose -f docker-compose-ci.yml restart
Expand Down
8 changes: 6 additions & 2 deletions apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import { resetUserE2EEncriptionKey } from '../../../../server/lib/resetUserE2EKe
import { resetTOTP } from '../../../2fa/server/functions/resetTOTP';
import { Team } from '../../../../server/sdk';
import { isValidQuery } from '../lib/isValidQuery';
import { setUserStatus } from '../../../../imports/users-presence/server/activeUsers';
import { getURL } from '../../../utils/server';
import { getUploadFormData } from '../lib/getUploadFormData';
import { api } from '../../../../server/sdk/api';

API.v1.addRoute(
'users.getAvatar',
Expand Down Expand Up @@ -1069,7 +1069,11 @@ API.v1.addRoute(
},
});

setUserStatus(user, status);
const { _id, username, statusText, roles, name } = user;
api.broadcast('presence.status', {
user: { status, _id, username, statusText, roles, name },
previousStatus: user.status,
});
} else {
throw new Meteor.Error('error-invalid-status', 'Valid status types include online, away, offline, and busy.', {
method: 'users.setStatus',
Expand Down
13 changes: 8 additions & 5 deletions apps/meteor/app/apps/server/bridges/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Random } from 'meteor/random';
import { UserPresence } from 'meteor/konecty:user-presence';
import { UserBridge } from '@rocket.chat/apps-engine/server/bridges/UserBridge';
import type { IUserCreationOptions, IUser } from '@rocket.chat/apps-engine/definition/users';
import { Subscriptions, Users as UsersRaw } from '@rocket.chat/models';
Expand Down Expand Up @@ -84,7 +83,11 @@ export class AppUserBridge extends UserBridge {
return true;
}

protected async update(user: IUser & { id: string }, fields: Partial<IUser>, appId: string): Promise<boolean> {
protected async update(
user: IUser & { id: string },
fields: Partial<IUser> & { statusDefault: string },
appId: string,
): Promise<boolean> {
this.orch.debugLog(`The App ${appId} is updating a user`);

if (!user) {
Expand All @@ -98,12 +101,12 @@ export class AppUserBridge extends UserBridge {
const { status } = fields;
delete fields.status;

await UsersRaw.update({ _id: user.id }, { $set: fields as any });

if (status) {
UserPresence.setDefaultStatus(user.id, status);
fields.statusDefault = status;
}

await UsersRaw.updateOne({ _id: user.id }, { $set: fields as any });

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './cron';
import './status.ts';

export { Apps, AppEvents } from './orchestrator';
16 changes: 0 additions & 16 deletions apps/meteor/app/apps/server/status.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/meteor/app/file-upload/ufs/Webdav/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class WebdavStore extends UploadFS.Store {
.then((data) => {
callback && callback(null, data);
})
.catch(SystemLogger.error);
.catch((...args) => SystemLogger.error(...args));
};

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ export class WebdavStore extends UploadFS.Store {
*/
this.getWriteStream = function (fileId, file) {
const writeStream = new stream.PassThrough();
const webdavStream = client.createWriteStream(this.getPath(file));
const webdavStream = client.createWriteStream(this.getPath(file), file.size || 0);

// TODO remove timeout when UploadFS bug resolved
const newListenerCallback = (event, listener) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export { saveUserIdentity } from './saveUserIdentity';
export { sendMessage } from './sendMessage';
export { setEmail } from './setEmail';
export { setRealName, _setRealName } from './setRealName';
export { setStatusText, _setStatusText, _setStatusTextPromise } from './setStatusText';
export { setStatusText } from './setStatusText';
export { getStatusText } from './getStatusText';
export { setUserAvatar } from './setUserAvatar';
export { _setUsername, setUsername } from './setUsername';
Expand Down
49 changes: 13 additions & 36 deletions apps/meteor/app/lib/server/functions/setStatusText.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Meteor } from 'meteor/meteor';
import s from 'underscore.string';
import type { IUser } from '@rocket.chat/core-typings';
import { Users as UsersRaw } from '@rocket.chat/models';
import { Users } from '@rocket.chat/models';

import { Users } from '../../../models/server';
import { hasPermission } from '../../../authorization/server';
import { RateLimiter } from '../lib';
import { api } from '../../../../server/sdk/api';

export const _setStatusTextPromise = async function (userId: string, statusText: string): Promise<boolean> {
async function _setStatusTextPromise(userId: string, statusText: string): Promise<boolean> {
if (!userId) {
return false;
}

statusText = s.trim(statusText).substr(0, 120);

const user = await UsersRaw.findOneById(userId);
const user = await Users.findOneById<Pick<IUser, '_id' | 'username' | 'name' | 'status' | 'roles' | 'statusText'>>(userId, {
projection: { username: 1, name: 1, status: 1, roles: 1, statusText: 1 },
});

if (!user) {
return false;
Expand All @@ -25,44 +26,20 @@ export const _setStatusTextPromise = async function (userId: string, statusText:
return true;
}

await UsersRaw.updateStatusText(user._id, statusText);
await Users.updateStatusText(user._id, statusText);

const { _id, username, status } = user;
const { _id, username, status, name, roles } = user;
api.broadcast('presence.status', {
user: { _id, username, status, statusText },
user: { _id, username, status, statusText, name, roles },
previousStatus: status,
});

return true;
};

export const _setStatusText = function (userId: any, statusText: string): IUser | boolean {
statusText = s.trim(statusText);
if (statusText.length > 120) {
statusText = statusText.substr(0, 120);
}

if (!userId) {
return false;
}

const user = Users.findOneById(userId);
}

// User already has desired statusText, return
if (user.statusText === statusText) {
return user;
}

// Set new statusText
Users.updateStatusText(user._id, statusText);
user.statusText = statusText;

const { _id, username, status } = user;
api.broadcast('presence.status', {
user: { _id, username, status, statusText },
});

return true;
};
function _setStatusText(userId: any, statusText: string): boolean {
return Promise.await(_setStatusTextPromise(userId, statusText));
}

export const setStatusText = RateLimiter.limitFunction(_setStatusText, 5, 60000, {
0() {
Expand Down

This file was deleted.

28 changes: 0 additions & 28 deletions apps/meteor/app/livechat/client/views/app/livechatReadOnly.html

This file was deleted.

0 comments on commit ce2e59f

Please sign in to comment.