group.py
46 lines
| 1.7 KiB
| text/x-python
|
PythonLexer
r0 | # -*- coding: utf-8 -*- | |||
r112 | # Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors | |||
r0 | # | |||
r112 | # Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. | ||||
# You may obtain a copy of the License at | ||||
r0 | # | |||
r112 | # http://www.apache.org/licenses/LICENSE-2.0 | |||
r0 | # | |||
r112 | # Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
# See the License for the specific language governing permissions and | ||||
# limitations under the License. | ||||
r0 | ||||
from ziggurat_foundations.models.group import GroupMixin | ||||
from appenlight.models import Base | ||||
class Group(GroupMixin, Base): | ||||
r153 | __possible_permissions__ = ( | |||
"root_administration", | ||||
"test_features", | ||||
"admin_panel", | ||||
"admin_users", | ||||
"manage_partitions", | ||||
) | ||||
r0 | ||||
r153 | def get_dict(self, exclude_keys=None, include_keys=None, include_perms=False): | |||
r0 | result = super(Group, self).get_dict(exclude_keys, include_keys) | |||
if include_perms: | ||||
r153 | result["possible_permissions"] = self.__possible_permissions__ | |||
result["current_permissions"] = [p.perm_name for p in self.permissions] | ||||
r0 | else: | |||
r153 | result["possible_permissions"] = [] | |||
result["current_permissions"] = [] | ||||
r0 | exclude_keys_list = exclude_keys or [] | |||
include_keys_list = include_keys or [] | ||||
d = {} | ||||
for k in result.keys(): | ||||
r153 | if k not in exclude_keys_list and ( | |||
k in include_keys_list or not include_keys | ||||
): | ||||
r0 | d[k] = result[k] | |||
return d | ||||