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

Flex-Tab CoffeeScript to JavaScript III #6278

Merged
merged 6 commits into from
Mar 23, 2017
Merged

Flex-Tab CoffeeScript to JavaScript III #6278

merged 6 commits into from
Mar 23, 2017

Conversation

MartinSchoeler
Copy link
Contributor

@RocketChat/core
Please let me know if i left anything wrong, since this is a big file.

@MartinSchoeler MartinSchoeler requested a review from rodrigok March 7, 2017 18:19
@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-6278 March 7, 2017 18:19 Inactive
@MartinSchoeler MartinSchoeler changed the title userInfo.coffee to js Flex-Tab CoffeeScript to JavaScript III Mar 7, 2017
Copy link
Member

@marceloschmidt marceloschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have stopped looking for more errors, since after you make the requested changes I'll have to look all over again... please fix all == to === and != to !== and double-check places where you are not checking for the existence of the variable, such as Template.instance().user.get() (where coffeescript uses ? to check for existence).


email() {
const user = Template.instance().user.get();
if (user.emails && user.emails[0] && user.emails[0].address) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note you may use return user.emails && user.emails[0] && user.emails[0].address;

},

canDirectMessage(username) {
return RocketChat.authz.hasAllPermission('create-d') && (Meteor.user.username !== username);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail: Meteor.user.username !== username. Use Meteor.user() && Meteor.user().username !== username;

},

isModerator() {
return !!RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': Template.instance().user.get()._id, roles: 'moderator' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking if Template.instance().user.get() is null or undefined

},

isOwner() {
return !!RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': Template.instance().user.get()._id, roles: 'owner' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking if Template.instance().user.get() is null or undefined

},

hasAdminRole() {
return RocketChat.authz.hasRole(Template.instance().user.get()._id, 'admin');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking if Template.instance().user.get() is null or undefined


roleTags() {
const uid = Template.instance().user.get()._id;
const roles = _.union(UserRoles.findOne(uid).roles, RoomRoles.findOne({'u._id': uid, rid: Session.get('openedRoom') }).roles);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking if UserRoles.findOne(uid) is null or undefined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking if RoomRoles.findOne({'u._id': uid, rid: Session.get('openedRoom') }) is null of undefined

closeOnConfirm: false,
html: false
}, () => {
return Meteor.call('removeUserFromRoom', { rid, username: instance.user.get().usernamed }, (err) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a d on instance.user.get().usernamed

const rid = Session.get('openedRoom');
//const room = ChatRoom.findOne(rid); // never used
if (RocketChat.authz.hasAllPermission('mute-user', rid)) {
return Meteor.call('unmuteUserInRoom', { rid, username: t.user.get().username }, function(err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking if t.user.get() is null or undefined

'click .set-moderator'(e, t) {
e.preventDefault();

const userModerator = RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': t.user.get()._id, roles: 'moderator' }, { fields: { _id: 1 } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not checking if t.instance().user.get() is null or undefined

e.preventDefault();

const userModerator = RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': t.user.get()._id, roles: 'moderator' }, { fields: { _id: 1 } });
if (userModerator == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using == instead of ===

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check for undefined

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-6278 March 21, 2017 21:17 Inactive
@MartinSchoeler
Copy link
Contributor Author

@marceloschmidt changed some things could you do a review again? Thanks!

@marceloschmidt marceloschmidt self-assigned this Mar 21, 2017
},

canDirectMessage(username) {
return RocketChat.authz.hasAllPermission('create-d') && (Meteor.user && Meteor.user.username !== username);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meteor.user is a function


linkedinUsername() {
const user = Template.instance().user.get();
if (user.services && user.services.linkedin && user.services.linkedin.publicProfileUrl) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user can be undefined

},

roleTags() {
const uid = Template.instance().user.get()._id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template.instance().user.get() can be null

roleTags() {
const uid = Template.instance().user.get()._id;
if (uid) {
const roles = _.union(UserRoles.findOne(uid).roles, RoomRoles.findOne({'u._id': uid, rid: Session.get('openedRoom') }).roles);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserRoles.findOne(uid) can be null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RoomRoles.findOne({'u._id': uid, rid: Session.get('openedRoom') }) can be null

closeOnConfirm: false,
html: false
}, () => {
return Meteor.call('removeUserFromRoom', { rid, username: instance.user.get().username }, (err) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance.user.get() can be null

'click .unset-moderator'(e, t) {
e.preventDefault();
const user = t.user.get();
const userModerator = RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': user._id, roles: 'moderator' }, { fields: { _id: 1 } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user can be null

'click .set-owner'(e, t) {
e.preventDefault();
const user = t.user.get();
const userOwner = RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': user._id, roles: 'owner' }, { fields: { _id: 1 } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user can be null

'click .unset-owner'(e, t) {
e.preventDefault();
const user = t.user.get();
const userOwner = RoomRoles.findOne({ rid: Session.get('openedRoom'), 'u._id': user._id, roles: 'owner' }, { fields: { _id: 1 } });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user can be null

html: false
}, function() {
swal.disableButtons();
return Meteor.call('deleteUser', user._id, function(error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user can be null

this.autorun(() => {
username = this.loadedUsername.get();

if ((username == null)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ((?

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-6278 March 22, 2017 13:45 Inactive
@rodrigok
Copy link
Member

@marceloschmidt can you review again?

@rodrigok rodrigok modified the milestone: 0.55.0 Mar 22, 2017
Template.userInfo.helpers({
name() {
const user = Template.instance().user.get();
return user.name ? user.name : TAPi18n.__('Unnamed');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return user && user.name ? user.name : TAPi18n.__('Unnamed');

@rodrigok rodrigok modified the milestone: 0.55.0 Mar 23, 2017
@rodrigok rodrigok merged commit 5344047 into develop Mar 23, 2017
@rodrigok rodrigok deleted the flex-tab-to-js-3 branch March 23, 2017 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants