-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuserncquota.py
94 lines (71 loc) · 3.07 KB
/
userncquota.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""userncquota.py - FreeIPA plugin to set a quota for nextcloud users.
Copyright (C) $( 2020 ) Radio Bern RaBe
Switzerland
http://www.rabe.ch
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, version
3 of the License.
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/>.
Please submit enhancements, bugfixes or comments via:
https://github.com/radiorabe/kanboard-tasks-from-email
Authors:
Simon Nussbaum <[email protected]>
Description:
With this plugin a switch will be added to the ipa cli to set a quota for
users connecting to nextcloud. It will set the Attribute nextcloudQuota.
Allowed values are 'default' or an integer with 'MB', 'GB' etc.
For this to work, extending the LDAP schema is required.
Installation:
Copy file to <path to python lib>/ipaserver/plugins/
Usage:
ipa user-mod --nextcloudquota="100 MB" <username>
"""
from ipaserver.plugins import user
from ipalib.parameters import Str
from ipalib.text import _
user.user.takes_params = user.user.takes_params + (
Str(
"nextcloudquota?",
cli_name="nextcloudquota",
label=_("Nextcloud Share Quota"),
doc=_(
"Defines Nextcloud share quota in Bytes. "
'Allowed values are "none",'
'"default", e.g. "1024 MB" (default is "default").'
),
default="default",
autofill=True,
pattern="^(default|none|[0-9]+ [MGT]B)$",
pattern_errmsg="".join(
'may only be "none", '
'"default" or a number of mega-, giga- or terabytes (e.g. 1024 MB)'
),
),
)
user.user.default_attributes.append("nextcloudquota")
# pylint: disable-msg=unused-argument,invalid-name,line-too-long
def useradd_precallback(self, ldap, dn, entry, attrs_list, *keys, **options):
"""Callback for `register_pre_callback`.
See <https://github.com/freeipa/freeipa/blob/master/doc/guide/guide.org#extending-existing-object> for details.
"""
entry["objectclass"].append("nextclouduser")
return dn
user.user_add.register_pre_callback(useradd_precallback)
# pylint: disable-msg=unused-argument,invalid-name,line-too-long
def usermod_precallback(self, ldap, dn, entry, attrs_list, *keys, **options):
"""Callback for `register_pre_callback`.
See <https://github.com/freeipa/freeipa/blob/master/doc/guide/guide.org#extending-existing-object> for details.
"""
if "objectclass" not in entry.keys():
old_entry = ldap.get_entry(dn, ["objectclass"])
entry["objectclass"] = old_entry["objectclass"]
entry["objectclass"].append("nextclouduser")
return dn
user.user_mod.register_pre_callback(usermod_precallback)