[MERGE] Merge improvement of google contact lp:~openerp-dev/openobject-addons/trunk-import_google-merge-dbr
bzr revid: sbh@tinyerp.com-20110620044036-usdonlyyp7uygx8n
This commit is contained in:
@@ -37,7 +37,7 @@ class crm_installer(osv.osv_memory):
|
||||
'thunderbird': fields.boolean('Thunderbird', help="Allows you to link your e-mail to OpenERP's documents. You can attach it to any existing one in OpenERP or create a new one."),
|
||||
'outlook': fields.boolean('MS-Outlook', help="Allows you to link your e-mail to OpenERP's documents. You can attach it to any existing one in OpenERP or create a new one."),
|
||||
'wiki_sale_faq': fields.boolean('Sale FAQ', help="Helps you manage wiki pages for Frequently Asked Questions on Sales Application."),
|
||||
'import_google': fields.boolean('Google Contacts', help="Imports contacts from your google account."),
|
||||
'import_google': fields.boolean('Google Import', help="Imports contacts and events from your google account."),
|
||||
}
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
|
||||
@@ -346,11 +346,6 @@ class import_framework(Thread):
|
||||
result = []
|
||||
imported = set() #to invoid importing 2 times the sames modules
|
||||
for table in self.table_list:
|
||||
# try:
|
||||
# to_import = self.get_mapping()[table].get('import', True)
|
||||
# except:
|
||||
# import traceback,sys
|
||||
# info = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
|
||||
to_import = self.get_mapping()[table].get('import', True)
|
||||
if not table in imported:
|
||||
res = self._resolve_dependencies(self.get_mapping()[table].get('dependencies', []), imported)
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import import_google_contact
|
||||
import sync_google_calendar
|
||||
import partner
|
||||
import wizard
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -20,22 +20,24 @@
|
||||
##############################################################################
|
||||
|
||||
{
|
||||
'name': 'Google Contact Import',
|
||||
'name': 'Google Import',
|
||||
'version': '1.0',
|
||||
'category': 'Generic Modules/Others',
|
||||
'description': """The module adds google contact in partner address""",
|
||||
'description': """The module adds google contact in partner address and add google calendar events details in Meeting""",
|
||||
'author': 'OpenERP SA',
|
||||
'website': 'http://www.openerp.com',
|
||||
'depends': ['base', 'google_base_account','crm'],
|
||||
'init_xml': [],
|
||||
'update_xml': [
|
||||
'update_xml': ['security/ir.model.access.csv',
|
||||
'sync_google_calendar_view.xml',
|
||||
'wizard/google_contact_import_view.xml',
|
||||
'wizard/import_google_data_view.xml',
|
||||
'wizard/google_import_message_view.xml'
|
||||
|
||||
],
|
||||
'demo_xml': [],
|
||||
'test': [
|
||||
# 'test/test_sync_google_contact_import_partner.yml',
|
||||
# 'test/test_sync_google_contact_import_address.yml',
|
||||
'test/test_sync_google_contact_import_partner.yml',
|
||||
'test/test_sync_google_contact_import_address.yml',
|
||||
'test/test_sync_google_calendar.yml',
|
||||
],
|
||||
'installable': True,
|
||||
|
||||
@@ -36,4 +36,11 @@ class res_partner_address(osv.osv):
|
||||
|
||||
res_partner_address()
|
||||
|
||||
class crm_case_categ(osv.osv):
|
||||
""" Category of Case """
|
||||
_inherit = "crm.case.categ"
|
||||
_columns = {
|
||||
'user_id': fields.many2one('res.users', 'User')
|
||||
}
|
||||
crm_case_categ()
|
||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,3 +1,5 @@
|
||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_res_users_partner_manager","google.res.partner.manager","base.model_ir_model_data","base.group_partner_manager",1,1,1,0
|
||||
"access_ir_model_data_partner_manager","ir.model.data.partner.manager","base.model_res_users","base.group_partner_manager",1,1,0,0
|
||||
"access_google_import_message_partner_manager","google.import.message.partner.manager","model_google_import_message","base.group_partner_manager",1,1,0,0
|
||||
|
||||
|
||||
|
@@ -4,33 +4,33 @@
|
||||
- |
|
||||
I create a record for the gmail account for which I want to import the contacts.
|
||||
-
|
||||
!record {model: google.login, id: google_login_contact_id0}:
|
||||
!record {model: google.login, id: google_login_id0}:
|
||||
user: testmail.openerp@gmail.com
|
||||
password: openerptiny
|
||||
- |
|
||||
I login into that account.
|
||||
-
|
||||
!python {model: google.login}: |
|
||||
self.login(cr, uid, [ref('google_login_contact_id0')], context)
|
||||
self.login(cr, uid, [ref('google_login_id0')], context)
|
||||
- |
|
||||
Now I want to import all the events from all the calendars in the user account.
|
||||
- |
|
||||
I select all calendars.
|
||||
-
|
||||
!record {model: synchronize.google.calendar, id: synchronize_google_calendar_id0}:
|
||||
!record {model: synchronize.google.import, id: synchronize_google_import_id0}:
|
||||
calendar_name: all
|
||||
- |
|
||||
I import the events from the google calendar.
|
||||
-
|
||||
!python {model: synchronize.google.calendar}: |
|
||||
self.import_calendar_events(cr, uid, [ref('synchronize_google_calendar_id0')], context)
|
||||
!python {model: synchronize.google.import}: |
|
||||
self.import_google(cr, uid, [ref('synchronize_google_import_id0')], context={'calendar':True})
|
||||
- |
|
||||
Now I check my meetings are created or not.
|
||||
-
|
||||
!python {model: crm.meeting}: |
|
||||
model_obj = self.pool.get('ir.model.data')
|
||||
meeting_ids = self.search(cr, uid, [])
|
||||
model_ids = model_obj.search(cr, uid, [('res_id','in',meeting_ids),('model','=','crm.meeting'),('module','=','sync_google_calendar')])
|
||||
model_ids = model_obj.search(cr, uid, [('res_id','in',meeting_ids),('model','=','crm.meeting'),('module','=','synchronize_google')])
|
||||
assert model_ids, 'Meetings not created !'
|
||||
|
||||
|
||||
|
||||
@@ -4,31 +4,31 @@
|
||||
- |
|
||||
I create a record for the gmail account for which I want to import the contacts.
|
||||
-
|
||||
!record {model: google.login, id: google_login_contact_id0}:
|
||||
user: testmail.openerp
|
||||
!record {model: google.login, id: google_login_id0}:
|
||||
user: testmail.openerp@gmail.com
|
||||
password: openerptiny
|
||||
- |
|
||||
I login into that account.
|
||||
-
|
||||
!python {model: google.login}: |
|
||||
self.login(cr, uid, [ref('google_login_contact_id0')], context)
|
||||
self.login(cr, uid, [ref('google_login_id0')], context)
|
||||
- |
|
||||
Now I select from which group I want to get the contact details.
|
||||
-
|
||||
!record {model: synchronize.google.contact.import, id: synchronize_google_contact_import_id0}:
|
||||
!record {model: synchronize.google.import, id: synchronize_google_import_id0}:
|
||||
create_partner: create_address
|
||||
group_name: all
|
||||
calendar_name: all
|
||||
- |
|
||||
I import the contacts and I also check if the contact already exists in db and updates the address.
|
||||
-
|
||||
!python {model: synchronize.google.contact.import}: |
|
||||
self.import_contact(cr, uid, [ref('synchronize_google_contact_import_id0')], context)
|
||||
!python {model: synchronize.google.import}: |
|
||||
self.import_google(cr, uid, [ref('synchronize_google_import_id0')], context={'contact':True})
|
||||
- |
|
||||
I check whether the Contacts are created in Partner address or not.
|
||||
-
|
||||
!python {model: ir.model.data}: |
|
||||
addr_obj = self.pool.get('res.partner.address')
|
||||
addr_ids = addr_obj.search(cr, uid, [])
|
||||
data_ids = self.search(cr, uid, [('res_id','in',addr_ids),('model','=','res.partner.address'),('module','=','sync_google_contact')])
|
||||
!python {model: res.partner.address}: |
|
||||
addr_obj = self.pool.get('ir.model.data')
|
||||
data_ids = addr_obj.search(cr, uid, [('model','=','res.partner.address'),('module','=','synchronize_google')])
|
||||
assert data_ids, 'Addresses not created !'
|
||||
|
||||
@@ -4,33 +4,33 @@
|
||||
- |
|
||||
I create a record for the gmail account for which I want to import the contacts.
|
||||
-
|
||||
!record {model: google.login, id: google_login_contact_id1}:
|
||||
user: testmail.openerp
|
||||
!record {model: google.login, id: google_login_id1}:
|
||||
user: testmail.openerp@gmail.com
|
||||
password: openerptiny
|
||||
- |
|
||||
I login into that account.
|
||||
-
|
||||
!python {model: google.login}: |
|
||||
self.login(cr, uid, [ref('google_login_contact_id1')], context)
|
||||
self.login(cr, uid, [ref('google_login_id1')], context)
|
||||
- |
|
||||
Now I select from which group I want to get the contact details and I want to create partner for all contacts.
|
||||
-
|
||||
!record {model: synchronize.google.contact.import, id: synchronize_google_contact_import_id1}:
|
||||
!record {model: synchronize.google.import, id: synchronize_google_import_id1}:
|
||||
create_partner: create_all
|
||||
group_name: all
|
||||
- |
|
||||
I import the contacts.
|
||||
-
|
||||
!python {model: synchronize.google.contact.import}: |
|
||||
self.import_contact(cr, uid, [ref('synchronize_google_contact_import_id1')], context)
|
||||
!python {model: synchronize.google.import}: |
|
||||
self.import_google(cr, uid, [ref('synchronize_google_import_id1')], context={'contact':True})
|
||||
- |
|
||||
I check whether the Partners are created or not.
|
||||
-
|
||||
!python {model: ir.model.data}: |
|
||||
addr_obj = self.pool.get('res.partner.address')
|
||||
!python {model: res.partner.address }: |
|
||||
addr_obj = self.pool.get('ir.model.data')
|
||||
addr_ids = addr_obj.search(cr, uid, [])
|
||||
data_ids = self.search(cr, uid, [('res_id','in',addr_ids),('model','=','res.partner.address'),('module','=','sync_google_contact')])
|
||||
address_ids = map(lambda x: x.res_id, [child for child in self.browse(cr, uid, data_ids) if child.res_id])
|
||||
partner_ids = map(lambda x: x.partner_id.id, [addr for addr in addr_obj.browse(cr, uid, address_ids) if addr.partner_id])
|
||||
data_ids = addr_obj.search(cr, uid, [('model','=','res.partner.address'),('module','=','synchronize_google')])
|
||||
address_ids = map(lambda x: x.res_id, [child for child in addr_obj.browse(cr, uid, data_ids) if child.res_id])
|
||||
partner_ids = map(lambda x: x.partner_id.id, [addr for addr in self.browse(cr, uid, address_ids) if addr.partner_id])
|
||||
assert partner_ids, 'Partners not created !'
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
#
|
||||
##############################################################################
|
||||
import import_google
|
||||
import google_contact_import
|
||||
import import_google_data
|
||||
import google_import_message
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,363 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import datetime
|
||||
|
||||
try:
|
||||
import gdata
|
||||
import gdata.contacts.service
|
||||
import gdata.contacts
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
from osv import fields
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
from import_google import import_contact
|
||||
|
||||
class google_login_contact(osv.osv_memory):
|
||||
_inherit = 'google.login'
|
||||
_name = 'google.login.contact'
|
||||
|
||||
def _get_next_action(self, cr, uid, context):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_contact_import_form')
|
||||
|
||||
view_id = False
|
||||
if data_id:
|
||||
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
|
||||
value = {
|
||||
'name': _('Import Contact'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'res_model': 'synchronize.google.contact.import',
|
||||
'view_id': False,
|
||||
'context': context,
|
||||
'views': [(view_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
return value
|
||||
google_login_contact()
|
||||
|
||||
class synchronize_google_contact(osv.osv_memory):
|
||||
_name = 'synchronize.google.contact.import'
|
||||
|
||||
def _get_group(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google=self.pool.get('google.login')
|
||||
if not user_obj.gmail_user or not user_obj.gmail_password:
|
||||
raise osv.except_osv(_('Warning !'), _("No Google Username or password Defined for user.\nPlease define in user view"))
|
||||
gd_client = google.google_login(user_obj.gmail_user,user_obj.gmail_password,type='group')
|
||||
if not gd_client:
|
||||
raise osv.except_osv(_('Error'), _("Authentication fail check the user and password !"))
|
||||
|
||||
res = []
|
||||
query = gdata.contacts.service.GroupsQuery(feed='/m8/feeds/groups/default/full')
|
||||
if gd_client:
|
||||
groups = gd_client.GetFeed(query.ToUri())
|
||||
for grp in groups.entry:
|
||||
res.append((grp.id.text, grp.title.text))
|
||||
res.append(('all','All Groups'))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'create_partner': fields.selection([('create_all','Create partner for each contact'),('create_address','Import only address')],'Options'),
|
||||
'customer': fields.boolean('Customer', help="Check this box to set newly created partner as Customer."),
|
||||
'supplier': fields.boolean('Supplier', help="Check this box to set newly created partner as Supplier."),
|
||||
'group_name': fields.selection(_get_group, "Group Name", size=32,help="Choose which group to import, By default it takes all."),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'create_partner': 'create_all',
|
||||
'group_name': 'all',
|
||||
}
|
||||
#
|
||||
# def create_partner(self, cr, uid, data={}, context=None):
|
||||
# if context == None:
|
||||
# context = {}
|
||||
# if not data:
|
||||
# return False
|
||||
# name = data.get("company") or data.get('name','')
|
||||
# partner_pool = self.pool.get('res.partner')
|
||||
# partner_id = partner_pool.create(cr, uid, {
|
||||
# 'name': name,
|
||||
# 'user_id': uid,
|
||||
# 'address' : [(6, 0, [data['address_id']])],
|
||||
# 'customer': data.get('customer', False),
|
||||
# 'supplier': data.get('supplier', False)
|
||||
# }, context=context)
|
||||
# return partner_id
|
||||
#
|
||||
# def set_partner(self, cr, uid, name, address_id, context=None):
|
||||
# partner_pool = self.pool.get('res.partner')
|
||||
# partner_ids = partner_pool.search(cr, uid, [('name', '=', name)], context=context)
|
||||
# if partner_ids:
|
||||
# address_pool = self.pool.get('res.partner.address')#TODO create partner of find the one with the same name
|
||||
# data = {'partner_id' : partner_ids[0]}
|
||||
# address_pool.write(cr, uid, [address_id], data, context=context)
|
||||
# return partner_ids[0]
|
||||
# return False
|
||||
|
||||
def import_contact_all(self, cr, uid, ids, context=None):
|
||||
tables = ['contact']
|
||||
obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google = self.pool.get('google.login')
|
||||
|
||||
gmail_user = user_obj.gmail_user
|
||||
gmail_pwd = user_obj.gmail_password
|
||||
context = {}
|
||||
gd_client = google.google_login(gmail_user, gmail_pwd, type='contact')
|
||||
context.update({'user': gmail_user,'password': gmail_pwd,'gd_client':gd_client})
|
||||
|
||||
imp = import_contact(self, cr, uid,'google', "synchronize_google_contact", context=context)
|
||||
imp.set_table_list(tables)
|
||||
imp.start()
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
#
|
||||
# if not gd_client:
|
||||
# raise osv.except_osv(_('Error'), _("Please specify correct user and password !"))
|
||||
#
|
||||
# if obj.group_name not in ['all']:
|
||||
# query = gdata.contacts.service.ContactsQuery()
|
||||
# query.group = obj.group_name
|
||||
# contact = gd_client.GetContactsFeed(query.ToUri())
|
||||
# else:
|
||||
# contact = gd_client.GetContactsFeed()
|
||||
#
|
||||
# ids = self.create_contact(cr, uid, ids, gd_client, contact, option=obj.create_partner,context=context)
|
||||
# if not ids:
|
||||
# return {'type': 'ir.actions.act_window_close'}
|
||||
#
|
||||
# return {
|
||||
# 'name': _(obj.create_partner =='create_all' and 'Partners') or _('Contacts'),
|
||||
# 'domain': "[('id','in', ["+','.join(map(str,ids))+"])]",
|
||||
# 'view_type': 'form',
|
||||
# 'view_mode': 'tree,form',
|
||||
# 'res_model': obj.create_partner =='create_all' and 'res.partner' or 'res.partner.address',
|
||||
# 'context': context,
|
||||
# 'views': [(False, 'tree'),(False, 'form')],
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# }
|
||||
|
||||
|
||||
# def create_contact(self, cr, uid, ids, gd_client, contact, option,context=None):
|
||||
# model_obj = self.pool.get('ir.model.data')
|
||||
# addresss_obj = self.pool.get('res.partner.address')
|
||||
# company_pool = self.pool.get('res.company')
|
||||
# addresses = []
|
||||
# partner_ids = []
|
||||
# contact_ids = []
|
||||
# if 'tz' in context and context['tz']:
|
||||
# time_zone = context['tz']
|
||||
# else:
|
||||
# time_zone = tools.get_server_timezone()
|
||||
# au_tz = timezone(time_zone)
|
||||
# while contact:
|
||||
# for entry in contact.entry:
|
||||
# data = self._retreive_data(entry)
|
||||
# google_id = data.pop('id')
|
||||
# model_data = {
|
||||
# 'name': google_id,
|
||||
# 'model': 'res.partner.address',
|
||||
# 'module': 'sync_google_contact',
|
||||
# 'noupdate': True
|
||||
# }
|
||||
#
|
||||
# data_ids = model_obj.search(cr, uid, [('model','=','res.partner.address'), ('name','=', google_id)])
|
||||
# if data_ids:
|
||||
# contact_ids = [model_obj.browse(cr, uid, data_ids[0], context=context).res_id]
|
||||
# elif data['email']:
|
||||
# contact_ids = addresss_obj.search(cr, uid, [('email', 'ilike', data['email'])])
|
||||
#
|
||||
# if contact_ids:
|
||||
# addresses.append(contact_ids[0])
|
||||
# address = addresss_obj.browse(cr, uid, contact_ids[0], context=context)
|
||||
# google_updated = entry.updated.text
|
||||
# utime = dateutil.parser.parse(google_updated)
|
||||
# au_dt = au_tz.normalize(utime.astimezone(au_tz))
|
||||
# updated_dt = datetime.datetime(*au_dt.timetuple()[:6]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
# if address.write_date < updated_dt:
|
||||
# self.update_contact(cr, uid, contact_ids, data, context=context)
|
||||
# res_id = contact_ids[0]
|
||||
# if not contact_ids:
|
||||
# #create or link to an existing partner only if it's a new contact
|
||||
# data.update({'type': 'default'})
|
||||
# res_id = addresss_obj.create(cr, uid, data, context=context)
|
||||
# data['address_id'] = res_id
|
||||
# if option == 'create_all':
|
||||
# obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
# data['customer'] = obj.customer
|
||||
# data['supplier'] = obj.supplier
|
||||
# res = False
|
||||
# if 'company' in data:
|
||||
# res = self.set_partner(cr, uid, data.get('company'), res_id, context=context)
|
||||
# if res:
|
||||
# partner_ids.append(res)
|
||||
# if not res:
|
||||
# partner_id = self.create_partner(cr, uid, data, context=context)
|
||||
# partner_ids.append(partner_id)
|
||||
# addresses.append(res_id)
|
||||
#
|
||||
# if not data_ids: #link to google_id if it was not the case before
|
||||
# model_data.update({'res_id': res_id})
|
||||
# model_obj.create(cr, uid, model_data, context=context)
|
||||
#
|
||||
# next = contact.GetNextLink()
|
||||
# contact = next and gd_client.GetContactsFeed(next.href) or None
|
||||
#
|
||||
# if option == 'create_all':
|
||||
# return partner_ids
|
||||
# else:
|
||||
# return addresses
|
||||
|
||||
# def _retreive_data(self, entry):
|
||||
# data = {}
|
||||
# data['id'] = entry.id.text
|
||||
# name = tools.ustr(entry.title.text)
|
||||
# if name == "None":
|
||||
# name = entry.email[0].address
|
||||
# data['name'] = name
|
||||
# emails = ','.join(email.address for email in entry.email)
|
||||
# data['email'] = emails
|
||||
# if entry.organization:
|
||||
# if entry.organization.org_name:
|
||||
# data.update({'company': entry.organization.org_name.text})
|
||||
# if entry.organization.org_title:
|
||||
# data.update ({'function': entry.organization.org_title.text})
|
||||
#
|
||||
#
|
||||
# if entry.phone_number:
|
||||
# for phone in entry.phone_number:
|
||||
# if phone.rel == gdata.contacts.REL_WORK:
|
||||
# data['phone'] = phone.text
|
||||
# if phone.rel == gdata.contacts.PHONE_MOBILE:
|
||||
# data['mobile'] = phone.text
|
||||
# if phone.rel == gdata.contacts.PHONE_WORK_FAX:
|
||||
# data['fax'] = phone.text
|
||||
# return data
|
||||
|
||||
# def update_contact(self, cr, uid, contact_ids, data, context=None):
|
||||
# addresss_obj = self.pool.get('res.partner.address')
|
||||
# vals = {}
|
||||
# addr = addresss_obj.browse(cr,uid,contact_ids)[0]
|
||||
# name = str((addr.name or addr.partner_id and addr.partner_id.name or '').encode('utf-8'))
|
||||
#
|
||||
# if name != data.get('name'):
|
||||
# vals['name'] = data.get('name','')
|
||||
# if addr.email != data.get('email'):
|
||||
# vals['email'] = data.get('email','')
|
||||
# if addr.mobile != data.get('mobile'):
|
||||
# vals['mobile'] = data.get('mobile','')
|
||||
# if addr.phone != data.get('phone'):
|
||||
# vals['phone'] = data.get('phone','')
|
||||
# if addr.fax != data.get('fax'):
|
||||
# vals['fax'] = data.get('fax','')
|
||||
#
|
||||
# addresss_obj.write(cr, uid, contact_ids, vals, context=context)
|
||||
# return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
synchronize_google_contact()
|
||||
|
||||
|
||||
class google_login_calendar(osv.osv_memory):
|
||||
"""Gdata Login Object for Google Calendar Import"""
|
||||
_inherit = 'google.login'
|
||||
_name = 'google.login'
|
||||
|
||||
def _get_next_action(self, cr, uid, context):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_calendar_import_form')
|
||||
|
||||
view_id = False
|
||||
if data_id:
|
||||
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
|
||||
value = {
|
||||
'name': _('Import Events'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'res_model': 'synchronize.google.calendar',
|
||||
'view_id': False,
|
||||
'context': context,
|
||||
'views': [(view_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
return value
|
||||
google_login_calendar()
|
||||
|
||||
|
||||
class synchronize_google_calendar_events(osv.osv_memory):
|
||||
"""
|
||||
Wizard to initiate import specific calendar or all calendars
|
||||
"""
|
||||
_name = 'synchronize.google.calendar'
|
||||
|
||||
def _get_calendars(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google = self.pool.get('google.login')
|
||||
res = []
|
||||
try:
|
||||
gd_client = google.google_login(user_obj.gmail_user, user_obj.gmail_password, type='calendar')
|
||||
calendars = gd_client.GetAllCalendarsFeed()
|
||||
for cal in calendars.entry:
|
||||
res.append((cal.id.text, cal.title.text))
|
||||
except Exception, e:
|
||||
raise osv.except_osv('Error !', e.args[0].get('body'))
|
||||
res.append(('all', 'All Calendars'))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'calendar_name': fields.selection(_get_calendars, "Calendar Name", size=32),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'calendar_name': 'all',
|
||||
}
|
||||
|
||||
def import_calendar_events(self, cr, uid, ids, context=None):
|
||||
if context == None:
|
||||
context = {}
|
||||
if not ids:
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
table = ['Events']
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
gmail_user = user_obj.gmail_user
|
||||
gmail_pwd = user_obj.gmail_password
|
||||
if not gmail_user or not gmail_pwd:
|
||||
raise osv.except_osv(_('Error'), _("Invalid login detail !\n Specify Username/Password."))
|
||||
current_rec = self.browse(cr, uid, ids, context=context)
|
||||
calendars = False
|
||||
for rec in current_rec:
|
||||
if rec.calendar_name != 'all':
|
||||
calendars = [rec.calendar_name]
|
||||
else:
|
||||
calendars = map(lambda x: x[0], [cal for cal in self._get_calendars(cr, uid, context) if cal[0] != 'all'])
|
||||
context.update({'user': gmail_user,
|
||||
'password': gmail_pwd,
|
||||
'calendars': calendars,
|
||||
'instance': 'calendar'})
|
||||
imp = import_contact(self, cr, uid, 'import_google', "import_google_calendar", [gmail_user], context)
|
||||
imp.set_table_list(table)
|
||||
imp.start()
|
||||
return {}
|
||||
|
||||
synchronize_google_calendar_events()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
+17
-12
@@ -19,19 +19,24 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
from osv import osv
|
||||
from osv import fields
|
||||
|
||||
class crm_meeting(osv.osv):
|
||||
_inherit = "crm.meeting"
|
||||
|
||||
crm_meeting()
|
||||
|
||||
class crm_case_categ(osv.osv):
|
||||
""" Category of Case """
|
||||
_inherit = "crm.case.categ"
|
||||
class google_import_message(osv.osv):
|
||||
"""Import Message"""
|
||||
|
||||
_name = "google.import.message"
|
||||
_description = "Import Message"
|
||||
_columns = {
|
||||
'user_id': fields.many2one('res.users', 'User')
|
||||
}
|
||||
crm_case_categ()
|
||||
'name': fields.text('Message', readonly=True),
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
if context == None:
|
||||
context = {}
|
||||
res = super(google_import_message, self).default_get(cr, uid, fields, context=context)
|
||||
res.update({'name': context.get('message')})
|
||||
return res
|
||||
|
||||
google_import_message()
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- Import Message Form View -->
|
||||
<record model="ir.ui.view" id="view_google_import_message_form">
|
||||
<field name="name">google.import.message.form</field>
|
||||
<field name="model">google.import.message</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Google Data">
|
||||
<group colspan="4" col="4" width="300">
|
||||
<field name='name' nolabel='1'/>
|
||||
</group>
|
||||
<separator string="" colspan="4"/>
|
||||
<group colspan="4">
|
||||
<group colspan="2"/>
|
||||
<group colspan="2">
|
||||
<button icon="gtk-ok" special="cancel" string="_Ok"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -37,31 +37,47 @@ except ImportError:
|
||||
from import_base.import_framework import *
|
||||
from import_base.mapper import *
|
||||
|
||||
class import_contact(import_framework):
|
||||
class google_import(import_framework):
|
||||
|
||||
gd_client = False
|
||||
calendars = False
|
||||
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
TABLE_CONTACT = 'contact'
|
||||
TABLE_CONTACT = 'Contact'
|
||||
TABLE_ADDRESS ='Address'
|
||||
TABLE_EVENT = 'Events'
|
||||
|
||||
def initialize(self):
|
||||
google = self.obj.pool.get('google.login')
|
||||
self.external_id_field = 'Id'
|
||||
self.gd_client = google.google_login(self.context.get('user'),
|
||||
self.context.get('password'),
|
||||
type = self.context.get('instance'))
|
||||
self.context.get('instance'))
|
||||
|
||||
if self.context.get('instance') and self.context.get('instance') == 'contact':
|
||||
self.contact = self.context.get('contact')
|
||||
if self.context.get('instance') and self.context.get('instance') == 'calendar':
|
||||
self.calendars = self.context.get('calendars')
|
||||
|
||||
def get_mapping(self):
|
||||
return {
|
||||
self.TABLE_EVENT: self.get_event_mapping(),
|
||||
self.TABLE_CONTACT: self.get_contact_mapping(),
|
||||
self.TABLE_ADDRESS: self.get_address_mapping(),
|
||||
}
|
||||
|
||||
def get_data(self, table):
|
||||
val = {
|
||||
self.TABLE_EVENT: self.get_events(),
|
||||
}
|
||||
if table == "Contact":
|
||||
val = {
|
||||
self.TABLE_CONTACT: self.get_contact(),
|
||||
}
|
||||
if table == "Address":
|
||||
val = {
|
||||
self.TABLE_ADDRESS: self.get_contact(),
|
||||
}
|
||||
elif table == "Events":
|
||||
val = {
|
||||
self.TABLE_EVENT: self.get_events(),
|
||||
}
|
||||
return val.get(table)
|
||||
|
||||
|
||||
@@ -257,3 +273,98 @@ class import_contact(import_framework):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def get_contact(self):
|
||||
table = self.context.get('table')[0]
|
||||
datas = []
|
||||
if self.context.get('group_name'):
|
||||
query = gdata.contacts.service.ContactsQuery()
|
||||
query.group = self.context.get('group_name')
|
||||
self.contact = self.gd_client.GetContactsFeed(query.ToUri())
|
||||
else:
|
||||
self.contact = self.gd_client.GetContactsFeed()
|
||||
while self.contact:
|
||||
for entry in self.contact.entry:
|
||||
data = {}
|
||||
data['id'] = entry.id.text
|
||||
name = tools.ustr(entry.title.text)
|
||||
if name == "None":
|
||||
name = entry.email[0].address
|
||||
data['name'] = name
|
||||
emails = ','.join(email.address for email in entry.email)
|
||||
data['email'] = emails
|
||||
if table == 'Contact':
|
||||
data.update({'customer': str(self.context.get('customer')),
|
||||
'supplier': str(self.context.get('supplier'))})
|
||||
if entry.organization:
|
||||
if entry.organization.org_name:
|
||||
data.update({'company': entry.organization.org_name.text})
|
||||
if entry.organization.org_title:
|
||||
data.update ({'function': entry.organization.org_title.text})
|
||||
if entry.phone_number:
|
||||
for phone in entry.phone_number:
|
||||
if phone.rel == gdata.contacts.REL_WORK:
|
||||
data['phone'] = phone.text
|
||||
if phone.rel == gdata.contacts.PHONE_MOBILE:
|
||||
data['mobile'] = phone.text
|
||||
if phone.rel == gdata.contacts.PHONE_WORK_FAX:
|
||||
data['fax'] = phone.text
|
||||
datas.append(data)
|
||||
next = self.contact.GetNextLink()
|
||||
self.contact = next and self.gd_client.GetContactsFeed(next.href) or None
|
||||
return datas
|
||||
|
||||
def get_partner_address(self,val):
|
||||
partner_id = False
|
||||
address_pool = self.obj.pool.get('res.partner.address')
|
||||
company_pool = self.obj.pool.get('res.company')
|
||||
if 'company' in val:
|
||||
cids = company_pool.search(self.cr, self.uid, [('name', '=', val.get('company'))])
|
||||
if cids:
|
||||
records = company_pool.browse(self.cr, self.uid, cids)
|
||||
for rec in records:
|
||||
if rec.partner_id:
|
||||
partner_id = rec.partner_id
|
||||
field_map = {
|
||||
'name': 'name',
|
||||
'type': 'Type',
|
||||
'city': 'city',
|
||||
'phone': 'phone',
|
||||
'mobile': 'mobile',
|
||||
'email': 'email',
|
||||
'fax': 'fax',
|
||||
}
|
||||
val.update({'Type':'contact'})
|
||||
val.update({'id_new': val['id']+'address_contact' })
|
||||
return self.import_object_mapping(field_map , val, 'res.partner.address', self.context.get('table')[0], val['id_new'], self.DO_NOT_FIND_DOMAIN)
|
||||
|
||||
def get_contact_mapping(self):
|
||||
return {
|
||||
'model': 'res.partner',
|
||||
'dependencies': [],
|
||||
'map': {
|
||||
'id':'id',
|
||||
'name': 'name',
|
||||
'customer': 'customer',
|
||||
'supplier': 'supplier',
|
||||
'address/id': self.get_partner_address,
|
||||
}
|
||||
}
|
||||
|
||||
def get_address_mapping(self):
|
||||
return {
|
||||
'model': 'res.partner.address',
|
||||
'dependencies': [],
|
||||
'map': {
|
||||
'id':'id',
|
||||
'name': 'name',
|
||||
'city': 'city',
|
||||
'phone': 'phone',
|
||||
'mobile': 'mobile',
|
||||
'email': 'email',
|
||||
'fax': 'fax',
|
||||
'function': 'function'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import datetime
|
||||
|
||||
try:
|
||||
import gdata
|
||||
import gdata.contacts.service
|
||||
import gdata.contacts
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Contacts Import Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
from osv import fields
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
from import_google import google_import
|
||||
|
||||
|
||||
class google_login_contact(osv.osv_memory):
|
||||
|
||||
_inherit = 'google.login'
|
||||
|
||||
def _get_next_action(self, cr, uid, context=None):
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_contact_import_form')
|
||||
view_id = False
|
||||
if context.get('contact'):
|
||||
data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_contact_import_form')
|
||||
if context.get('calendar'):
|
||||
data_id = data_obj._get_id(cr, uid, 'import_google', 'view_synchronize_google_calendar_import_form')
|
||||
if data_id:
|
||||
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
|
||||
value = {
|
||||
'name': _('Import google'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form,tree',
|
||||
'res_model': 'synchronize.google.import',
|
||||
'view_id': False,
|
||||
'context': context,
|
||||
'views': [(view_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
return value
|
||||
|
||||
google_login_contact()
|
||||
|
||||
class synchronize_google(osv.osv_memory):
|
||||
_name = 'synchronize.google.import'
|
||||
|
||||
def _get_group(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google=self.pool.get('google.login')
|
||||
if not user_obj.gmail_user or not user_obj.gmail_password:
|
||||
raise osv.except_osv(_('Warning !'), _("No Google Username or password Defined for user.\nPlease define in user view"))
|
||||
gd_client = google.google_login(user_obj.gmail_user,user_obj.gmail_password,type='group')
|
||||
if not gd_client:
|
||||
raise osv.except_osv(_('Error'), _("Authentication fail check the user and password !"))
|
||||
|
||||
res = []
|
||||
query = gdata.contacts.service.GroupsQuery(feed='/m8/feeds/groups/default/full')
|
||||
if gd_client:
|
||||
groups = gd_client.GetFeed(query.ToUri())
|
||||
for grp in groups.entry:
|
||||
res.append((grp.id.text, grp.title.text))
|
||||
res.append(('all','All Groups'))
|
||||
return res
|
||||
|
||||
def _get_calendars(self, cr, uid, context=None):
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
google = self.pool.get('google.login')
|
||||
res = []
|
||||
try:
|
||||
gd_client = google.google_login(user_obj.gmail_user, user_obj.gmail_password, type='calendar')
|
||||
calendars = gd_client.GetAllCalendarsFeed()
|
||||
for cal in calendars.entry:
|
||||
res.append((cal.id.text, cal.title.text))
|
||||
except Exception, e:
|
||||
raise osv.except_osv('Error !', e.args[0].get('body'))
|
||||
res.append(('all', 'All Calendars'))
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'create_partner': fields.selection([('create_all','Create partner for each contact'),('create_address','Import only address')],'Options'),
|
||||
'customer': fields.boolean('Customer', help="Check this box to set newly created partner as Customer."),
|
||||
'supplier': fields.boolean('Supplier', help="Check this box to set newly created partner as Supplier."),
|
||||
'group_name': fields.selection(_get_group, "Group Name", size=32,help="Choose which group to import, By default it takes all."),
|
||||
'calendar_name': fields.selection(_get_calendars, "Calendar Name", size=32),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'create_partner': 'create_all',
|
||||
'group_name': 'all',
|
||||
'calendar_name': 'all',
|
||||
}
|
||||
|
||||
def import_google(self, cr, uid, ids, context=None):
|
||||
if context == None:
|
||||
context = {}
|
||||
if not ids:
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
obj = self.browse(cr, uid, ids, context=context)[0]
|
||||
cust = obj.customer
|
||||
sup = obj.supplier
|
||||
tables=[]
|
||||
user_obj = self.pool.get('res.users').browse(cr, uid, uid)
|
||||
|
||||
gmail_user = user_obj.gmail_user
|
||||
gmail_pwd = user_obj.gmail_password
|
||||
google = self.pool.get('google.login')
|
||||
if not gmail_user or not gmail_pwd:
|
||||
raise osv.except_osv(_('Error'), _("Invalid login detail !\n Specify Username/Password."))
|
||||
|
||||
if context.get('contact'):
|
||||
msg = " You're Contact are import in background, a email will be send when the process is finished to %s"%(user_obj.gmail_user)
|
||||
gd_client = google.google_login(gmail_user, gmail_pwd, type='contact')
|
||||
if not gd_client:
|
||||
raise osv.except_osv(_('Error'), _("Please specify correct user and password !"))
|
||||
if obj.group_name not in ['all']:
|
||||
context.update({ 'group_name': obj.group_name})
|
||||
if obj.create_partner=='create_all':
|
||||
tables.append('Contact')
|
||||
else:
|
||||
tables.append('Address')
|
||||
context.update({'user': gmail_user,
|
||||
'password': gmail_pwd,
|
||||
'instance': 'contact',
|
||||
'table':tables,
|
||||
'customer':cust,
|
||||
'supplier':sup})
|
||||
|
||||
elif context.get('calendar'):
|
||||
msg = " You're Meeting are import in background, a email will be send when the process is finished to %s"%(user_obj.gmail_user)
|
||||
|
||||
tables.append('Events')
|
||||
current_rec = self.browse(cr, uid, ids, context=context)
|
||||
calendars = False
|
||||
for rec in current_rec:
|
||||
if rec.calendar_name != 'all':
|
||||
calendars = [rec.calendar_name]
|
||||
else:
|
||||
calendars = map(lambda x: x[0], [cal for cal in self._get_calendars(cr, uid, context) if cal[0] != 'all'])
|
||||
context.update({'user': gmail_user,
|
||||
'password': gmail_pwd,
|
||||
'calendars': calendars,
|
||||
'instance': 'calendar'})
|
||||
|
||||
imp = google_import(self, cr, uid,'import_google' , "synchronize_google", gmail_user, context)
|
||||
imp.set_table_list(tables)
|
||||
imp.start()
|
||||
context.update({'message': msg})
|
||||
obj_model = self.pool.get('ir.model.data')
|
||||
model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','view_google_import_message_form')])
|
||||
resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
|
||||
return {
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'google.import.message',
|
||||
'views': [(resource_id,'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
'context': context,
|
||||
}
|
||||
|
||||
synchronize_google()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
+7
-5
@@ -3,7 +3,7 @@
|
||||
<data>
|
||||
<record model="ir.ui.view" id="view_synchronize_google_contact_import_form">
|
||||
<field name="name">synchronize.base.form</field>
|
||||
<field name="model">synchronize.google.contact.import</field>
|
||||
<field name="model">synchronize.google.import</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import contacts from a google account">
|
||||
@@ -23,7 +23,7 @@
|
||||
<group colspan="2" col="2"/>
|
||||
<group colspan="2" col="2">
|
||||
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
|
||||
<button name="import_contact" string="_Import Contacts" type="object" icon="terp-personal+"/>
|
||||
<button name="import_google" string="_Import Contacts" type="object" icon="terp-personal+"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
<record model="ir.ui.view" id="view_synchronize_google_calendar_import_form">
|
||||
<field name="name">synchronize.google.calendar.form</field>
|
||||
<field name="model">synchronize.google.calendar</field>
|
||||
<field name="model">synchronize.google.import</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Import Google Calendar Events">
|
||||
@@ -46,7 +46,7 @@
|
||||
<group colspan="2" col="2"/>
|
||||
<group colspan="2" col="2">
|
||||
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
|
||||
<button name="import_calendar_events" string="_Import Events" type="object" icon="terp-calendar"/>
|
||||
<button name="import_google" string="_Import Events" type="object" icon="terp-calendar"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
@@ -62,16 +62,18 @@
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'calendar':True}</field>
|
||||
<field name="view_id" ref="google_base_account.view_google_login_form" />
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="act_google_login_contact_form">
|
||||
<field name="name">Import Google Contacts</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">google.login.contact</field>
|
||||
<field name="res_model">google.login</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'contact':True}</field>
|
||||
<field name="view_id" ref="google_base_account.view_google_login_form" />
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user