You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let part_of_site = state.cache.raw.get_with(cache_key,async{
144
-
// Verify that the user is a member of the team that owns the site
145
-
let part_of_site = query_scalar!(
146
-
"SELECT EXISTS (SELECT 1 FROM sites WHERE site_id = $1 AND team_id IN (SELECT team_id FROM user_teams WHERE user_id = $2) OR team_id IN (SELECT team_id FROM teams WHERE owner_id = $2))",
147
-
self.0,
148
-
user_id
149
-
)
150
-
.fetch_one(&state.database.pool)
151
-
.await;
152
-
153
-
let part_of_site = part_of_site.ok().flatten().unwrap_or(false);
154
-
serde_json::to_value(part_of_site).unwrap()
149
+
if resource == "user"{
150
+
// Verify that the user is a member of the team that owns the site
151
+
let part_of_site = query_scalar!(
152
+
"SELECT EXISTS (SELECT 1 FROM sites WHERE site_id = $1 AND team_id IN (SELECT team_id FROM user_teams WHERE user_id = $2) OR team_id IN (SELECT team_id FROM teams WHERE owner_id = $2))",
153
+
self.0,
154
+
resource_id
155
+
)
156
+
.fetch_one(&state.database.pool)
157
+
.await;
158
+
159
+
let part_of_site = part_of_site.ok().flatten().unwrap_or(false);
160
+
161
+
serde_json::to_value(part_of_site).unwrap()
162
+
}elseif resource == "site"{
163
+
ifself.0 == resource_id {
164
+
serde_json::to_value(true).unwrap()
165
+
}else{
166
+
serde_json::to_value(false).unwrap()
167
+
}
168
+
}elseif resource == "team"{
169
+
let site = Site::get_by_id(&state.database, resource_id).await.map_err(HttpError::from).ok();
170
+
171
+
let site_has_access = site
172
+
.map(|s| s.team_id == resource_id)
173
+
.unwrap_or(false);
174
+
175
+
serde_json::to_value(site_has_access).unwrap()
176
+
}else{
177
+
serde_json::to_value(false).unwrap()
178
+
}
155
179
}).await;
156
180
157
181
let part_of_site:bool = serde_json::from_value(part_of_site).unwrap_or_default();
0 commit comments