@@ -125,26 +125,30 @@ def login():
125
125
126
126
def set_template_access (tosca , user_groups , active_group ):
127
127
info = {}
128
- for k , v in tosca .items ():
129
- visibility = v .get ("metadata" ).get ("visibility" ) if "visibility" in v .get ("metadata" ) else {"type" : "public" }
130
128
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
134
141
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
140
143
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
146
144
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
148
152
149
153
150
154
def check_template_access (user_groups , active_group ):
0 commit comments