source: translationmanagerplugin/1.0/transmgr/Permissions.py

Last change on this file was 14413, checked in by Franz, 9 years ago

initial version of translationmanagerplugin based on the Bachelor thesis of Barbara Streppel

File size: 2.9 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2015 Gefasoft AG
4# Copyright (C) 2015 Franz Mayer <franz.mayer@gefasoft.de>
5# All rights reserved.
6#
7# This software is licensed as described in the file COPYING, which
8# you should have received as part of this distribution.
9#
10
11
12from trac.core import Component, implements
13from trac.perm import IPermissionRequestor, PermissionSystem
14
15"""
16Created on 06.10.2014
17
18@author: barbara.streppel
19"""
20
21
22# ===========================================================================
23# accepted permissions for this plugin
24# ===========================================================================
25
26permissionListView = [
27    "TRAC_ADMIN", "TM_EXPORT", "TM_VIEW", "TM_IMPORT", "TM_EDIT"]
28permissionListEdit = ["TRAC_ADMIN", "TM_EXPORT", "TM_IMPORT", "TM_EDIT"]
29permissionListExport = ["TRAC_ADMIN", "TM_EXPORT"]
30permissionListImport = ["TRAC_ADMIN", "TM_IMPORT"]
31
32
33# ===========================================================================
34# Method returns true, if the given user from the request object meets
35# the required demands
36# ===========================================================================
37
38
39def checkPermissionsView(self, req):
40    for permission in permissionListView:
41        if permission in PermissionSystem(self.env).get_user_permissions(
42            req.authname
43        ):
44            return True
45    return False
46
47
48def checkPermissionsEdit(self, req):
49    for permission in permissionListEdit:
50        if permission in PermissionSystem(self.env).get_user_permissions(
51            req.authname
52        ):
53            return True
54    return False
55
56
57def checkPermissionsExport(self, req):
58    for permission in permissionListExport:
59        if permission in PermissionSystem(self.env).get_user_permissions(
60            req.authname
61        ):
62            return True
63    return False
64
65
66def checkPermissionsImport(self, req):
67    for permission in permissionListImport:
68        if permission in PermissionSystem(self.env).get_user_permissions(
69            req.authname
70        ):
71            return True
72    return False
73
74
75def whatPermission(self, req):
76    perm = []
77    if checkPermissionsExport(self, req):
78        perm.append("export")
79    if checkPermissionsImport(self, req):
80        perm.append("import")
81    if checkPermissionsEdit(self, req):
82        perm.append("edit")
83    if checkPermissionsView(self, req):
84        perm.append("view")
85    return perm
86
87
88# ===========================================================================
89# Class to publish an additional Permission Type
90# ===========================================================================
91
92
93class TransPermission(Component):
94    implements(IPermissionRequestor)
95    """ publicise permission 'TM_VIEW', 'TM_EDIT', 'TM_EXPORT', 'TM_IMPORT'"""
96
97    # IPermissionRequestor
98
99    def get_permission_actions(self):
100        return ["TM_VIEW", "TM_EDIT", "TM_EXPORT", "TM_IMPORT"]
Note: See TracBrowser for help on using the repository browser.