Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype of rewritten Administration > Users and Administration > Rooms #17281

Merged
merged 76 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
d92a7bd
init
gabriellsh Apr 7, 2020
68d55a9
Added route, changes in directoryTable
gabriellsh Apr 13, 2020
ad7b0a5
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into adm/…
gabriellsh Apr 14, 2020
c1c26b8
Users and Rooms working partially
gabriellsh Apr 14, 2020
dbb2c54
lint
gabriellsh Apr 14, 2020
e792cba
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into adm/…
gabriellsh Apr 15, 2020
b345151
Added permissions, tabs now clickable
gabriellsh Apr 15, 2020
bfd8f06
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into adm/…
ggazzo Apr 16, 2020
4a2b5aa
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into adm/…
ggazzo Apr 16, 2020
1273706
Avatar provider
ggazzo Apr 16, 2020
d64d67f
Page Content
ggazzo Apr 16, 2020
0b94585
fix multiple call rest api directory
ggazzo Apr 16, 2020
41ba0a1
VerticalBar
ggazzo Apr 16, 2020
333f377
deep navigation
ggazzo Apr 16, 2020
32a1d5a
rename tab component
ggazzo Apr 16, 2020
612b5be
anchor table
ggazzo Apr 16, 2020
83dd5c5
refactor using props
ggazzo Apr 16, 2020
527a1a6
admin routes
ggazzo Apr 16, 2020
c3d354b
Removed imports from '.' and created hooks file
gabriellsh Apr 16, 2020
0f8d2cd
Fixed array type for query parameters
gabriellsh Apr 16, 2020
7aee377
Made Table generic, Renamed users and rooms routes
gabriellsh Apr 16, 2020
c10c42d
Lint, Stories
gabriellsh Apr 16, 2020
fbfe9f7
Removed underscore calls
gabriellsh Apr 16, 2020
a69c028
removed debounde reference
gabriellsh Apr 16, 2020
afa1f0b
Changed folders, fixed discussion icon/type
gabriellsh Apr 16, 2020
b886337
fix calling multipe times endpoint
ggazzo Apr 17, 2020
2e94d64
improve labels
ggazzo Apr 17, 2020
bda8a99
fix margin
ggazzo Apr 17, 2020
00a7273
add new button
ggazzo Apr 17, 2020
f4a0264
edit room first iteration with all fields
gabriellsh Apr 17, 2020
5f96a40
Removed comments, reset
gabriellsh Apr 17, 2020
03d272c
saveRoomSettings rest api
ggazzo Apr 17, 2020
60beb92
Archivation and saving edits
gabriellsh Apr 18, 2020
3855ca5
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into adm/…
gabriellsh Apr 18, 2020
34be166
Avatar fix
gabriellsh Apr 18, 2020
c815753
fixed NotAuthorizedPage import
gabriellsh Apr 18, 2020
3d1fb6b
Removed unused component import
gabriellsh Apr 18, 2020
c95b76e
Added delete button to editRoom
gabriellsh Apr 18, 2020
8f38a0d
UserInfo mockup
gabriellsh Apr 18, 2020
6dd92b5
fix review admin room
ggazzo Apr 18, 2020
14f146d
Merge branch 'adm/users_and_rooms' of github.com:RocketChat/Rocket.Ch…
ggazzo Apr 18, 2020
93654eb
caguei
ggazzo Apr 18, 2020
ce625f9
User info showing data
gabriellsh Apr 19, 2020
26f440f
Adjust Margins
gabriellsh Apr 19, 2020
a9199ff
userinfo: added missing fields
gabriellsh Apr 19, 2020
a69d679
Added missing translations
gabriellsh Apr 19, 2020
57f0d21
updated import
gabriellsh Apr 19, 2020
a88e6c0
Open direct messages
gabriellsh Apr 19, 2020
c50f599
Init edit users
gabriellsh Apr 19, 2020
284c3ae
Email verified symbol
gabriellsh Apr 19, 2020
62fbe62
backup
gabriellsh Apr 19, 2020
cb6e81f
AddUser, open context by ID
gabriellsh Apr 20, 2020
28cbe4e
improve
ggazzo Apr 20, 2020
4ab3608
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into adm/…
ggazzo Apr 20, 2020
efb3c4a
preparing avatar upload
ggazzo Apr 20, 2020
d6b209f
Missing translation
gabriellsh Apr 21, 2020
750b050
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into adm/…
gabriellsh Apr 21, 2020
7f09d07
Fixed roles wrap
gabriellsh Apr 21, 2020
d4d0136
user.create and update bio fields
ggazzo Apr 22, 2020
a6a7988
Merge branch 'adm/users_and_rooms' of github.com:RocketChat/Rocket.Ch…
gabriellsh Apr 22, 2020
04daffe
Avatar init
gabriellsh Apr 22, 2020
3329779
New avatar componentes and SetAvatar
gabriellsh Apr 23, 2020
6f65c05
Changed folder structure
gabriellsh Apr 23, 2020
77e801d
User Invite done.
gabriellsh Apr 23, 2020
b567c4e
Removed imaginary props, removed console.logs
gabriellsh Apr 23, 2020
0f8b87b
small fixes
gabriellsh Apr 23, 2020
a5f93f5
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into adm/…
gabriellsh Apr 23, 2020
feb4379
upload avatar via rest
gabriellsh Apr 23, 2020
213f10f
Missing field
gabriellsh Apr 23, 2020
aec1a03
lint
gabriellsh Apr 23, 2020
daaab14
Merge branch 'admin-refactor' of github.com:RocketChat/Rocket.Chat in…
tassoevan Apr 27, 2020
3dd0b49
Add useUpload to ServerContext
tassoevan Apr 27, 2020
e9d655a
Rename component
tassoevan Apr 27, 2020
e52bad6
Split UserAvatar and RoomAvatar
tassoevan Apr 27, 2020
03e0931
Move useFileInput hook
tassoevan Apr 27, 2020
c5f5393
Refactor VerticalBar
tassoevan Apr 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/api/server/lib/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ export async function findAdminRooms({ uid, filter, types = [], pagination: { of
};
}

export async function findAdminRoom({ uid, rid }) {
if (!await hasPermissionAsync(uid, 'view-room-administration')) {
throw new Error('error-not-authorized');
}
const fields = {
prid: 1,
fname: 1,
name: 1,
t: 1,
cl: 1,
u: 1,
usernames: 1,
usersCount: 1,
muted: 1,
unmuted: 1,
ro: 1,
default: 1,
favorite: 1,
featured: 1,
topic: 1,
msgs: 1,
archived: 1,
tokenpass: 1,
};

return Rooms.findOneById(rid, { fields });
}

export async function findChannelAndPrivateAutocomplete({ uid, selector }) {
if (!await hasPermissionAsync(uid, 'view-other-user-channels')) {
return { items: [] };
Expand Down
43 changes: 42 additions & 1 deletion app/api/server/v1/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Busboy from 'busboy';
import { FileUpload } from '../../../file-upload';
import { Rooms, Messages } from '../../../models';
import { API } from '../api';
import { findAdminRooms, findChannelAndPrivateAutocomplete } from '../lib/rooms';
import { findAdminRooms, findChannelAndPrivateAutocomplete, findAdminRoom } from '../lib/rooms';

function findRoomByIdOrName({ params, checkedArchived = true }) {
if ((!params.roomId || !params.roomId.trim()) && (!params.roomName || !params.roomName.trim())) {
Expand Down Expand Up @@ -299,6 +299,22 @@ API.v1.addRoute('rooms.adminRooms', { authRequired: true }, {
},
});

API.v1.addRoute('rooms.adminRooms.getRoom', { authRequired: true }, {
get() {
const { rid } = this.requestParams();
const room = Promise.await(findAdminRoom({
uid: this.userId,
rid,
}));

if (!room) {
return API.v1.failure('not-allowed', 'Not Allowed');
}
return API.v1.success(room);
},
});


API.v1.addRoute('rooms.autocomplete.channelAndPrivate', { authRequired: true }, {
get() {
const { selector } = this.queryParams;
Expand All @@ -312,3 +328,28 @@ API.v1.addRoute('rooms.autocomplete.channelAndPrivate', { authRequired: true },
})));
},
});

API.v1.addRoute('rooms.saveRoomSettings', { authRequired: true }, {
post() {
const { rid, ...params } = this.bodyParams;

const result = Meteor.runAsUser(this.userId, () => Meteor.call('saveRoomSettings', rid, params));

return API.v1.success({ rid: result.rid });
},
});

API.v1.addRoute('rooms.changeArchivationState', { authRequired: true }, {
post() {
const { rid, action } = this.bodyParams;

let result;
if (action === 'archive') {
result = Meteor.runAsUser(this.userId, () => Meteor.call('archiveRoom', rid));
} else {
result = Meteor.runAsUser(this.userId, () => Meteor.call('unarchiveRoom', rid));
}

return API.v1.success({ result });
},
});
3 changes: 3 additions & 0 deletions app/api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ API.v1.addRoute('users.create', { authRequired: true }, {
password: String,
username: String,
active: Match.Maybe(Boolean),
bio: Match.Maybe(String),
statusText: Match.Maybe(String),
roles: Match.Maybe(Array),
joinDefaultChannels: Match.Maybe(Boolean),
requirePasswordChange: Match.Maybe(Boolean),
Expand Down Expand Up @@ -431,6 +433,7 @@ API.v1.addRoute('users.update', { authRequired: true, twoFactorRequired: true },
name: Match.Maybe(String),
password: Match.Maybe(String),
username: Match.Maybe(String),
bio: Match.Maybe(String),
statusText: Match.Maybe(String),
active: Match.Maybe(Boolean),
roles: Match.Maybe(Array),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/lib/roomTypes/direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class DirectMessageRoomType extends RoomTypeConfig {
: Subscriptions.findOne({ rid: roomData._id });

if (subscription === undefined) {
return console.log('roomData', roomData);
return;
}

if (settings.get('UI_Use_Real_Name') && subscription.fname) {
Expand Down
4 changes: 2 additions & 2 deletions app/ui-admin/client/components/info/InformationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function InformationPage({
</ButtonGroup>}
</Page.Header>

<Page.Content>
<Page.ContentShadowScroll>
{alertOplogForMultipleInstances
&& <Margins blockEnd='x16'>
<Callout type='danger' title={t('Error_RocketChat_requires_oplog_tailing_when_running_in_multiple_instances')}>
Expand All @@ -62,6 +62,6 @@ export function InformationPage({
<BuildEnvironmentSection info={info} />
{canViewStatistics && <UsageSection statistics={statistics} isLoading={isLoading} />}
<InstancesSection instances={instances} />
</Page.Content>
</Page.ContentShadowScroll>
</Page>;
}
18 changes: 7 additions & 11 deletions app/ui-admin/client/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
// import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { Meteor } from 'meteor/meteor';

import { renderRouteComponent } from '../../../client/reactAdapters';
Expand Down Expand Up @@ -43,20 +43,16 @@ registerAdminRoute('/mailer', {
lazyRouteComponent: () => import('./components/mailer/MailerRoute'),
});

registerAdminRoute('/users', {
registerAdminRoute('/users/:context?/:id?', {
name: 'admin-users',
action: async () => {
await import('./users/views');
BlazeLayout.render('main', { center: 'adminUsers' });
},
lazyRouteComponent: () => import('../../../client/admin/users/AdminUsersRoute'),
tab: 'users',
});

registerAdminRoute('/rooms', {
registerAdminRoute('/rooms/:context?/:id?', {
name: 'admin-rooms',
action: async () => {
await import('./rooms/views');
BlazeLayout.render('main', { center: 'adminRooms' });
},
lazyRouteComponent: () => import('../../../client/admin/rooms/AdminRoomsRoute'),
tab: 'rooms',
});

Meteor.startup(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useMemo, useState, useEffect, useCallback } from 'react';
import { Box, Icon, Pagination, Skeleton, Table, Flex, TextInput, Tile } from '@rocket.chat/fuselage';
import { Box, Pagination, Skeleton, Table, Flex, Tile, Scrollable } from '@rocket.chat/fuselage';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';

import { useTranslation } from '../../../../../../../client/contexts/TranslationContext';
import { Markdown as mrkd } from '../../../../../../markdown/client';
import { useTranslation } from '../../../../client/contexts/TranslationContext';
import { Markdown as mrkd } from '../../../markdown/client';

function SortIcon({ direction }) {
return <Box is='svg' width='x16' height='x16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'>
Expand Down Expand Up @@ -42,33 +42,28 @@ const LoadingRow = ({ cols }) => <Table.Row>
</Table.Cell>)}
</Table.Row>;

const style = { minHeight: '40px' };

export function DirectoryTable({
data = {},
export function GenericTable({
results,
total,
renderRow,
header,
searchPlaceholder = 'placeholder',
setParams = () => { },
params: paramsDefault = '',
FilterComponent = () => null,
}) {
const t = useTranslation();

const [text, setText] = useState('');
const [filter, setFilter] = useState(paramsDefault);

const [itemsPerPage, setItemsPerPage] = useState(25);

const [current, setCurrent] = useState(0);

const term = useDebouncedValue(text, 500);
const params = useDebouncedValue(filter, 500);

useEffect(() => {
setParams({ term, current, itemsPerPage });
}, [term, current, itemsPerPage]);

const { result: channels, total } = data;


const handleChange = useCallback((event) => setText(event.currentTarget.value), []);
setParams({ ...params, current, itemsPerPage });
}, [params, current, itemsPerPage]);

const Loading = useCallback(() => Array.from({ length: 10 }, (_, i) => <LoadingRow cols={header.length} key={i}/>), [header && header.length]);

Expand All @@ -77,40 +72,40 @@ export function DirectoryTable({
const itemsPerPageLabel = useCallback(() => t('Items_per_page:'), []);

return <>
<Flex.Container direction='column'>
<Box>
<Box mb='x16' display='flex' flexDirection='column' style={style}>
<TextInput placeholder={searchPlaceholder} addon={<Icon name='magnifier' size='x20'/>} onChange={handleChange} value={text} />
</Box>
{channels && !channels.length
? <Tile textStyle='p1' elevation='0' textColor='info' style={{ textAlign: 'center' }}>
{t('No_data_found')}
</Tile>
: <>
<Table fixed>
{ header && <Table.Head>
<Table.Row>
{header}
</Table.Row>
</Table.Head> }
<Table.Body>
{channels
? channels.map(renderRow)
: <Loading/>}
</Table.Body>
</Table>
<Pagination
current={current}
itemsPerPage={itemsPerPage}
itemsPerPageLabel={itemsPerPageLabel}
showingResultsLabel={showingResultsLabel}
count={total || 0}
onSetItemsPerPage={setItemsPerPage}
onSetCurrent={setCurrent}
/>
</>
}
</Box>
</Flex.Container>
<>
<FilterComponent setFilter={setFilter}/>
{results && !results.length
? <Tile textStyle='p1' elevation='0' textColor='info' style={{ textAlign: 'center' }}>
{t('No_data_found')}
</Tile>
: <>
<Scrollable>
<Box mi={'neg-x24'} pi={'x24'} flexGrow={1}>
<Table fixed>
{ header && <Table.Head>
<Table.Row>
{header}
</Table.Row>
</Table.Head> }
<Table.Body>
{results
? results.map(renderRow)
: <Loading/>}
</Table.Body>
</Table>
</Box>
</Scrollable>
<Pagination
current={current}
itemsPerPage={itemsPerPage}
itemsPerPageLabel={itemsPerPageLabel}
showingResultsLabel={showingResultsLabel}
count={total || 0}
onSetItemsPerPage={setItemsPerPage}
onSetCurrent={setCurrent}
/>
</>
}
</>
</>;
}
27 changes: 27 additions & 0 deletions app/ui/client/components/GenericTable.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { TextInput, Box, Icon } from '@rocket.chat/fuselage';

import { GenericTable, Th } from './GenericTable';


export default {
title: 'directory/table',
component: GenericTable,
decorators: [(fn) => <div children={fn()} style={{ height: '100vh' }} />],
};


export const _default = () => {
const Search = () => <Box mb='x16' is='form' display='flex' flexDirection='column'>
<TextInput placeholder='Search...' addon={<Icon name='magnifier' size='x20'/>}/>
</Box>;


const header = [
<Th>Name</Th>,
<Th>Email</Th>,
<Th>Data</Th>,
<Th>Info</Th>,
];
return <GenericTable FilterComponent={Search} header={header} />;
};
Loading