Skip to content

Commit

Permalink
Merge branch 'develop' into improve/home
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Aug 17, 2022
2 parents 8b8256a + e8aeae3 commit 0588618
Show file tree
Hide file tree
Showing 50 changed files with 689 additions and 315 deletions.
41 changes: 41 additions & 0 deletions apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
isMethodCallProps,
isMethodCallAnonProps,
isMeteorCall,
validateParamsPwGetPolicyRest,
} from '@rocket.chat/rest-typings';
import type { IUser } from '@rocket.chat/core-typings';
import { Users as UsersRaw } from '@rocket.chat/models';

import { hasPermission } from '../../../authorization/server';
import { Users } from '../../../models/server';
Expand All @@ -24,6 +26,7 @@ import { getDefaultUserFields } from '../../../utils/server/functions/getDefault
import { getURL } from '../../../utils/lib/getURL';
import { getLogs } from '../../../../server/stream/stdout';
import { SystemLogger } from '../../../../server/lib/logger/system';
import { passwordPolicy } from '../../../lib/server';

/**
* @openapi
Expand Down Expand Up @@ -383,6 +386,44 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'pw.getPolicy',
{
authRequired: true,
},
{
get() {
return API.v1.success(passwordPolicy.getPasswordPolicy());
},
},
);

API.v1.addRoute(
'pw.getPolicyReset',
{
authRequired: false,
validateParams: validateParamsPwGetPolicyRest,
},
{
async get() {
check(
this.queryParams,
Match.ObjectIncluding({
token: String,
}),
);
const { token } = this.queryParams;

const user = await UsersRaw.findOneByResetToken(token, { projection: { _id: 1 } });
if (!user) {
return API.v1.unauthorized();
}

return API.v1.success(passwordPolicy.getPasswordPolicy());
},
},
);

/**
* @openapi
* /api/v1/stdout.queue:
Expand Down
16 changes: 14 additions & 2 deletions apps/meteor/app/api/server/v1/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import type { ITeam } from '@rocket.chat/core-typings';
import { TEAM_TYPE } from '@rocket.chat/core-typings';

import { removeUserFromRoom } from '../../../lib/server/functions/removeUserFromRoom';
import { Users } from '../../../models/server';
import { hasAtLeastOnePermission, hasPermission } from '../../../authorization/server';
import { Rooms, Users } from '../../../models/server';
import { canAccessRoom, hasAtLeastOnePermission, hasPermission } from '../../../authorization/server';
import { Team } from '../../../../server/sdk';
import { API } from '../api';

Expand Down Expand Up @@ -576,6 +576,18 @@ API.v1.addRoute(
return API.v1.failure('Team not found');
}

const room = Rooms.findOneById(teamInfo.roomId);

if (!room) {
return API.v1.failure('Room not found');
}

const canViewInfo = canAccessRoom(room, { _id: this.userId }) || hasPermission(this.userId, 'view-all-teams');

if (!canViewInfo) {
return API.v1.unauthorized();
}

return API.v1.success({ teamInfo });
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useTranslation,
TranslationKey,
useToastMessageDispatch,
useEndpoint,
} from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { Meteor } from 'meteor/meteor';
Expand All @@ -27,13 +28,14 @@ const ResetPassword = (): ReactElement => {
const resetPassword = useMethod('resetPassword');
const token = useRouteParameter('token');

const getPasswordPolicy = useMethod('getPasswordPolicy');
const getPasswordPolicy = useEndpoint('GET', '/v1/pw.getPolicy');
const getPasswordPolicyRest = useEndpoint('GET', '/v1/pw.getPolicyReset');

const dispatchToastMessage = useToastMessageDispatch();

const { data: { enabled: policyEnabled, policy: policies } = {} } = useQuery(
['login/password-policy', token],
async () => getPasswordPolicy(token ? { token } : undefined),
async () => (user || !token ? getPasswordPolicy() : getPasswordPolicyRest({ token })),
{
onError: (error: any) => {
dispatchToastMessage({ type: 'error', message: error });
Expand Down Expand Up @@ -103,7 +105,7 @@ const ResetPassword = (): ReactElement => {
<Field.Hint>
{policies?.map((policy, index) => (
<Box is='p' textAlign='start' key={index}>
{t(...policy)}
{t(...(policy as unknown as [name: TranslationKey, options?: Record<string, unknown>]))}
</Box>
))}
</Field.Hint>
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/room/Header/ToolBox/ToolBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useToolboxContext } from '../../lib/Toolbox/ToolboxContext';
import { useTab, useTabBarOpen } from '../../providers/ToolboxProvider';

const renderMenuOption: OptionRenderer = ({ label: { title, icon }, ...props }: any): ReactNode => (
<Option label={title} icon={icon} {...props} />
<Option label={title} icon={icon} data-qa-id={`ToolBoxAction-${icon}`} {...props} />
);

type ToolBoxProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { States, StatesIcon, StatesTitle, StatesSubtitle, StatesActions, StatesAction, Icon } from '@rocket.chat/fuselage';
import { ErrorBoundary } from '@rocket.chat/ui-client';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React, { ReactElement, ReactNode } from 'react';
import { ErrorBoundary } from 'react-error-boundary';

const MessageListErrorBoundary = ({ children }: { children: ReactNode }): ReactElement => {
const t = useTranslation();
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/client/views/room/Room/Room.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { ErrorBoundary } from '@rocket.chat/ui-client';
import { useUserPreference, useTranslation } from '@rocket.chat/ui-contexts';
import React, { useMemo, ReactElement } from 'react';
import { ErrorBoundary } from 'react-error-boundary';

import { useEmbeddedLayout } from '../../../hooks/useEmbeddedLayout';
import Announcement from '../Announcement';
Expand Down Expand Up @@ -43,7 +43,7 @@ export const Room = (): ReactElement => {
</RoomTemplate.Body>
{tab && (
<RoomTemplate.Aside data-qa-tabbar-name={tab.id}>
<ErrorBoundary>
<ErrorBoundary fallback={null}>
<SelectedMessagesProvider>
{typeof tab.template === 'string' && (
<VerticalBarOldActions {...tab} name={tab.template} tabBar={tabBar} rid={room._id} _id={room._id} />
Expand All @@ -58,7 +58,7 @@ export const Room = (): ReactElement => {
{appsContextualBarContext && (
<RoomTemplate.Aside data-qa-tabbar-name={appsContextualBarContext.viewId}>
<SelectedMessagesProvider>
<ErrorBoundary>
<ErrorBoundary fallback={null}>
<LazyComponent
template={AppsContextualBar}
viewId={appsContextualBarContext.viewId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const NotificationByDevice = ({ device, icon, children }: NotificationByD
</Box>
</Box>
}
data-qa-id={`${device}-notifications`}
>
<FieldGroup>{children}</FieldGroup>
</Accordion.Item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { IRoom, IUser } from '@rocket.chat/core-typings';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useTranslation, useMethod, useUserSubscription, useUserRoom, useUserId, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import {
useTranslation,
useUserSubscription,
useUserRoom,
useUserId,
useToastMessageDispatch,
useEndpoint,
} from '@rocket.chat/ui-contexts';
import { useMemo } from 'react';

import { Action } from '../../../../hooks/useActionSpread';
Expand All @@ -13,7 +20,7 @@ export const useIgnoreUserAction = (user: Pick<IUser, '_id' | 'username'>, rid:
const ownUserId = useUserId();
const dispatchToastMessage = useToastMessageDispatch();
const currentSubscription = useUserSubscription(rid);
const ignoreUser = useMethod('ignoreUser');
const ignoreUser = useEndpoint('GET', '/v1/chat.ignoreUser');

const isIgnored = currentSubscription?.ignored && currentSubscription.ignored.indexOf(uid) > -1;

Expand All @@ -25,7 +32,7 @@ export const useIgnoreUserAction = (user: Pick<IUser, '_id' | 'username'>, rid:

const ignoreUserAction = useMutableCallback(async () => {
try {
await ignoreUser({ rid, userId: uid, ignore: !isIgnored });
await ignoreUser({ rid, userId: uid, ignore: String(!isIgnored) });
if (isIgnored) {
dispatchToastMessage({ type: 'success', message: t('User_has_been_unignored') });
} else {
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/client/views/room/threads/ThreadComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
import { useLocalStorage } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch, useRoute, useUserId, useUserSubscription, useEndpoint, useMethod } from '@rocket.chat/ui-contexts';
import { useToastMessageDispatch, useRoute, useUserId, useUserSubscription, useEndpoint } from '@rocket.chat/ui-contexts';
import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';
import { Tracker } from 'meteor/tracker';
Expand Down Expand Up @@ -72,8 +72,8 @@ const ThreadComponent: FC<{
const following = !uid ? false : threadMessage?.replies?.includes(uid) ?? false;

const dispatchToastMessage = useToastMessageDispatch();
const followMessage = useMethod('followMessage');
const unfollowMessage = useMethod('unfollowMessage');
const followMessage = useEndpoint('POST', '/v1/chat.followMessage');
const unfollowMessage = useEndpoint('POST', '/v1/chat.unfollowMessage');

const setFollowing = useCallback<(following: boolean) => void>(
async (following) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Box } from '@rocket.chat/fuselage';
import React, { ReactElement, ReactNode } from 'react';

import Card from '../../../../../client/components/Card';
import EngagementDashboardCardErrorBoundary from './EngagementDashboardCardErrorBoundary';

type EngagementDashboardCardProps = {
children?: ReactNode;
title?: string;
};

const EngagementDashboardCard = ({ children, title = undefined }: EngagementDashboardCardProps): ReactElement => (
<Box mb='x16'>
<Card variant='light'>
{title && <Card.Title>{title}</Card.Title>}
<Card.Body>
<Card.Col>
<EngagementDashboardCardErrorBoundary>
<Box>{children}</Box>
</EngagementDashboardCardErrorBoundary>
</Card.Col>
</Card.Body>
</Card>
</Box>
);

export default EngagementDashboardCard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { States, StatesAction, StatesActions, StatesIcon, StatesSubtitle, StatesTitle } from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import { QueryErrorResetBoundary } from '@tanstack/react-query';
import React, { ReactElement, ReactNode, useState } from 'react';
import { ErrorBoundary } from 'react-error-boundary';

export type EngagementDashboardCardErrorBoundaryProps = {
children?: ReactNode;
};

const EngagementDashboardCardErrorBoundary = ({ children }: EngagementDashboardCardErrorBoundaryProps): ReactElement => {
const t = useTranslation();

const [error, setError] = useState<Error>();
const isError = (error: unknown): error is Error => error instanceof Error;

const errorHandler = (error: Error, info: { componentStack: string }): void => {
setError(error);
console.error('Uncaught Error:', error, info);
};

return (
<QueryErrorResetBoundary>
{({ reset }): ReactElement => (
<ErrorBoundary
children={children}
onError={errorHandler}
onReset={reset}
fallbackRender={({ resetErrorBoundary }): ReactElement => (
<States>
<StatesIcon name='circle-exclamation' />
<StatesTitle>{t('Something_Went_Wrong')}</StatesTitle>
<StatesSubtitle>{isError(error) && error?.message}</StatesSubtitle>
<StatesActions data-qa='EngagementDashboardCardErrorBoundary'>
<StatesAction onClick={(): void => resetErrorBoundary()}>{t('Retry')}</StatesAction>
</StatesActions>
</States>
)}
/>
)}
</QueryErrorResetBoundary>
);
};

export default EngagementDashboardCardErrorBoundary;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Box, Flex, InputBox } from '@rocket.chat/fuselage';
import React, { ReactElement, ReactNode } from 'react';

type EngagementDashboardCardFilterProps = {
children?: ReactNode;
};

const EngagementDashboardCardFilter = ({ children = <InputBox.Skeleton /> }: EngagementDashboardCardFilterProps): ReactElement => (
<Box display='flex' justifyContent='flex-end' alignItems='center' wrap='no-wrap'>
{children && <Flex.Item grow={0}>{children}</Flex.Item>}
</Box>
);

export default EngagementDashboardCardFilter;
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ const EngagementDashboardPage = ({ tab = 'users', onSelectTab }: EngagementDashb
);

return (
<Page>
<Page backgroundColor='neutral-100' data-qa='EngagementDashboardPage'>
<Page.Header title={t('Engagement_Dashboard')}>
<Select options={timezoneOptions} value={timezoneId} onChange={handleTimezoneChange} />
</Page.Header>
<Tabs>
<Tabs.Item selected={tab === 'users'} onClick={handleTabClick('users')}>
<Tabs.Item data-qa-id='EngagementDashboardPage-usersTab' selected={tab === 'users'} onClick={handleTabClick('users')}>
{t('Users')}
</Tabs.Item>
<Tabs.Item selected={tab === 'messages'} onClick={handleTabClick('messages')}>
<Tabs.Item data-qa-id='EngagementDashboardPage-messagesTab' selected={tab === 'messages'} onClick={handleTabClick('messages')}>
{t('Messages')}
</Tabs.Item>
<Tabs.Item selected={tab === 'channels'} onClick={handleTabClick('channels')}>
<Tabs.Item data-qa-id='EngagementDashboardPage-channelsTab' selected={tab === 'channels'} onClick={handleTabClick('channels')}>
{t('Channels')}
</Tabs.Item>
</Tabs>
Expand Down
26 changes: 0 additions & 26 deletions apps/meteor/ee/client/views/admin/engagementDashboard/Section.tsx

This file was deleted.

Loading

0 comments on commit 0588618

Please sign in to comment.