~yeliabmas/sloecode/bug-fix

« back to all changes in this revision

Viewing changes to sloecode/lib/security.py

  • Committer: Thomi Richards
  • Date: 2012-05-02 16:20:55 UTC
  • mfrom: (156.1.1 license-compat)
  • Revision ID: thomi.richards@canonical.com-20120502162055-tkccaqjx2ffuqk09
merged code to fix GPL license compatibility, PEp8 and PEP257 fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""Functions that perform various security checks. Used by security predicate
2
 
classes, and also from within template code.
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation, either version 3 of the License, or
 
6
# (at your option) any later version.
 
7
 
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
# Copyright 2012 Sloecode Developers
 
17
 
 
18
"""Functions that perform various security checks.
 
19
 
 
20
Used by security predicate classes, and also from within template code.
3
21
"""
4
22
 
5
23
import logging
13
31
 
14
32
logger = logging.getLogger(__name__)
15
33
 
 
34
 
16
35
def has_site_role(role_name, user=None):
17
36
    """Determines whether the currently logged in user has the specified
18
37
    site-role.
55
74
        raise TypeError("project must be Project,str,unicode, or int type.")
56
75
    return prj_obj
57
76
 
 
77
 
58
78
def has_project_role(project, role_name, user=None):
59
79
    """Determines whether the currently logged in user has the specified role
60
80
    for a given project. The project can either be the project name (as a
75
95
    except KeyError:
76
96
        return False
77
97
 
 
98
 
78
99
def has_project_access(project, user=None, read_only=True):
79
100
    """Checks whether user as read access to the project resource."""
80
101
    prj_obj = _get_project_object(project)
100
121
            return False
101
122
    return False
102
123
 
 
124
 
103
125
def _get_user_object(user):
104
126
    usr_obj = None
105
127
    if isinstance(user, Person):
122
144
        raise TypeError("user must be Person,str,unicode, or int type.")
123
145
    return usr_obj
124
146
 
 
147
 
125
148
def visible_projects(user):
126
149
    """Get the list of projects visible by a user.
127
150