forked from Smile-SA/odoo_addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Corentin POUHET-BRUNERIE
committed
Nov 7, 2016
1 parent
9e806d5
commit 7f2f84b
Showing
10 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (C) 2011 Smile (<http://www.smile.fr>). All Rights Reserved | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (C) 2011 Smile (<http://www.smile.fr>). All Rights Reserved | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
{ | ||
"name": "Login as another user in website", | ||
"version": "0.1", | ||
"author": "Smile", | ||
"website": 'http://www.smile.fr', | ||
"license": 'AGPL-3', | ||
"category": "Tools", | ||
"description": """ | ||
Allows to login as another user in website | ||
========================================== | ||
Suggestions & Feedback to: [email protected] & [email protected] | ||
""", | ||
"depends": ['website'], | ||
"data": [ | ||
"views/res_users_view.xml", | ||
"views/webclient_templates.xml", | ||
], | ||
"demo": [], | ||
"qweb": [ | ||
"static/src/xml/login_as.xml", | ||
], | ||
"installable": True, | ||
"active": False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (C) 2011 Smile (<http://www.smile.fr>). All Rights Reserved | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
import ir_http | ||
import res_users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (C) 2011 Smile (<http://www.smile.fr>). All Rights Reserved | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
import werkzeug | ||
|
||
from odoo import models | ||
from odoo.http import request | ||
|
||
|
||
class Http(models.AbstractModel): | ||
_inherit = 'ir.http' | ||
|
||
@classmethod | ||
def _website_enabled(cls): | ||
try: | ||
func, arguments = cls._find_handler() | ||
return func.routing.get('website', False) | ||
except werkzeug.exceptions.NotFound: | ||
return True | ||
|
||
@classmethod | ||
def _dispatch(cls): | ||
if cls._website_enabled(): | ||
if not request.uid and request.context.get('uid'): | ||
user = request.env['res.users'].browse(request.context['uid']) | ||
else: | ||
user = request.env.user | ||
if user: | ||
request.uid = user.login_as_user_id.id or user.id | ||
return super(Http, cls)._dispatch() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (C) 2011 Smile (<http://www.smile.fr>). All Rights Reserved | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ResUsers(models.Model): | ||
_inherit = 'res.users' | ||
|
||
login_as_user_id = fields.Many2one('res.users', 'Login as') | ||
|
||
@api.multi | ||
def login_as(self): | ||
self.ensure_one() | ||
return { | ||
'type': 'ir.actions.act_url', | ||
'url': '/', | ||
'target': 'new', | ||
} | ||
|
||
@api.multi | ||
def logout_as(self): | ||
return self.write({'login_as_user_id': False}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
odoo.define('login_as', function (require) { | ||
'use strict'; | ||
|
||
var core = require('web.core'); | ||
var session = require('web.session'); | ||
var Model = require('web.DataModel'); | ||
var SystrayMenu = require('web.SystrayMenu'); | ||
var Widget = require('web.Widget'); | ||
var _t = core._t; | ||
|
||
var LoginAs = Widget.extend({ | ||
template: 'LoginAs', | ||
events: { | ||
'click a#login_as': 'login_as', | ||
}, | ||
login_as: function() { | ||
var self = this; | ||
new Model('ir.ui.view').call('get_view_id', ['smile_website_login_as.view_res_users_login_as_form']).then(function (view_id) { | ||
self.do_action({ | ||
type: 'ir.actions.act_window', | ||
name: _t('Login as'), | ||
views: [[view_id, 'form']], | ||
res_model: 'res.users', | ||
res_id: session.uid, | ||
target: 'new', | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
SystrayMenu.Items.push(LoginAs); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<templates> | ||
|
||
<t t-name="LoginAs"> | ||
<li title="Login as"> | ||
<a href="#" id="login_as"> | ||
<i class="fa fa-globe"/> | ||
</a> | ||
</li> | ||
</t> | ||
|
||
</templates> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="view_res_users_login_as_form" model="ir.ui.view"> | ||
<field name="name">res.users.login_as.form</field> | ||
<field name="model">res.users</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<sheet> | ||
<field name="login_as_user_id" options="{'no_create': True, 'no_open': True}"/> | ||
</sheet> | ||
<footer> | ||
<button name="login_as" type="object" string="Access to website" class="oe_highlight"/> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<data noupdate="0"> | ||
|
||
<template id="login_as" inherit_id="web.assets_backend"> | ||
<xpath expr="." position="inside"> | ||
<script type="text/javascript" src="/smile_website_login_as/static/src/js/login_as.js"></script> | ||
</xpath> | ||
</template> | ||
|
||
</data> | ||
</odoo> |