Fetch a server group by ID, verifying user access. Returns the group if: - Desktop mode, OR - The user owns it, OR - It contains shared servers (Server.shared=True). Returns None otherwise. The Administrator role does not grant access to other users' private groups.
(gid)
| 66 | |
| 67 | |
| 68 | def get_server_group(gid): |
| 69 | """Fetch a server group by ID, verifying user access. |
| 70 | |
| 71 | Returns the group if: |
| 72 | - Desktop mode, OR |
| 73 | - The user owns it, OR |
| 74 | - It contains shared servers (Server.shared=True). |
| 75 | |
| 76 | Returns None otherwise. The Administrator role does not grant |
| 77 | access to other users' private groups. |
| 78 | """ |
| 79 | if not config.SERVER_MODE: |
| 80 | return ServerGroup.query.filter_by(id=gid).first() |
| 81 | |
| 82 | return ServerGroup.query.filter( |
| 83 | ServerGroup.id == gid, |
| 84 | or_( |
| 85 | ServerGroup.user_id == current_user.id, |
| 86 | ServerGroup.id.in_( |
| 87 | db.session.query(Server.servergroup_id).filter( |
| 88 | Server.shared |
| 89 | ) |
| 90 | ) |
| 91 | ) |
| 92 | ).first() |
| 93 | |
| 94 | |
| 95 | def get_server_groups_for_user(): |
no test coverage detected