Skip to content

Commit 75ccf10

Browse files
author
Romaric Mourgues
authored
🛠 Before go to production 21/04 fixes (#2105)
* Fix securirty issue * Fix ensure badge is reachable * Fix missing user name in mentions * Fix channels bar load time and bold channels * Fix search for start direct chat with user * Fix #2083
1 parent ccd6266 commit 75ccf10

File tree

15 files changed

+81
-56
lines changed

15 files changed

+81
-56
lines changed

twake/backend/core/src/Twake/Drive/Services/DrivePreview.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function generatePreview($filename, $file, $path, $ext, $entity = null)
4545
$filetype === 'image/gif' ||
4646
$filetype === 'image/x-icon' ||
4747
$filetype === 'image/jpeg' ||
48-
$filetype === 'image/svg+xml' ||
4948
$filetype === 'image/tiff' ||
5049
$filetype === 'image/webp' ||
5150
$this->isImage($ext)) {

twake/backend/node/src/services/notifications/services/badges/service.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ export class UserNotificationBadgeService implements UserNotificationBadgeServic
162162
user: { id: channelMemberPk.user_id, server_request: true },
163163
channel: { id: channelId, ...channelMemberPk },
164164
};
165-
const exists = await this.channelsService.members.get(channelMemberPk, context);
165+
const exists =
166+
(await this.channelsService.channels.get({
167+
id: channelId,
168+
..._.pick(channelMemberPk, "company_id", "workspace_id"),
169+
})) && (await this.channelsService.members.get(channelMemberPk, context));
166170
if (!exists) {
167171
for (const badge of badges.getEntities()) {
168172
if (badge.channel_id === channelId) this.removeUserChannelBadges(badge);
@@ -179,10 +183,15 @@ export class UserNotificationBadgeService implements UserNotificationBadgeServic
179183
continue;
180184
}
181185
try {
182-
const exists = await this.userService.workspaces.getUser({
183-
workspaceId,
184-
userId,
185-
});
186+
const exists =
187+
(await this.userService.workspaces.get({
188+
id: workspaceId,
189+
company_id: companyId,
190+
})) &&
191+
(await this.userService.workspaces.getUser({
192+
workspaceId,
193+
userId,
194+
}));
186195
if (!exists) {
187196
await this.channelsService.members.ensureUserNotInWorkspaceIsNotInChannel(
188197
{ id: userId },

twake/frontend/src/app/components/twacode/pseudo-markdown-dictionary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export const DynamicComponent = ({
215215
(data.full_width ? 'full_width ' : '')
216216
}
217217
defaultValue={data.content || ''}
218-
placeholder={data.placeholder}
218+
placeholder={data.placeholder || 'Write something...'}
219219
onChange={(evt: any) => {
220220
eventContainer.onAction(
221221
'interactive_change',

twake/frontend/src/app/components/ui/user-or-mail.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ const EmailRow = ({ email }: { email: string }): JSX.Element => {
2727
const UserRow = ({ id }: { id: string }): JSX.Element => {
2828
const user = useUser(id);
2929

30+
if (user) {
31+
console.log(UsersService.getFullName(user));
32+
} else {
33+
console.log('user not found');
34+
}
35+
3036
return user ? (
3137
<>
3238
<Col className="icon">
3339
<Avatar size={20} src={UsersService.getThumbnail(user)} />
3440
</Col>
35-
<Col className="text" flex="auto">
41+
<Col
42+
className="text"
43+
flex="auto"
44+
style={{ overflow: 'auto', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}
45+
>
3646
<Text strong>{UsersService.getFullName(user)}</Text>
3747
<Text>{user.email ? `, ${user.email}` : ''}</Text>
3848
</Col>

twake/frontend/src/app/components/user-list-manager/user-list-manager.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useEffect, useRef } from 'react';
22
import { Button, Col, Row, Typography } from 'antd';
33
import classNames from 'classnames';
44
import TrashIcon from '@material-ui/icons/DeleteOutlined';
@@ -30,13 +30,18 @@ const UserListManager = (props: PropsType) => {
3030
const [input, setInput] = useState<string>('');
3131
const [editing, setEditing] = useState<boolean>(props.autoFocus ? props.autoFocus : false);
3232
const [usersIds, setUsersIds] = useState<string[]>([...props.users]);
33+
const callback = useRef<Function>(() => {});
3334
let savedUserProps: string;
3435

3536
useEffect(() => {
3637
updateStateFromProps(props, true);
3738
// eslint-disable-next-line react-hooks/exhaustive-deps
3839
}, []);
3940

41+
useEffect(() => {
42+
callback.current(result.map(u => u.id));
43+
}, [result]);
44+
4045
const updateStateFromProps = (props: PropsType, force?: boolean) => {
4146
let anti_duplicates: string[] = [];
4247

@@ -54,23 +59,25 @@ const UserListManager = (props: PropsType) => {
5459
}
5560
};
5661

57-
const filter = (text: string, callback: (arr: any[]) => any) => {
62+
const filter = (text: string, cb: (arr: any[]) => any) => {
5863
setInput(text);
5964
if ((text || '').indexOf('@') > 0) {
6065
if (
6166
props.allowMails &&
6267
Strings.verifyMail(text) &&
6368
usersIds.indexOf(text.toLocaleLowerCase()) < 0
6469
) {
65-
callback([{ email: text.toLocaleLowerCase() }]);
70+
cb([{ email: text.toLocaleLowerCase() }]);
6671
return;
6772
}
68-
callback([]);
73+
cb([]);
6974
return;
7075
}
7176

72-
search(text);
73-
callback([...result.map(u => u.id)]);
77+
const tmp = search(text);
78+
cb([...tmp.map(u => u.id)]);
79+
80+
callback.current = cb;
7481
};
7582

7683
const renderLine = (item: any, added?: boolean): JSX.Element => {
@@ -139,7 +146,7 @@ const UserListManager = (props: PropsType) => {
139146
<div className={'users-list no-background'}>
140147
{usersIds.map((item: string, index: number) => (
141148
<div key={index} style={props.collapsed ? { display: 'inline-block' } : {}}>
142-
<Row align="middle" gutter={[8, 8]}>
149+
<Row align="middle" gutter={[8, 8]} style={{ flexFlow: 'nowrap' }}>
143150
{renderLine(item, true)}
144151
</Row>
145152
</div>
@@ -182,7 +189,7 @@ const UserListManager = (props: PropsType) => {
182189
}
183190
render={(user: UserType) => (
184191
<React.Suspense fallback={<></>}>
185-
<Row align="middle" gutter={[8, 8]}>
192+
<Row align="middle" gutter={[8, 8]} style={{ flexFlow: 'nowrap' }}>
186193
<UserOrMail item={user} />
187194
</Row>
188195
</React.Suspense>

twake/frontend/src/app/deprecated/user/CurrentUser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import JWTStorage from 'app/features/auth/jwt-storage-service';
1313
import Globals from 'app/features/global/services/globals-twake-app-service';
1414
import { useCurrentUser } from 'app/features/users/hooks/use-current-user';
1515
import UserAPIClient from '../../features/users/api/user-api-client';
16+
import { getUser } from 'app/features/users/hooks/use-user-list';
1617

1718
class CurrentUser extends Observable {
1819
loading: boolean;
@@ -48,7 +49,7 @@ class CurrentUser extends Observable {
4849
start() {}
4950

5051
get() {
51-
return Collections.get('users').find(Login.currentUserId);
52+
return getUser(Login.currentUserId);
5253
}
5354

5455
updateUserStatus = (newStatus: string[]) => {

twake/frontend/src/app/features/messages/hooks/use-message.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { useRecoilCallback, useRecoilState } from 'recoil';
55
import { AtomMessageKey, MessageState } from '../state/atoms/messages';
66
import { NodeMessage, NodeMessageSubType, ReactionType } from 'app/features/messages/types/message';
77
import { messageToMessageWithReplies } from '../utils/message-with-replies';
8-
import { UserState } from 'app/features/users/state/atoms/user';
9-
import { setUserList, useSetUserList } from 'app/features/users/hooks/use-user-list';
10-
import { UserListState } from 'app/features/users/state/atoms/user-list';
8+
import { useSetUserList } from 'app/features/users/hooks/use-user-list';
119

1210
export const useMessage = (partialKey: AtomMessageKey) => {
1311
const key = {

twake/frontend/src/app/features/users/hooks/use-search-user-list.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import UserAPIClient, { SearchContextType } from '../api/user-api-client';
77
import { delayRequest } from 'app/features/global/utils/managedSearchRequest';
88
import Strings from 'app/features/global/utils/strings';
99
import useRouterWorkspace from 'app/features/router/hooks/use-router-workspace';
10+
import _ from 'lodash';
1011

1112
export const searchBackend = async (
1213
query: string | undefined,
@@ -102,16 +103,19 @@ export const useSearchUserList = ({
102103
}: {
103104
scope: SearchContextType['scope'];
104105
}): {
105-
search: (str?: string) => void;
106+
search: (str?: string) => UserType[];
106107
result: UserType[];
107108
} => {
108109
const { set: setUserList } = useSetUserList('use-search-user-list');
109110
const [query, setQuery] = useState<string | undefined>();
110-
const { userList } = useUserList();
111+
let { userList } = useUserList();
112+
userList = _.uniqBy(userList, 'id');
113+
111114
const companyId = useRouterCompany();
112115
const workspaceId = useRouterWorkspace();
113-
const search = async (str?: string) => {
116+
const search = (str?: string) => {
114117
setQuery(str);
118+
return searchFrontend(str, { workspaceId, scope, companyId, userList: userList || [] });
115119
};
116120

117121
useEffect(() => {

twake/frontend/src/app/features/users/hooks/use-user-list.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { useEffect } from 'react';
22
import { cloneDeep, concat, isEqual, uniqBy } from 'lodash';
3-
import { RecoilState, useRecoilCallback, useRecoilValueLoadable } from 'recoil';
3+
import { useRecoilCallback, useRecoilValueLoadable } from 'recoil';
44

55
import useRouterCompany from 'app/features/router/hooks/use-router-company';
66
import useRouterWorkspace from 'app/features/router/hooks/use-router-workspace';
77
import { UserCompanyType, UserType, UserWorkspaceType } from 'app/features/users/types/user';
88
import WorkspaceUserAPIClient from 'app/features/workspace-members/api/workspace-members-api-client';
99
import { UserListState } from '../state/atoms/user-list';
1010
import Logger from 'app/features/global/framework/logger-service';
11+
import Collections from 'app/deprecated/CollectionsV1/Collections/Collections';
12+
import _ from 'lodash';
1113

1214
export const usePreloadSomeUsers = () => {
1315
const companyId = useRouterCompany();
@@ -84,6 +86,7 @@ export function useSetUserList(key: string) {
8486

8587
if (currentList && newList && !isEqual(currentList, newList)) {
8688
set(UserListState, newList);
89+
newList.forEach(user => Collections.get('users').completeObject(_.cloneDeep(user)));
8790
currentUserList = newList;
8891
}
8992
}

twake/frontend/src/app/features/users/services/current-user-service.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Languages from 'app/features/global/services/languages-service';
55
import { UserType } from 'app/features/users/types/user';
66
import { TwakeService } from 'app/features/global/framework/registry-decorator-service';
77
import { addApiUrlIfNeeded, getAsFrontUrl } from 'app/features/global/utils/URLUtils';
8+
import { getUser } from '../hooks/use-user-list';
89

910
type SearchQueryType = {
1011
searching: boolean;
@@ -29,7 +30,7 @@ class User {
2930
}
3031

3132
getCurrentUser(): UserType & { id: string } {
32-
return Collections.get('users').find(Login.currentUserId);
33+
return getUser(Login.currentUserId) as UserType & { id: string };
3334
}
3435

3536
getCurrentUserId(): string {
@@ -45,14 +46,9 @@ class User {
4546

4647
if (user.deleted) {
4748
name = Languages.t('general.user.deleted');
48-
}
49-
50-
if (user.first_name?.length) {
51-
name = user.first_name;
52-
}
53-
54-
if (user.first_name?.length && user.last_name?.length) {
55-
name = `${user.first_name} ${user.last_name}`;
49+
} else {
50+
name = [user.first_name, user.last_name].filter(a => a).join(' ');
51+
name = name || user.username;
5652
}
5753

5854
return name.charAt(0).toUpperCase() + name.slice(1);

0 commit comments

Comments
 (0)