- no more "can subscribe X"
- add a new util function on socket `has_permission`
Basic usage:
```js
socket.has_permission(doctype, [name]).then(() => { // do something });
```
You can now specify custom event handlers for SocketIO.
Usage:
1. In your app's hooks.py add `has_realtime_event_handlers=True` so
Framework can assume your app contains custom handler and import them.
2. Create a file called `/app/realtime/handlers.js` with single module
export a function that will setup handlers using socket.
Here's sample code:
```js
// This is /app_root/realtime/handler.js`
function chat_app_handlers(socket) {
socket.on("hello_chat") {
console.log("hello world!");
}
}
module.exports = chat_app_handlers;
```
3. Restart SocketIO server and see if it worked by sending event from
client. In desk based app you can do
`frappe.realtime.socket.emit("hello_chat")`
Middlewares are not yet possible... will be worked upon __some other day__ [tm]
closes https://github.com/frappe/frappe/issues/21528
* fix: reduce retries for rq connection
10 seconds of retries when connection isn't available is too much, just
failing might be beneficial.
- BusyLoadingError only occurs when redis is restarting
- ConnectionError mostly means redis is dead, no amount of retries will
bring it back.
* fix: dont retry if redis is down for realtime
- realtime communication uses pub-sub and no storage. So using same
redis server for both should be just fine.
- This is how FC works since quite a lot of time. We haven't seen any
problem so far.
* Refactor type checks defined in APIs
* Remove dead/deprecated kwargs usages
* Added appropriate hints to APIs and consecutive utils defined in the following modules:
- frappe.realtime
- frappe.translate
- frappe.utils.global_search
- frappe.www.third_party_apps
- frappe.www.search
- frappe.www.printview
other changes
- Name list room as doctype room for more generic use
- avoid re-setting up listeners for generic events
- discard docinfo_subscribe event
- Rename event from `update_docinfo_for_{}_{}` to docinfo_update
- Separate rooms for separate documents generated on requirement
- Check if user has access to doc before sharing docinfo
- Check request data in middleware
- Authenticate each connection before allowing room access
- Allow site room access only to System Users, restrict Website User &
Guests to their respective user rooms
Note: This doesn't check for roles / permissions
# Changes
- Introduces `subqry` class to use in where clause when there is a non-column condition. eg.
> .where(subqry(no_of_roles) == 0)
- Convert SQL queries to frappe.qb
# Testing
Functions with query refactors
- frappe.boot.get_user_pages_or_reports() -> Same output of `get_bootinfo()` as develop
- frappe.boot.get_unseen_notes() -> Forms the same query as develop
```sql
SELECT `name`,`title`,`content`,`notify_on_every_login`
FROM `tabNote` WHERE `notify_on_every_login`=1
AND `expire_notification_on`>'2022-03-30 01:10:53.393874'
AND (SELECT `nsb`.`user` FROM `tabNote Seen By` `nsb` WHERE `nsb`.`parent`=`tabNote`.`name`) NOT IN ('Administrator')
```
- frappe.installer._delete_doctypes() -> installed and uninsalled a dummy app to drop tables
### Not tested
- frappe.make_property_setter()
- frappe.realtime.get_pending_tasks_for_doc() [whitelist method]
- frappe.sessions.Session.start()
- frappe.twofactor.cache_2fa_data()
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.