Coverage for portality / bll / services / tour.py: 74%
34 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
1from portality.core import app
3class TourService(object):
4 def activeTours(self, path, user):
5 tours = app.config.get("TOURS", {})
6 active_tours = []
7 for k, v in tours.items():
8 if self._is_active_path(path, k):
9 for tour in v:
10 if "roles" in tour:
11 if user is None:
12 continue
13 for r in tour.get("roles"):
14 if user.has_role(r):
15 active_tours.append(tour)
16 break
17 else:
18 active_tours.append(tour)
19 return active_tours
21 def _is_active_path(self, given, candidate):
22 sw = False
23 if candidate.endswith("*"):
24 candidate = candidate[:-1]
25 sw = True
27 if not sw and given == candidate:
28 return True
30 if sw and given.startswith(candidate):
31 return True
33 return False
35 def validateContentId(self, content_id):
36 tours = app.config.get("TOURS", {})
37 for k, v in tours.items():
38 for tour in v:
39 if tour.get("content_id") == content_id:
40 return True
41 return False