This repository was archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtraversal.py
More file actions
80 lines (61 loc) · 2.26 KB
/
traversal.py
File metadata and controls
80 lines (61 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This file is a part of github2fedmsg, a pubsubhubbub to zeromq bridge.
# Copyright (C) 2014, Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from hashlib import md5
import tw2.core as twc
import github2fedmsg.models
import github2fedmsg.widgets
from pyramid.security import authenticated_userid
def make_root(request):
return RootApp(request)
class RootApp(dict):
__name__ = None
__parent__ = None
def __init__(self, request):
dict.__init__(self)
self.request = request
self.static = dict(
api=ApiApp(),
)
def __getitem__(self, key):
if key in self.static:
return self.static[key]
query = github2fedmsg.models.User.query.filter_by(username=key)
if query.count() != 1:
raise KeyError("No such user")
user = query.one()
# TODO -- use __acl__ machinery some day
userid = authenticated_userid(self.request)
# TODO -- check if this is an org that I own
show_buttons = (userid == user.username)
return UserApp(user=user, show_buttons=show_buttons)
class ApiApp(object):
def __getitem__(self, key):
query = github2fedmsg.models.User.query.filter_by(username=key)
if query.count() != 1:
raise KeyError("No such user")
return query.one()
class UserApp(github2fedmsg.widgets.UserProfile):
__name__ = None
__parent__ = RootApp
@classmethod
def __getitem__(self, key):
for repo in self.user.repos:
if repo.name == key:
return repo
raise KeyError
class APISuccess(object):
def __init__(self, data):
self.data = data