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

[FIX] Sync of non existent field throws exception #8006

Merged

Conversation

goiaba
Copy link
Contributor

@goiaba goiaba commented Aug 31, 2017

  • checks if the field is whitelisted for sync
  • if a customField, checks its validity before syncing (through Accounts_CustomFields)
  • fixes the case when the field is still absent in the user document
  • This implementation does not allow dots in the customField name, because the dots would be treated as nested fields

@RocketChat/core

@rodrigok rodrigok added this to the 0.59.0-rc.4 milestone Aug 31, 2017
@rodrigok rodrigok self-requested a review August 31, 2017 23:02
@rodrigok
Copy link
Member

Awesome @goiaba

Can you create unit tests for this method? You can see some tests here https://github.com/RocketChat/Rocket.Chat/blob/develop/packages/rocketchat-markdown/tests/client.tests.js

You can run using meteor npm run testunit

@graywolf336
Copy link
Contributor

This implementation does not allow dots in the customField name, because the dots would be treated as nested fields

This has me worried. Does the existing behavior of Rocket.Chat allow dots in the customField name and it be treated as a regular field and not nested ones? If so, then this is a breaking change...

@rodrigok
Copy link
Member

rodrigok commented Sep 1, 2017

@graywolf336 The existing behavior is the same, the dot is allowed, the difference now is that you can access sub values of the LDAP object

@goiaba
Copy link
Contributor Author

goiaba commented Sep 1, 2017

@rodrigok Sure, I'll do it.

@graywolf336 Don't worry! They were already treated as nested fields in customFields (I was just emphasizing).

@gdelavald gdelavald modified the milestones: UI-Sprint-36, 0.59.0-rc.4 Sep 4, 2017
@engelgabriel engelgabriel modified the milestones: 0.60.0, 0.59.0-rc.4 Sep 5, 2017
@goiaba
Copy link
Contributor Author

goiaba commented Sep 5, 2017

@rodrigok I'm in trouble trying to create the unit tests. Following the example you gave me, I'm not able to import the mut in the test file. It complains that "ReferenceError: Logger is not defined". If I also import the Logger from rocketchat-logger/server.js, then it complains that "ReferenceError: EventEmitter is not defined"...

Any tips?

@vinimdocarmo
Copy link

@goiaba, I'll try to help you with the unit tests. But any tips from any of the core team members would be great.

@rodrigok
Copy link
Member

rodrigok commented Oct 9, 2017

@goiaba can you fix the conflicts?

@goiaba
Copy link
Contributor Author

goiaba commented Oct 9, 2017

@rodrigok

Yes, I can for sure.

Besides that, I would love get some help on developing the unit tests for this code. The code you told me to use as guide was not enough. Is there anyone that could help me with that?

@vinimdocarmo
Copy link

@goiaba Can you show them the problem that we were getting when executing the unit test? That error that occured because of some problem on package rocketchat:streamer.

- checks if the field is whitelisted for sync
- if a customField, checks its validity before syncing (through Accounts_CustomFields)
- fixes the case when the field is still absent in the user document
* This implementation does not allow dots in the customField name, because the dots would be treated as nested fields
@goiaba goiaba force-pushed the ldap-sync-custom-fields branch from 7ffcfe0 to 8601754 Compare November 8, 2017 09:37
@goiaba
Copy link
Contributor Author

goiaba commented Nov 9, 2017

Good idea!

@vinimdocarmo oriented me to follow this guide

So I added to packages/rocketchat-ldap/package.js all the packages that I thought rocketchat:ldap could depend upon (based on Package.onUse):

Package.onTest(function(api){
	api.use('rocketchat:ldap');

	api.use('rocketchat:ldapjs');
	api.use('rocketchat:logger');
	api.use('rocketchat:lib');
	api.use('yasaricli:slugify');
	api.use('ecmascript');
	api.use('sha');
	api.use(['ecmascript', 'random', 'practicalmeteor:mocha']);
	api.mainModule('tests/sync.tests.js');
});

Then I tried to run the tests this way:

[10:08:53] bruno@ideapad-Y700:~/CloudStorage/GitHub/Rocket.Chat$ meteor test-packages ./packages/rocketchat-ldap/

But the result was:

[[[[[ Tests ]]]]]                             

=> Started proxy.                             
=> Started MongoDB.                           
=> Errors prevented startup:                                                       
   
   While processing files with ecmascript (for target web.browser):
   packages/rocketchat:streamer/client/client.js:109:2: super() outside of class constructor (109:2)
   
   While processing files with ecmascript (for target os.linux.x86_64):
   packages/rocketchat:streamer/server/server.js:253:3: 'super' outside of function or class (253:3)
   
=> Your application has errors. Waiting for file change.

@rodrigok rodrigok merged commit 9fdf328 into RocketChat:develop Dec 6, 2017
@goiaba goiaba deleted the ldap-sync-custom-fields branch December 6, 2017 13:08
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.

6 participants