• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uw-it-aca / myuw / 9232782437

25 May 2024 04:06AM UTC coverage: 91.866% (+0.05%) from 91.816%
9232782437

Pull #3109

github

fanglinfang
Add test cache_expiration of mailman
Pull Request #3109: Fix/muwm 5308

69 of 78 new or added lines in 9 files covered. (88.46%)

1 existing line in 1 file now uncovered.

17540 of 19093 relevant lines covered (91.87%)

9.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.81
/myuw/dao/pws.py
1
# Copyright 2024 UW-IT, University of Washington
2
# SPDX-License-Identifier: Apache-2.0
3

4
"""
1✔
5
This module encapsulates the interactions with the uw_pws,
6
provides information of the current user
7
"""
8

9
import logging
1✔
10
from uw_pws import PWS, Person
1✔
11
from restclients_core.exceptions import DataFailureException
1✔
12
from myuw.dao import get_netid_of_current_user
1✔
13
from myuw.dao.exceptions import IndeterminateCampusException
1✔
14

15
#
16
# mailstop campus range limits as set by UW Mailing Services
17
#
18
MAILSTOP_MIN_TACOMA = 358400
1✔
19
MAILSTOP_MAX_TACOMA = 358499
1✔
20
MAILSTOP_MIN_BOTHELL = 358500
1✔
21
MAILSTOP_MAX_BOTHELL = 358599
1✔
22
pws = PWS()
1✔
23
logger = logging.getLogger(__name__)
1✔
24

25

26
def get_person_by_employee_id(employee_id):
1✔
27
    return pws.get_person_by_employee_id(employee_id)
1✔
28

29

30
def get_person_by_regid(regid):
1✔
31
    return pws.get_person_by_regid(regid)
×
32

33

34
def get_person_of_current_user(request):
1✔
35
    """
36
    Retturn a pws Person object with the netid of the current user,
37
    If no Person exists return a pws Entity object
38
    """
39
    if not hasattr(request, "myuw_pws_person"):
1✔
40
        netid = get_netid_of_current_user(request)
1✔
41
        try:
1✔
42
            request.myuw_pws_person = pws.get_person_by_netid(netid)
1✔
43
        except DataFailureException as err:
1✔
44
            if err.status == 404:  # Non-personal
1✔
45
                request.myuw_pws_person = pws.get_entity_by_netid(netid)
1✔
46
            else:
47
                raise
×
48
    return request.myuw_pws_person
1✔
49

50

51
def person_prefetch():
1✔
52
    def _method(request):
1✔
53
        return get_person_of_current_user(request)
1✔
54
    return [_method]
1✔
55

56

57
def get_display_name_of_current_user(request):
1✔
58
    person = get_person_of_current_user(request)
1✔
59
    return person.display_name
1✔
60

61

62
def get_regid_of_current_user(request):
1✔
63
    person = get_person_of_current_user(request)
1✔
64
    return person.uwregid
1✔
65

66

67
def get_employee_id_of_current_user(request):
1✔
68
    person = get_person_of_current_user(request)
1✔
69
    if isinstance(person, Person):
1✔
70
        return person.employee_id
1✔
71
    return None
×
72

73

74
def get_student_number_of_current_user(request):
1✔
75
    person = get_person_of_current_user(request)
1✔
76
    if isinstance(person, Person):
1✔
77
        return person.student_number
1✔
78
    return None
×
79

80

81
def get_student_system_key_of_current_user(request):
1✔
82
    person = get_person_of_current_user(request)
1✔
83
    if isinstance(person, Person):
1✔
84
        return person.student_system_key
1✔
85
    return None
×
86

87

88
def is_alumni(request):
1✔
89
    person = get_person_of_current_user(request)
1✔
90
    return (isinstance(person, Person) and
1✔
91
            person.is_alum is True and
92
            person.is_alum_state_current())
93

94

95
def is_employee(request):
1✔
96
    """
97
    Current faculty, staff, and student employees
98
    """
99
    person = get_person_of_current_user(request)
1✔
100
    return (isinstance(person, Person) and
1✔
101
            person.is_employee is True and
102
            person.is_emp_state_current())
103

104

105
def is_student(request):
1✔
106
    """
107
    Return true if the user is an
108
    UW undergraduate/graduate/onleave graduate/pce students
109
    who are enrolled for the current quarter,
110
    the previous quarter, or a future quarter
111
    """
112
    person = get_person_of_current_user(request)
1✔
113
    return isinstance(person, Person) and person.is_student is True
1✔
114

115

116
def is_faculty(request):
1✔
117
    """
118
    UW faculty members who are currently employed.
119
    """
120
    person = get_person_of_current_user(request)
1✔
121
    return isinstance(person, Person) and person.is_faculty is True
1✔
122

123

124
def is_bothell_employee(request):
1✔
125
    person = get_person_of_current_user(request)
1✔
126
    if isinstance(person, Person) and person.mailstop:
1✔
127
        mailstop = int(person.mailstop)
1✔
128
        return MAILSTOP_MIN_BOTHELL <= mailstop <= MAILSTOP_MAX_BOTHELL
1✔
129
    return False
1✔
130

131

132
def is_tacoma_employee(request):
1✔
133
    person = get_person_of_current_user(request)
1✔
134
    if isinstance(person, Person) and person.mailstop:
1✔
135
        mailstop = int(person.mailstop)
1✔
136
        return MAILSTOP_MIN_TACOMA <= mailstop <= MAILSTOP_MAX_TACOMA
1✔
137
    return False
1✔
138

139

140
def is_seattle_employee(request):
1✔
141
    person = get_person_of_current_user(request)
1✔
142
    return (isinstance(person, Person) and person.mailstop and
1✔
143
            not is_tacoma_employee(request) and
144
            not is_bothell_employee(request))
145

146

147
def is_prior_employee(request):
1✔
148
    person = get_person_of_current_user(request)
1✔
149
    return isinstance(person, Person) and person.is_emp_state_prior()
1✔
150

151

152
def is_prior_student(request):
1✔
153
    person = get_person_of_current_user(request)
1✔
154
    return (isinstance(person, Person) and
1✔
155
            person.is_stud_state_prior() and
156
            is_student(request) is False)
157

158

159
def is_retiree(request):
1✔
160
    person = get_person_of_current_user(request)
1✔
161
    return isinstance(person, Person) and person.is_retiree()
1✔
162

163

164
def get_idcard_photo(regid):
1✔
UNCOV
165
    return pws.get_idcard_photo(regid)
×
166

167

168
def get_employee_campus(request):
1✔
169
    """
170
    determine based on mailstop ranges supplied by
171
    UW Campus Mailing Services mailserv@uw.edu
172
    """
173
    if is_tacoma_employee(request):
1✔
174
        return 'Tacoma'
1✔
175
    if is_bothell_employee(request):
1✔
176
        return 'Bothell'
1✔
177
    if is_seattle_employee(request):
1✔
178
        return 'Seattle'
1✔
179
    raise IndeterminateCampusException()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc