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

[NEW] Directory page refactored, new user's bio field #17043

Merged
merged 37 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b3e0687
directory page using react
ggazzo Mar 27, 2020
4e9cacf
Update app/ui/client/views/app/components/Directory/ChannelsTab.js
ggazzo Mar 27, 2020
ce76a2a
fix review
ggazzo Mar 28, 2020
07e9e0b
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
ggazzo Mar 28, 2020
a17e249
Merge branch 'feat/directory' of github.com:RocketChat/Rocket.Chat in…
ggazzo Mar 28, 2020
34f67cf
avoiding few rerenders
ggazzo Mar 28, 2020
02d9af0
Merge branch 'develop' into feat/directory
ggazzo Mar 28, 2020
5fba758
Show correctly and search by discussions
rodrigok Mar 29, 2020
7ae1fc4
User Bio
ggazzo Mar 29, 2020
55227d3
Merge branch 'feat/directory' of github.com:RocketChat/Rocket.Chat in…
ggazzo Mar 29, 2020
f74215e
Featured channels
ggazzo Mar 29, 2020
7846c4f
Merge remote-tracking branch 'origin/develop' into feat/directory
rodrigok Mar 30, 2020
bdbe781
Featured on top always
rodrigok Mar 30, 2020
a5dcdb8
Remove topic column from users tab
rodrigok Mar 30, 2020
b988e29
Add bio as default field for searching
rodrigok Mar 30, 2020
06490a9
Sort List merged and using React
ggazzo Mar 30, 2020
1315766
Merge branch 'feat/directory' of github.com:RocketChat/Rocket.Chat in…
ggazzo Mar 30, 2020
146b30f
directory ui improve
ggazzo Mar 30, 2020
ffe552d
revert account to blaze
ggazzo Mar 30, 2020
b0aecad
useMediaQuery
ggazzo Mar 30, 2020
41db4ee
return routes
ggazzo Mar 30, 2020
5831794
fix member list
ggazzo Mar 30, 2020
c8e3a9c
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
ggazzo Mar 30, 2020
2c1fd08
fix text overflow
ggazzo Mar 30, 2020
6233d91
Use text index to search for users
rodrigok Mar 31, 2020
bc576df
Fix tests
rodrigok Mar 31, 2020
5498b3e
update fuselage
ggazzo Mar 31, 2020
e47e4ec
Merge branch 'feat/directory' of github.com:RocketChat/Rocket.Chat in…
ggazzo Mar 31, 2020
2862c2d
avatar size
ggazzo Mar 31, 2020
268baaf
Fix Lint
rodrigok Mar 31, 2020
749b92d
add bio limit to 256
ggazzo Mar 31, 2020
904efa8
Merge branch 'develop' into feat/directory
tassoevan Mar 31, 2020
c2e4467
Update app/channel-settings/server/methods/saveRoomSettings.js
ggazzo Mar 31, 2020
aea6951
Update app/lib/server/functions/saveUser.js
ggazzo Mar 31, 2020
e3a6508
260
ggazzo Mar 31, 2020
486af94
Merge branch 'feat/directory' of github.com:RocketChat/Rocket.Chat in…
ggazzo Mar 31, 2020
f360f96
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into feat…
ggazzo Apr 1, 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
1 change: 1 addition & 0 deletions app/api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ API.v1.addRoute('directory', { authRequired: true }, {
const { sort, query } = this.parseJsonQuery();

const { text, type, workspace = 'local' } = query;

if (sort && Object.keys(sort).length > 1) {
return API.v1.failure('This method support only one "sort" parameter');
}
Expand Down
1 change: 1 addition & 0 deletions app/api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ API.v1.addRoute('users.info', { authRequired: true }, {
user.rooms = Subscriptions.findByUserId(user._id, {
fields: {
rid: 1,
bio: 1,
name: 1,
t: 1,
roles: 1,
Expand Down
11 changes: 10 additions & 1 deletion app/channel-settings/server/methods/saveRoomSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { saveRoomTokenpass } from '../functions/saveRoomTokens';
import { saveStreamingOptions } from '../functions/saveStreamingOptions';
import { RoomSettingsEnum, roomTypes } from '../../../utils';

const fields = ['roomName', 'roomTopic', 'roomAnnouncement', 'roomCustomFields', 'roomDescription', 'roomType', 'readOnly', 'reactWhenReadOnly', 'systemMessages', 'default', 'joinCode', 'tokenpass', 'streamingOptions', 'retentionEnabled', 'retentionMaxAge', 'retentionExcludePinned', 'retentionFilesOnly', 'retentionOverrideGlobal', 'encrypted'];
const fields = ['featured', 'roomName', 'roomTopic', 'roomAnnouncement', 'roomCustomFields', 'roomDescription', 'roomType', 'readOnly', 'reactWhenReadOnly', 'systemMessages', 'default', 'joinCode', 'tokenpass', 'streamingOptions', 'retentionEnabled', 'retentionMaxAge', 'retentionExcludePinned', 'retentionFilesOnly', 'retentionOverrideGlobal', 'encrypted'];
Meteor.methods({
saveRoomSettings(rid, settings, value) {
const userId = Meteor.userId();
Expand Down Expand Up @@ -79,6 +79,12 @@ Meteor.methods({
action: 'Viewing_room_administration',
});
}
if (settings === 'featured' && !hasPermission(userId, 'view-room-administration')) {
throw new Meteor.Error('error-action-not-allowed', 'Viewing room administration is not allowed', {
method: 'saveRoomSettings',
action: 'Viewing_room_administration',
});
}
if (setting === 'roomType' && value !== room.t && value === 'c' && !hasPermission(userId, 'create-c')) {
throw new Meteor.Error('error-action-not-allowed', 'Changing a private group to a public channel is not allowed', {
method: 'saveRoomSettings',
Expand Down Expand Up @@ -194,6 +200,9 @@ Meteor.methods({
case 'default':
Rooms.saveDefaultById(rid, value);
break;
case 'featured':
Rooms.saveFeaturedById(rid, value);
break;
case 'retentionEnabled':
Rooms.saveRetentionEnabledById(rid, value);
break;
Expand Down
1 change: 1 addition & 0 deletions app/lib/server/functions/getFullUserData.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const fullFields = {
emails: 1,
phone: 1,
statusConnection: 1,
bio: 1,
createdAt: 1,
lastLogin: 1,
services: 1,
Expand Down
26 changes: 22 additions & 4 deletions app/lib/server/functions/saveUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,23 @@ function validateUserEditing(userId, userData) {
}
}

const handleBio = (updateUser, bio) => {
if (bio) {
if (bio.trim()) {
if (typeof bio !== 'string' || bio.length > 260) {
throw new Meteor.Error('error-invalid-field', 'bio', {
method: 'saveUserProfile',
});
}
updateUser.$set = updateUser.$set || {};
updateUser.$set.bio = bio;
ggazzo marked this conversation as resolved.
Show resolved Hide resolved
} else {
updateUser.$unset = updateUser.$unset || {};
updateUser.$unset.bio = 1;
}
}
};

export const saveUser = function(userId, userData) {
validateUserData(userId, userData);
let sendPassword = false;
Expand Down Expand Up @@ -225,14 +242,11 @@ export const saveUser = function(userId, userData) {
const updateUser = {
$set: {
roles: userData.roles || ['user'],
...typeof userData.name !== 'undefined' && { name: userData.name },
settings: userData.settings || {},
},
};

if (typeof userData.name !== 'undefined') {
updateUser.$set.name = userData.name;
}

if (typeof userData.requirePasswordChange !== 'undefined') {
updateUser.$set.requirePasswordChange = userData.requirePasswordChange;
}
Expand All @@ -241,6 +255,8 @@ export const saveUser = function(userId, userData) {
updateUser.$set['emails.0.verified'] = userData.verified;
}

handleBio(updateUser, userData.bio);

Meteor.users.update({ _id }, updateUser);

if (userData.sendWelcomeEmail) {
Expand Down Expand Up @@ -294,6 +310,8 @@ export const saveUser = function(userId, userData) {
$set: {},
};

handleBio(updateUser, userData.bio);

if (userData.roles) {
updateUser.$set.roles = userData.roles;
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ settings.addGroup('Accounts', function() {
type: 'boolean',
public: true,
});
this.add('Accounts_SearchFields', 'username, name', {
this.add('Accounts_SearchFields', '', {
type: 'string',
public: true,
});
Expand Down
29 changes: 29 additions & 0 deletions app/models/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export class Rooms extends Base {

this.tryEnsureIndex({ name: 1 }, { unique: true, sparse: true });
this.tryEnsureIndex({ default: 1 });
this.tryEnsureIndex({ featured: 1 });
this.tryEnsureIndex({ t: 1 });
this.tryEnsureIndex({ 'u._id': 1 });
this.tryEnsureIndex({ 'tokenpass.tokens.token': 1 });
this.tryEnsureIndex({ ts: 1 });
// discussions
this.tryEnsureIndex({ prid: 1 }, { sparse: true });
this.tryEnsureIndex({ fname: 1 }, { sparse: true });
// Livechat - statistics
this.tryEnsureIndex({ closedAt: 1 }, { sparse: true });

Expand Down Expand Up @@ -414,6 +416,20 @@ export class Rooms extends Base {
return this._db.find(query, options);
}

findByNameOrFNameAndType(name, type, options) {
const query = {
t: type,
$or: [{
name,
}, {
fname: name,
}],
};

// do not use cache
return this._db.find(query, options);
}

findByNameAndTypeNotDefault(name, type, options) {
const query = {
t: type,
Expand Down Expand Up @@ -873,6 +889,19 @@ export class Rooms extends Base {
return this.update(query, update);
}

saveFeaturedById(_id, featured) {
const query = { _id };
const set = ['true', true].includes(featured);

const update = {
[set ? '$set' : '$unset']: {
featured: true,
},
};

return this.update(query, update);
}

saveDefaultById(_id, defaultValue) {
const query = { _id };

Expand Down
28 changes: 24 additions & 4 deletions app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class Users extends Base {

this.tryEnsureIndex({ roles: 1 }, { sparse: 1 });
this.tryEnsureIndex({ name: 1 });
this.tryEnsureIndex({ name: 'text', username: 'text', bio: 'text' }, { default_language: 'none', language_override: 'documentLanguage' });
this.tryEnsureIndex({ createdAt: 1 });
this.tryEnsureIndex({ lastLogin: 1 });
this.tryEnsureIndex({ status: 1 });
Expand Down Expand Up @@ -688,16 +689,20 @@ export class Users extends Base {
const searchFields = forcedSearchFields || settings.get('Accounts_SearchFields').trim().split(',');

const orStmt = _.reduce(searchFields, function(acc, el) {
acc.push({ [el.trim()]: termRegex });
el = el.trim();
if (el && !['name', 'username', 'bio'].includes(el)) {
acc.push({ [el]: termRegex });
}
return acc;
}, []);

const query = {
$and: [
{
active: true,
$or: orStmt,
},
{
$or: [{
$text: { $search: searchTerm },
}, ...orStmt],
username: { $exists: true, $nin: exceptions },
},
...extraQuery,
Expand Down Expand Up @@ -1117,6 +1122,21 @@ export class Users extends Base {
return this.update(_id, update);
}

setBio(_id, bio = '') {
const update = {
...bio.trim() ? {
$set: {
bio,
},
} : {
$unset: {
bio: 1,
},
},
};
return this.update(_id, update);
}

clearSettings(_id) {
const update = {
$set: {
Expand Down
49 changes: 29 additions & 20 deletions app/ui-account/client/accountProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,6 @@
{{/if}}
</div>
</div>
<div class="rc-form-group rc-grid">
{{# with canChange=allowStatusMessageChange}}

<div class="rc-input rc-w100 padded {{#if statusMessageInvalid}}rc-input--error{{/if}}">
<label class="rc-input__label">
<div class="rc-input__title">{{_ "StatusMessage"}}</div>
<div class="rc-input__wrapper">
<div class="rc-input__icon">
{{> icon block="rc-input__icon-svg" icon="edit"}}
</div>

<input type="text" class="rc-input__element" maxlength="120" name="statusText" id="statusText" placeholder="{{_ "StatusMessage_Placeholder" }}" value="{{statusText}}" {{ifThenElse canChange '' 'disabled'}}>
</div>
</label>
{{# unless canChange}}
<div class="rc-input__description">{{_ 'StatusMessage_Change_Disabled'}}</div>
{{/unless}}
</div>
{{/with}}
</div>
<div class="rc-form-group rc-grid">
{{# with canChange=allowRealNameChange}}
<div class="rc-input rc-w50 padded {{#if nameInvalid}}rc-input--error{{/if}}">
Expand Down Expand Up @@ -129,6 +109,35 @@
</div>
{{/with}}
</div>
<div class="rc-form-group rc-grid">
{{# with canChange=allowStatusMessageChange}}
<div class="rc-input rc-w100 padded {{#if statusMessageInvalid}}rc-input--error{{/if}}">
<label class="rc-input__label">
<div class="rc-input__title">{{_ "StatusMessage"}}</div>
<div class="rc-input__wrapper">
<div class="rc-input__icon">
{{> icon block="rc-input__icon-svg" icon="edit"}}
</div>

<input type="text" class="rc-input__element" maxlength="120" name="statusText" id="statusText" placeholder="{{_ "StatusMessage_Placeholder" }}" value="{{get 'statusText'}}" {{ifThenElse canChange '' 'disabled'}}>
</div>
</label>
{{# unless canChange}}
<div class="rc-input__description">{{_ 'StatusMessage_Change_Disabled'}}</div>
{{/unless}}
</div>
{{/with}}
</div>
<div class="rc-form-group">
<div class="rc-input rc-w100 padded">
<label class="rc-input__label">
<div class="rc-input__title">{{_ "Bio"}}</div>
<div class="rc-input__wrapper">
<textarea type="text" class="rc-input__element" name="bio" id="bio" maxlength="260" rows="4" style="height: auto" placeholder="{{_ "Bio_Placeholder" }}" value="{{get 'bio'}}"></textarea>
</div>
</label>
</div>
</div>
<div class="rc-form-group rc-grid">
{{#with canChange=allowEmailChange}}
<div class="rc-input rc-w50 padded {{#if emailInvalid}}rc-input--error{{/if}}">
Expand Down
Loading