Skip to content

Commit 262c62d

Browse files
Hot fix service visibility
1 parent f0cfc52 commit 262c62d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

app/home/routes.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,30 @@ def login():
125125

126126
def set_template_access(tosca, user_groups, active_group):
127127
info = {}
128-
for k, v in tosca.items():
129-
visibility = v.get("metadata").get("visibility") if "visibility" in v.get("metadata") else {"type": "public"}
130128

131-
if visibility.get("type") != "public":
132-
133-
regex = False if "groups_regex" not in visibility else True
129+
for k, v in tosca.items():
130+
metadata = v.get("metadata", {})
131+
visibility = metadata.get("visibility", {"type": "public"})
132+
133+
if not active_group and visibility["type"] != "private":
134+
metadata["access_locked"] = True
135+
info[k] = v
136+
elif active_group:
137+
is_locked = is_access_locked(visibility, active_group)
138+
if not (visibility["type"] == "private" and is_locked):
139+
metadata["access_locked"] = is_locked
140+
info[k] = v
134141

135-
if regex:
136-
access_locked = not re.match(visibility.get('groups_regex'), active_group)
137-
else:
138-
allowed_groups = visibility.get("groups")
139-
access_locked = True if active_group not in allowed_groups else False
142+
return info
140143

141-
if (visibility.get("type") == "private" and not access_locked) or visibility.get("type") == "protected":
142-
v["metadata"]["access_locked"] = access_locked
143-
info[k] = v
144-
else:
145-
info[k] = v
146144

147-
return info
145+
def is_access_locked(visibility, active_group):
146+
regex = "groups_regex" in visibility
147+
if regex:
148+
return not re.match(visibility["groups_regex"], active_group)
149+
else:
150+
allowed_groups = visibility.get("groups", [])
151+
return active_group not in allowed_groups
148152

149153

150154
def check_template_access(user_groups, active_group):

0 commit comments

Comments
 (0)