Skip to content

[12.0][MIG] web_notify #1071

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

Merged
merged 14 commits into from
Oct 15, 2018
Merged

[12.0][MIG] web_notify #1071

merged 14 commits into from
Oct 15, 2018

Conversation

aitorbouzas
Copy link
Contributor

Migrated and tested. Minor changes in JS.

Messed up the commit history in #1070
CC for help with JS/code review: @lmignon @JayVora-SerpentCS

lmignon and others added 13 commits October 10, 2018 10:40
This technical module allows you to send instant notification messages from the server to the user in live.
Fix a check when comparing a user count with items within a mock call.

The previous method was succeeding by pure luck because OCA test
databases contain 2 users, which happens to be the amount of items
within a mock "call_args" (it contains args + kwargs).
- Use the 'session' class of the JS Framework (session no lounger bound
to web client)
- Test change: compare emitted & received messages based on content, not
order. Using string comparison raises false positives.
Currently translated at 100,0% (5 of 5 strings)

Translation: web-11.0/web-11.0-web_notify
Translate-URL: https://translation.odoo-community.org/projects/web-11-0/web-11-0-web_notify/pt_BR/
Currently translated at 40.0% (2 of 5 strings)

Translation: web-11.0/web-11.0-web_notify
Translate-URL: https://translation.odoo-community.org/projects/web-11-0/web-11-0-web_notify/da/
Only the admin user (sudo) is allowed to send notifications to other
users. The normal users can only send notifications to themselves.

This is to prevent attackers to craft malicious notifications and send
them to other users using RPC.

Correction based on the idea of @hbrunn
@OCA-git-bot OCA-git-bot mentioned this pull request Oct 10, 2018
40 tasks
@pedrobaeza pedrobaeza added this to the 12.0 milestone Oct 10, 2018
Copy link
Contributor

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

LGTM (Code review only)

@pedrobaeza
Copy link
Member

Maybe we can add as demo data a button (or 2, one for each kind of notification) on user form for launching a default notification, which can be done using the message as keyword argument, and this way, we can self-test the module. What do you think?

@aitorbouzas
Copy link
Contributor Author

@pedrobaeza Awesome. Maybe we can show the buttons only when debug mode is active?

@pedrobaeza
Copy link
Member

Well, if we load them as demo, that extra layer maybe is not needed, but it's up to you to decide which one is best.

Copy link
Member

@nikul-serpentcs nikul-serpentcs left a comment

Choose a reason for hiding this comment

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

Minor Change

@aitorbouzas
Copy link
Contributor Author

@pedrobaeza Added the buttons and updated USAGE.rst to show how to test it.
There's only one little problem, the message keyword argument shows the context when using the buttons, why is the context parsed as message?

@pedrobaeza
Copy link
Member

Uhm, maybe there's an argument mix, but I'm testing on runbot and can't get the notification. I think it's better to put the buttons on user form, not user preferences. Being a popup can also waste a bit.

@aitorbouzas
Copy link
Contributor Author

I'm getting the notifications correctly in my local environment... That's strange, can I check runbot's Odoo log?
Let's see if it works now that I moved the buttons to users form.

@aitorbouzas
Copy link
Contributor Author

Ok, I think I know the reason why it fails, could it be due to have more than 1 worker in runbot?

Copy link
Contributor

@simahawk simahawk left a comment

Choose a reason for hiding this comment

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

LG overall, small remarks

'title': title,
'sticky': sticky
}
notifications = [(getattr(record, channel_name_field), bus_message)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use getattr, you can access fields in dict-like notation: (record[channel_name_field], bus_message)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! It could be also a security problem. Bad habit to use getattr...

'notify_warning_channel_name', message, title, sticky)

def _notify_channel(self, channel_name_field, message, title, sticky):
if (self.env.uid != SUPERUSER_ID
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this a recent patch but: wouldn't be better to check for a group or to use self.env.user._is_admin()?
/cc @hbrunn

Copy link
Member

Choose a reason for hiding this comment

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

_is_admin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@simahawk
Copy link
Contributor

@aitorbouzas seems good: pls, squash your commits :)

@aitorbouzas
Copy link
Contributor Author

@simahawk Squashed!

@simahawk
Copy link
Contributor

simahawk commented Oct 15, 2018

@aitorbouzas do you really want to keep "Add buttons to users form"? If yes, you must split it as it contains things not related to it.
NOTE: next time when you use "--fixup" you can pass the commit to fixup like:

git commit --fixup 1234
git log
1234 A
4323 B
2343 fixup! A

then when you rebase w/ auto-squash (ie: git rebase -i --autosquash HEAD~3) you'll get them sorted properly.
In your case I'd expect to have a log like:

xxx web_notify: migrate to v11
yyy web_notify: add buttons to users form
zzz web_notify: improve security check

Do not rely on SUPERUSER_ID:
delegate higher permisions check to `user._is_admin()`.

Improves https://github.com/OCA/web/pull/1071/commits/ae8e4ec59deea6063bd912d6be0f62e4e5a8bc3b

kind of... 😉
NOTE2: you can reword commits in the rebase interactive session

Add self-test buttons in demo environment,
Updated readme to show how to test it.
Add buttons to users form
Do not rely on SUPERUSER_ID and avoid getattr usage
@aitorbouzas
Copy link
Contributor Author

@simahawk resquashed commits and reworded some. How's it now?

@simahawk
Copy link
Contributor

@JayVora-SerpentCS ok for you?

@simahawk
Copy link
Contributor

well, seem so, his comment is attended anyway.
@aitorbouzas thanks for your work!

@simahawk simahawk merged commit acc6e87 into OCA:12.0 Oct 15, 2018
@aitorbouzas
Copy link
Contributor Author

@simahawk Thank you for the reviews!

@JayVora-SerpentCS
Copy link
Contributor

Does it also solve the known issue of it with workers ?

@aitorbouzas
Copy link
Contributor Author

@JayVora-SerpentCS it doesn't, anyway I don't know if workers are the reason of the problem. It was just a supposition. Has this happened to you too?

@JayVora-SerpentCS
Copy link
Contributor

Happened once. I have @serpentcs-dev1 check it once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.