Lines 32-39
UCS@school UDM-hook to prevent invalid combinations of user options
|
Link Here
|
---|
|
32 |
# /usr/share/common-licenses/AGPL-3; if not, see |
32 |
# /usr/share/common-licenses/AGPL-3; if not, see |
33 |
# <http://www.gnu.org/licenses/>. |
33 |
# <http://www.gnu.org/licenses/>. |
34 |
|
34 |
|
35 |
import univention.debug as ud |
|
|
36 |
from univention.admin.hook import simpleHook |
35 |
from univention.admin.hook import simpleHook |
|
|
36 |
import univention.admin.modules |
37 |
import univention.admin.uexceptions |
37 |
import univention.admin.uexceptions |
38 |
import univention.admin.localization |
38 |
import univention.admin.localization |
39 |
|
39 |
|
Lines 41-79
translation = univention.admin.localization.translation("univention-admin-hooks-
|
Link Here
|
---|
|
41 |
_ = translation.translate |
41 |
_ = translation.translate |
42 |
|
42 |
|
43 |
|
43 |
|
44 |
blacklisted_option_combinations = { |
44 |
option_blacklist = { |
45 |
"ucsschoolAdministrator": {"ucsschoolExam", "ucsschoolStudent"}, |
45 |
"ucsschoolAdministrator": {"ucsschoolExam", "ucsschoolStudent"}, |
46 |
"ucsschoolExam": {"ucsschoolAdministrator", "ucsschoolStaff", "ucsschoolTeacher"}, |
46 |
"ucsschoolExam": {"ucsschoolAdministrator", "ucsschoolStaff", "ucsschoolTeacher"}, |
47 |
"ucsschoolStaff": {"ucsschoolExam", "ucsschoolStudent"}, |
47 |
"ucsschoolStaff": {"ucsschoolExam", "ucsschoolStudent"}, |
48 |
"ucsschoolStudent": {"ucsschoolAdministrator", "ucsschoolStaff", "ucsschoolTeacher"}, |
48 |
"ucsschoolStudent": {"ucsschoolAdministrator", "ucsschoolStaff", "ucsschoolTeacher"}, |
49 |
"ucsschoolTeacher": {"ucsschoolExam", "ucsschoolStudent"}, |
49 |
"ucsschoolTeacher": {"ucsschoolExam", "ucsschoolStudent"}, |
50 |
} |
50 |
} |
51 |
option_names = { |
|
|
52 |
"ucsschoolAdministrator": _("UCS@school Administrator"), |
53 |
"ucsschoolExam": _("UCS@school Examuser"), |
54 |
"ucsschoolStaff": _("UCS@school staff"), |
55 |
"ucsschoolStudent": _("UCS@school student"), |
56 |
"ucsschoolTeacher": _("UCS@school teacher") |
57 |
} |
58 |
error_msg = _("%(option)s cannot be activated together with %(illegals)s.") |
59 |
|
51 |
|
60 |
|
52 |
|
61 |
class UcsschoolUserOptions(simpleHook): |
53 |
class UcsschoolUserOptions(simpleHook): |
62 |
type = "UcsschoolUserOptions" |
|
|
63 |
|
54 |
|
64 |
@staticmethod |
55 |
@staticmethod |
65 |
def check_options(module): |
56 |
def check_options(module): |
66 |
users_options = set(module.options) |
57 |
def _option_name(option): |
67 |
ucsschool_options = users_options.intersection(set(blacklisted_option_combinations.keys())) |
58 |
return univention.admin.modules.get(module.module).options[option].short_description |
68 |
for option in ucsschool_options: |
59 |
for option, invalid_options in option_blacklist.items(): |
69 |
illegal_options = blacklisted_option_combinations[option] |
60 |
if option not in module.options: |
70 |
if illegal_options.intersection(users_options): |
61 |
continue |
71 |
msg = error_msg % { |
62 |
if invalid_options & set(module.options): |
72 |
"option": option_names[option], |
63 |
raise univention.admin.uexceptions.invalidOptions(_("%(option)s cannot be activated together with %(illegals)s.") % { |
73 |
"illegals": ", ".join([option_names[o] for o in illegal_options]) |
64 |
"option": _option_name(option), |
74 |
} |
65 |
"illegals": ", ".join(map(_option_name, (invalid_options & set(module.options)))) |
75 |
ud.debug(ud.ADMIN, ud.WARN, msg) |
66 |
}) |
76 |
raise univention.admin.uexceptions.invalidOptions(msg) |
|
|
77 |
|
67 |
|
78 |
def hook_ldap_pre_create(self, module): |
68 |
def hook_ldap_pre_create(self, module): |
79 |
self.check_options(module) |
69 |
self.check_options(module) |