Skip to content

Commit 070e099

Browse files
authored
Merge pull request #242 from mxmeinhold/rum
2 parents 2660100 + 9a137da commit 070e099

File tree

6 files changed

+57
-14
lines changed

6 files changed

+57
-14
lines changed

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[MASTER]
22
ignore = ,input
33
persistent = yes
4+
load-plugins = pylint_quotes
45

56
[MESSAGES CONTROL]
67
disable =

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ All DB commands are from the `Flask-Migrate` library and are used to configure D
115115
docs [here](https://flask-migrate.readthedocs.io/en/latest/) for details.
116116

117117
## Code standards
118-
This project is configured to use Pylint. Commits will be pylinted by Travis CI and if the score drops your build will
118+
This project is configured to use Pylint. Commits will be pylinted by GitHub actions and if the score drops your build will
119119
fail blocking you from merging. To make your life easier just run it before making a PR.
120120

121121
To run pylint use this command:
122122
```bash
123-
pylint --load-plugins pylint_quotes packet/routes packet
123+
pylint packet/routes packet
124124
```
125125

126126
All python files should have a top-level docstring explaining the contents of the file and complex functions should

config.env.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
# Logging config
1717
LOG_LEVEL = environ.get("PACKET_LOG_LEVEL", "INFO")
18-
ANALYTICS_ID = environ.get("ANALYTICS_ID", "UA-420696-9")
1918

2019
# OpenID Connect SSO config
2120
REALM = environ.get("PACKET_REALM", "csh")
@@ -68,3 +67,8 @@
6867
# Packet Config
6968
PACKET_UPPER = environ.get("PACKET_UPPER", "packet.csh.rit.edu")
7069
PACKET_INTRO = environ.get("PACKET_INTRO", "freshmen-packet.csh.rit.edu")
70+
71+
# RUM
72+
RUM_APP_ID = environ.get("PACKET_RUM_APP_ID", "")
73+
RUM_CLIENT_TOKEN = environ.get("PACKET_RUM_CLIENT_TOKEN","")
74+
DD_ENV = environ.get("DD_ENV", "local-dev")

packet/ldap.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ def _is_member_of_group(self, member, group):
6767
else:
6868
return group in member.groups
6969

70+
def get_groups(self, member):
71+
if self.ldap:
72+
return list(
73+
map(
74+
lambda g: g[0][3:],
75+
filter(
76+
lambda d: d[1] == 'cn=groups',
77+
map(
78+
lambda group_dn: group_dn.split(','),
79+
member.get('memberOf')
80+
)
81+
)
82+
)
83+
)
84+
else:
85+
return member.groups
86+
87+
7088

7189
# Getters
7290

packet/templates/include/head.html

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@
3434

3535
<link rel="stylesheet" href="{{ url_for('static', filename='css/packet.min.css') }}">
3636

37+
<!-- RUM -->
38+
<script
39+
src="https://www.datadoghq-browser-agent.com/datadog-rum.js"
40+
type="text/javascript">
41+
</script>
42+
<script>
43+
window.DD_RUM && window.DD_RUM.init({
44+
applicationId: '{{ config["RUM_APP_ID"] }}',
45+
clientToken: '{{ config["RUM_CLIENT_TOKEN"] }}',
46+
site: 'datadoghq.com',
47+
service: 'Packet',
48+
env: '{{ config["DD_ENV"] }}',
49+
version: '{{ config["VERSION"] }}',
50+
sampleRate: 100,
51+
trackInteractions: true
52+
});
53+
54+
window.DD_RUM && window.DD_RUM.setUser({
55+
id: '{{ info.uid }}',
56+
realm: '{{ info.realm }}',
57+
});
58+
59+
// Add groups to global context so they get interpreted as a list
60+
window.DD_RUM && window.DD_RUM.addRumGlobalContext('usr', {
61+
groups: {{ info.groups|safe }},
62+
});
63+
</script>
64+
65+
3766
<!-- Push Notifications -->
3867
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
3968
<script>
@@ -66,14 +95,4 @@
6695
});
6796
});
6897
</script>
69-
70-
<!-- Analytics -->
71-
<script async src="https://www.googletagmanager.com/gtag/js?id={{ config['ANALYTICS_ID'] }}"></script>
72-
<script>
73-
window.dataLayer = window.dataLayer || [];
74-
function gtag(){dataLayer.push(arguments);}
75-
gtag('js', new Date());
76-
gtag('set', {'user_id': '{{ info.uid }}' });
77-
gtag('config', '{{ config['ANALYTICS_ID'] }}');
78-
</script>
7998
</head>

packet/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def wrapped_function(*args, **kwargs):
3636
info = {
3737
'realm': 'csh',
3838
'uid': uid,
39-
'admin': ldap.is_evals(member)
39+
'admin': ldap.is_evals(member),
40+
'groups': ldap.get_groups(member),
4041
}
4142

4243
kwargs['info'] = info

0 commit comments

Comments
 (0)