Skip to content

Commit

Permalink
Merge branch 'develop' into chore/permission-translation
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris authored Aug 19, 2022
2 parents ef348d4 + cb5bf38 commit ac0abed
Show file tree
Hide file tree
Showing 18 changed files with 133 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ jobs:
run: |
LOWERCASE_REPOSITORY=$(echo "${{ github.repository_owner }}" | tr "[:upper:]" "[:lower:]")
GH_IMAGE_NAME="ghcr.io/${LOWERCASE_REPOSITORY}/${{ matrix.service }}-service:${{ needs.release-versions.outputs.gh-docker-tag }}.${{ matrix.release }}"
GH_IMAGE_NAME="ghcr.io/${LOWERCASE_REPOSITORY}/${{ matrix.service }}-service:${{ needs.release-versions.outputs.gh-docker-tag }}"
echo "GH_IMAGE_NAME: $GH_IMAGE_NAME"
Expand Down
19 changes: 3 additions & 16 deletions apps/meteor/app/lib/server/methods/getMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { check } from 'meteor/check';
import type { IMessage } from '@rocket.chat/core-typings';

import { canAccessRoomId } from '../../../authorization/server';
import { Messages, Rooms } from '../../../models/server';
import { Messages } from '../../../models/server';

Meteor.methods({
getMessages(messages) {
Expand All @@ -16,22 +16,9 @@ Meteor.methods({

const msgs = Messages.findVisibleByIds(messages).fetch() as IMessage[];
const rids = [...new Set(msgs.map((m) => m.rid))];
const prids = [
...new Set(
rids.reduce<string[]>((prids, rid) => {
const room = Rooms.findOneById(rid);

if (room?.prid) {
prids.push(room.prid);
}

return prids;
}, []),
),
];

if (!rids.every((_id) => canAccessRoomId(_id, uid)) || !prids.every((_id) => canAccessRoomId(_id, uid))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', 'getSingleMessage');
if (!rids.every((_id) => canAccessRoomId(_id, uid))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' });
}

return msgs;
Expand Down
19 changes: 16 additions & 3 deletions apps/meteor/app/slackbridge/server/SlackAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,26 @@ export default class SlackAdapter {
* Connect to the remote Slack server using the passed in token API and register for Slack events
* @param apiToken
*/
connect(apiToken) {
async connect(apiToken) {
this.apiToken = apiToken;

if (RTMClient != null) {
RTMClient.disconnect;
}
this.slackAPI = new SlackAPI(this.apiToken);
this.rtm = new RTMClient(this.apiToken);
this.rtm.start();

await this.rtm
.start()
.then((res) => slackLogger.debug('Connecting to slack', res))
.catch((err) => {
slackLogger.error('Error attempting to connect to Slack', err);
if (err.data.error === 'invalid_auth') {
throw new Error('The provided token is invalid');
}
throw new Error(err);
});

this.registerForEvents();

Meteor.startup(() => {
Expand All @@ -58,7 +69,9 @@ export default class SlackAdapter {
* Unregister for slack events and disconnect from Slack
*/
disconnect() {
this.rtm.disconnect && this.rtm.disconnect();
if (this.rtm.connected && this.rtm.disconnect) {
this.rtm.disconnect();
}
}

setRocket(rocket) {
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/slackbridge/server/slackbridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ class SlackBridgeClass {
this.rocket.clearSlackAdapters();

const tokenList = this.apiTokens.split('\n');

tokenList.forEach((apiToken) => {
const slack = new SlackAdapter(this);
slack.setRocket(this.rocket);
this.rocket.addSlack(slack);
this.slackAdapters.push(slack);

slack.connect(apiToken);
slack.connect(apiToken).catch((err) => connLogger.error('error connecting to slack', err));
});

if (settings.get('SlackBridge_Out_Enabled')) {
Expand Down
5 changes: 4 additions & 1 deletion apps/meteor/client/providers/TooltipProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ const TooltipProvider: FC = ({ children }) => {
setTooltip(null);
};

const handleClick = (): void => setTooltip(null);
const handleClick = (): void => {
setTooltip(null);
clearTimeout(timeout);
};

document.body.addEventListener('mouseover', handleMouseOver);
document.body.addEventListener('click', handleClick);
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/client/sidebar/search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ const SearchList = forwardRef(function SearchList({ onClose }: SearchListProps,
const placeholder = [t('Search'), shortcut].filter(Boolean).join(' ');

const { data: items = [], isLoading } = useSearchItems(filterText);
console.log({ items, isLoading });

const itemData = useMemo(
() => ({
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/admin/info/LicenseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const LicenseCard = (): ReactElement => {
const t = useTranslation();
const setModal = useSetModal();

const currentLicense = useSetting('Enterprise_License');
const licenseStatus = useSetting('Enterprise_License_Status');
const currentLicense = useSetting('Enterprise_License') as string;
const licenseStatus = useSetting('Enterprise_License_Status') as string;

const isAirGapped = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Modal, Box, ButtonGroup, Button, Scrollable, Callout, Margins, Icon } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import React, { useState } from 'react';
import { useEndpoint, useToastMessageDispatch, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ComponentProps, FormEvent, ReactElement, useState } from 'react';

import { useEndpointActionExperimental } from '../../../hooks/useEndpointActionExperimental';
type OfflineLicenseModalProps = {
onClose: () => void;
license: string;
licenseStatus: string;
} & ComponentProps<typeof Modal>;

const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }) => {
const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }: OfflineLicenseModalProps): ReactElement => {
const t = useTranslation();

const dispatchToastMessage = useToastMessageDispatch();
Expand All @@ -15,14 +19,12 @@ const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }) => {
const [status, setStatus] = useState(licenseStatus);
const [lastSetLicense, setLastSetLicense] = useState(license);

const handleNewLicense = (e) => {
const handleNewLicense = (e: FormEvent<HTMLInputElement>): void => {
setNewLicense(e.currentTarget.value);
};

const hasChanges = lastSetLicense !== newLicense;

const addLicense = useEndpointActionExperimental('POST', '/v1/licenses.add', t('Cloud_License_applied_successfully'));

const handlePaste = useMutableCallback(async () => {
try {
const text = await navigator.clipboard.readText();
Expand All @@ -32,16 +34,24 @@ const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }) => {
}
});

const addLicense = useEndpoint('POST', '/v1/licenses.add');

const handleApplyLicense = useMutableCallback(async () => {
setIsUpdating(true);
setLastSetLicense(newLicense);
const data = await addLicense({ license: newLicense });
if (data.success) {

try {
setIsUpdating(true);
await addLicense({ license: newLicense });
dispatchToastMessage({ type: 'success', message: t('Cloud_License_applied_successfully') });
onClose();
return;
} catch (error) {
dispatchToastMessage({
type: 'error',
message: error && typeof error === 'object' && 'error' in error ? (error as any).error : String(error),
});
setIsUpdating(false);
setStatus('invalid');
}
setIsUpdating(false);
setStatus('invalid');
});

return (
Expand All @@ -62,7 +72,7 @@ const OfflineLicenseModal = ({ onClose, license, licenseStatus, ...props }) => {
pb='x8'
flexGrow={1}
backgroundColor='neutral-800'
mb={status === 'invalid' && 'x8'}
mb={status === 'invalid' ? 'x8' : undefined}
>
<Margins block='x8'>
<Scrollable vertical>
Expand Down
58 changes: 11 additions & 47 deletions apps/meteor/client/views/notFound/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,26 @@
import { Box, Button, ButtonGroup, Flex, Margins } from '@rocket.chat/fuselage';
import { Box, States, StatesAction, StatesActions, StatesIcon, StatesSubtitle, StatesTitle } from '@rocket.chat/fuselage';
import { useRoute, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ReactElement } from 'react';

const NotFoundPage = (): ReactElement => {
const t = useTranslation();
const homeRoute = useRoute('home');

const handleGoToPreviousPageClick = (): void => {
window.history.back();
};

const handleGoHomeClick = (): void => {
homeRoute.push();
};

return (
<Flex.Container direction='column' justifyContent='center' alignItems='center'>
<Box
is='section'
width='full'
minHeight='sh'
textAlign='center'
backgroundColor='neutral-800'
style={{
backgroundImage: "url('/images/404.svg')",
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'cover',
}}
>
<Flex.Item>
<Box>
<Margins all='x12'>
<Box fontWeight='p2m' fontSize='x64' color='alternative'>
404
</Box>

<Box role='heading' aria-level={1} fontScale='h2' color='alternative'>
{t('Oops_page_not_found')}
</Box>

<Box role='status' aria-label='Sorry_page_you_requested_does_not_exist_or_was_deleted' fontScale='p2' color='alternative'>
{t('Sorry_page_you_requested_does_not_exist_or_was_deleted')}
</Box>
</Margins>

<ButtonGroup align='center' margin='x64'>
<Button type='button' primary onClick={handleGoToPreviousPageClick}>
{t('Return_to_previous_page')}
</Button>
<Button type='button' primary onClick={handleGoHomeClick}>
{t('Return_to_home')}
</Button>
</ButtonGroup>
</Box>
</Flex.Item>
</Box>
</Flex.Container>
<Box display='flex' justifyContent='center' height='full' backgroundColor='surface'>
<States>
<StatesIcon name='magnifier' />
<StatesTitle>{t('Page_not_found')}</StatesTitle>
<StatesSubtitle>{t('Page_not_exist_or_not_permission')}</StatesSubtitle>
<StatesActions mbs='x16'>
<StatesAction onClick={handleGoHomeClick}>{t('Homepage')}</StatesAction>
</StatesActions>
</States>
</Box>
);
};

Expand Down
12 changes: 10 additions & 2 deletions apps/meteor/client/views/room/Room/RoomNotFound/RoomNotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { States, StatesIcon, StatesTitle, StatesSubtitle, Box } from '@rocket.chat/fuselage';
import { useLayout, useTranslation } from '@rocket.chat/ui-contexts';
import { States, StatesIcon, StatesTitle, StatesSubtitle, Box, StatesActions, StatesAction } from '@rocket.chat/fuselage';
import { useLayout, useRoute, useTranslation } from '@rocket.chat/ui-contexts';
import React, { ReactElement } from 'react';

import BurgerMenu from '../../../../components/BurgerMenu';
Expand All @@ -9,6 +9,11 @@ import { RoomTemplate } from '../../components/RoomTemplate/RoomTemplate';
const RoomNotFound = (): ReactElement => {
const { isMobile } = useLayout();
const t = useTranslation();
const homeRoute = useRoute('home');

const handleGoHomeClick = (): void => {
homeRoute.push();
};

return (
<RoomTemplate>
Expand All @@ -27,6 +32,9 @@ const RoomNotFound = (): ReactElement => {
<StatesIcon name='magnifier' />
<StatesTitle>{t('Room_not_found')}</StatesTitle>
<StatesSubtitle>{t('Room_not_exist_or_not_permission')}</StatesSubtitle>
<StatesActions mbs='x16'>
<StatesAction onClick={handleGoHomeClick}>{t('Homepage')}</StatesAction>
</StatesActions>
</States>
</Box>
</RoomTemplate.Body>
Expand Down
7 changes: 5 additions & 2 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,7 @@
"Hold_Call": "Hold Call",
"Hold_Call_EE_only": "Hold Call (Enterprise Edition only)",
"Home": "Home",
"Homepage": "Homepage",
"Host": "Host",
"Hospitality_Businness": "Hospitality Business",
"hours": "hours",
Expand Down Expand Up @@ -3581,6 +3582,8 @@
"Override_URL_to_which_files_are_uploaded_This_url_also_used_for_downloads_unless_a_CDN_is_given": "Override URL to which files are uploaded. This url also used for downloads unless a CDN is given",
"Owner": "Owner",
"Play": "Play",
"Page_not_exist_or_not_permission": "The page does not exist or you may not have access permission",
"Page_not_found": "Page not found",
"Page_title": "Page title",
"Page_URL": "Page URL",
"Pages": "Pages",
Expand Down Expand Up @@ -3992,7 +3995,7 @@
"room_name": "room name",
"Room_name_changed": "Room name changed to: <em>__room_name__</em> by <em>__user_by__</em>",
"Room_name_changed_successfully": "Room name changed successfully",
"Room_not_exist_or_not_permission": "This room does not exist or you may not have permission to access",
"Room_not_exist_or_not_permission": "The room does not exist or you may not have access permission",
"Room_not_found": "Room not found",
"Room_password_changed_successfully": "Room password changed successfully",
"room_removed_read_only": "Room added writing permission by <em>__user_by__</em>",
Expand Down Expand Up @@ -5376,4 +5379,4 @@
"Device_Management_Email_Subject": "[Site_Name] - Login Detected",
"Device_Management_Email_Body": "You may use the following placeholders: <h2 class=\"rc-color\">{Login_Detected}</h2><p><strong>[name] ([username]) {Logged_In_Via}</strong></p><p><strong>{Device_Management_Client}:</strong> [browserInfo]<br><strong>{Device_Management_OS}:</strong> [osInfo]<br><strong>{Device_Management_Device}:</strong> [deviceInfo]<br><strong>{Device_Management_IP}:</strong>[ipInfo]</p><p><small>[userAgent]</small></p><a class=\"btn\" href=\"[Site_URL]\">{Access_Your_Account}</a><p>{Or_Copy_And_Paste_This_URL_Into_A_Tab_Of_Your_Browser}<br><a href=\"[Site_URL]\">[SITE_URL]</a></p><p>{Thank_You_For_Choosing_RocketChat}</p>",
"Something_Went_Wrong": "Something went wrong"
}
}
7 changes: 1 addition & 6 deletions apps/meteor/server/methods/loadHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

import { Subscriptions, Rooms } from '../../app/models/server';
import { canAccessRoom, canAccessRoomId, hasPermission, roomAccessAttributes } from '../../app/authorization/server';
import { canAccessRoom, hasPermission, roomAccessAttributes } from '../../app/authorization/server';
import { settings } from '../../app/settings/server';
import { loadMessageHistory } from '../../app/lib/server';

Expand All @@ -19,7 +19,6 @@ Meteor.methods({
const fromId = Meteor.userId();

const room = Rooms.findOneById(rid, { fields: { ...roomAccessAttributes, t: 1 } });

if (!room) {
return false;
}
Expand All @@ -28,10 +27,6 @@ Meteor.methods({
return false;
}

if (room.prid && !canAccessRoomId(room.prid, fromId)) {
return false;
}

const canAnonymous = settings.get('Accounts_AllowAnonymousRead');
const canPreview = hasPermission(fromId, 'preview-c-room');

Expand Down
8 changes: 1 addition & 7 deletions apps/meteor/server/methods/loadSurroundingMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

import { canAccessRoomId } from '../../app/authorization/server';
import { Messages, Rooms } from '../../app/models/server';
import { Messages } from '../../app/models/server';
import { settings } from '../../app/settings/server';
import { normalizeMessagesForUser } from '../../app/utils/server/lib/normalizeMessagesForUser';

Expand Down Expand Up @@ -33,12 +33,6 @@ Meteor.methods({
return false;
}

const room = Rooms.findOneById(message.rid);

if (room.prid && !canAccessRoomId(room.prid, fromId)) {
return false;
}

limit -= 1;

const options = {
Expand Down
Loading

0 comments on commit ac0abed

Please sign in to comment.