Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
1179 Weergaven

The setup method of the OWL 'mail.Activity' component is re-implemented, in order to get the current user id.
The difficulty here seems to resides in the fact that the mail.Activity OWL component is based on OWL v1, and that OWL v2 infrastructure is not available from OWL v1 components.

1. We can not use session.uid and session.user_id below as both are undefined

import { patch } from '@web/core/utils/patch';
import { Activity } from '@mail/core/web/activity';
import { Component } from '@odoo/owl';
import { session } from '@web/session';

patch(Activity.prototype, {
    setup() {
        super.setup();
        this.currentUserId = session.uid;
// WRONG, will return undefined
this.currentUserId = session.user_id;
// WRONG, will return undefined
},
});

2. We can not use userService('user') as it is not available in this context (an OWL v1 component)

import { patch } from '@web/core/utils/patch';
import { Activity } from '@mail/core/web/activity';
import { Component } from '@odoo/owl';
import { session } from '@web/session';

patch(Activity.prototype, {
    setup() {
        super.setup();
        this.user = useService("user");
// WRONG, will raise error useService user not available
this.currentUserId = this.user.userId;
},
});

3. Solution (this.env.model.config.context.uid)

import { patch } from '@web/core/utils/patch';
import { Activity } from '@mail/core/web/activity';
import { Component } from '@odoo/owl';

patch(Activity.prototype, {
    setup() {
        super.setup();
        this.currentUserId = this.env.model.config.context.uid;
    },
    async isOwner(activity) {
        return activity.user_id[0] === this.currentUserId;
    }
});

The reason seems to be that the mail.Activity OWL component is v1, and OWL v2 infrastructure is not available from OWL v1 components.


Avatar
Annuleer
Beste antwoord

Hi,


Try the following code to get the current user ID.

import { patch } from '@web/core/utils/patch';
import { Activity } from '@mail/core/web/activity';
import { Component } from '@odoo/owl';
import { session } from '@web/session';

patch(Activity.prototype, {
setup() {
super.setup();
this.currentUserId = this.props.activity.user_id[0];
console.log('Current User ID (from session):', this.currentUserId);
},
});


Hope it helps

Avatar
Annuleer
Auteur

Hi,
the issue is about retrieving the user id of the user currently signed-in on the odoo website, and not the user id of the owner of the activity.
Unfortunately, session.uid is not set in this context, and useService('user') and useService('rpc') are not usable too.

Any idea ?

Auteur

issue solved, the uid is available using this.env.model.config.context.uid

Gerelateerde posts Antwoorden Weergaven Activiteit
0
mei 25
690
1
jun. 25
1063
3
mrt. 25
1958
5
mrt. 25
2843
2
feb. 25
4649