d4910d1b2a06b7b101bb5c6b689ba8c3769749bf
[pyi2ncommon] / src / cnfline / build_user.py
1 # The software in this package is distributed under the GNU General
2 # Public License version 2 (with a special exception described below).
3 #
4 # A copy of GNU General Public License (GPL) is included in this distribution,
5 # in the file COPYING.GPL.
6 #
7 # As a special exception, if other files instantiate templates or use macros
8 # or inline functions from this file, or you compile this file and link it
9 # with other works to produce a work based on this file, this file
10 # does not by itself cause the resulting work to be covered
11 # by the GNU General Public License.
12 #
13 # However the source code for this file must still be made available
14 # in accordance with section (3) of the GNU General Public License.
15 #
16 # This exception does not invalidate any other reasons why a work based
17 # on this file might be covered by the GNU General Public License.
18 #
19 # Copyright (c) 2016-2018 Intra2net AG <info@intra2net.com>
20
21 from .build_cnfvar import BuildCnfVar
22 """Class to create user cnfvar objects on the fly"""
23
24
25 class BuildUser(BuildCnfVar):
26
27     def __init__(self, data='', instance=0, line_no=1):
28         BuildCnfVar.__init__(self, 'USER', instance, data, line_no)
29
30         # the bare defaults the UI adds upon
31         # creation of new groups
32         defaults = {
33             'USER_DISABLED': '0',
34             'USER_FULLNAME': '',
35             'USER_GROUPWARE_FOLDER_CALENDAR': 'INBOX/Calendar',
36             'USER_GROUPWARE_FOLDER_CONTACTS': 'INBOX/Contacts',
37             'USER_GROUPWARE_FOLDER_DRAFTS': 'INBOX/Drafts',
38             'USER_GROUPWARE_FOLDER_NOTES': 'INBOX/Notes',
39             'USER_GROUPWARE_FOLDER_OUTBOX': 'INBOX/Sent Items',
40             'USER_GROUPWARE_FOLDER_TASKS': 'INBOX/Tasks',
41             'USER_GROUPWARE_FOLDER_TRASH': 'INBOX/Deleted Items',
42             # always a member of the 'Alle' group
43             'USER_GROUP_MEMBER_REF': '2',
44             'USER_LOCALE': '',
45             'USER_PASSWORD': 'test1234',
46             'USER_TRASH_DELETEDAYS': '30',
47             'USER_WEBMAIL_MESSAGES_PER_PAGE': '25',
48             'USER_WEBMAIL_SIGNATURE': '',
49         }
50
51         self.add_defaults(defaults)
52
53     def disabled(self, disabled='1'):
54         self.update_cnf('USER_DISABLED', 0, disabled)
55         return self
56
57     def fullname(self, fullname):
58         self.update_cnf('USER_FULLNAME', 0, fullname)
59         return self
60
61     def password(self, password):
62         self.update_cnf('USER_PASSWORD', 0, password)
63         return self
64
65     def normal_email(self):
66         self.update_cnf('USER_EMAIL_FORWARD_ENABLE', 0, 'NONE')
67         return self
68
69     def forward_email(self, email):
70         self.update_cnf('USER_EMAIL_FORWARD_ENABLE', 0, 'FORWARD')
71
72         addr = self.update_cnf('USER_EMAIL_FORWARD_ADDRESS', 0, '')
73         self.update_cnf('USER_EMAIL_FORWARD_ADDRESS_ADDR', 0, email, addr)
74         return self
75
76     def copy_email(self, email):
77         self.update_cnf('USER_EMAIL_FORWARD_ENABLE', 0, 'COPY')
78
79         addr = self.update_cnf('USER_EMAIL_FORWARD_ADDRESS', 0, '')
80         self.update_cnf('USER_EMAIL_FORWARD_ADDRESS_ADDR', 0, email, addr)
81         return self
82
83     def add_group_member_ref(self, group_ref):
84         self.add_cnf('USER_GROUP_MEMBER_REF', -1, group_ref)
85         return self