Ensure a user's My Profile is mirrored into their Profiler list. This creates (or updates) one special encrypted Profiler entry owned by the same user. No username is excluded from the profile -> profiler sync.
(username: str)
| 15238 | SELECT g.id, g.name, g.owner, g.created_at, m.role AS my_role |
| 15239 | FROM groups g |
| 15240 | JOIN group_members m ON m.group_id=g.id |
| 15241 | WHERE m.username=? |
| 15242 | ORDER BY g.id DESC |
| 15243 | """, |
| 15244 | (me,), |
| 15245 | ).fetchall() |
| 15246 | return rows |
| 15247 | finally: |
| 15248 | conn.close() |
| 15249 | |
| 15250 | try: |
| 15251 | rows = _fetch_rows() |
| 15252 | except Exception: |
| 15253 | # One more attempt after ensuring schema (covers 'no such table' cases) |
| 15254 | try: |
| 15255 | db_init() |
| 15256 | except Exception: |
| 15257 | pass |
| 15258 | rows = _fetch_rows() |
| 15259 | |
| 15260 | class Obj: |
| 15261 | def __init__(self, r): |
| 15262 | self.__dict__.update(dict(r)) |
| 15263 | |
| 15264 | return render_template("groups.html", title="Groups", gs=[Obj(r) for r in rows]) |
| 15265 | |
| 15266 | @app.route("/groups/create", methods=["POST"]) |
| 15267 | @login_required |
| 15268 | def group_create(): |
| 15269 | """group_create. |
| 15270 | |
| 15271 | Chat/group feature helper or route handler. |
| 15272 | |
| 15273 | This docstring was expanded to make future maintenance easier. |
| 15274 | |
| 15275 | Returns: |
| 15276 | Varies. |
| 15277 | """ |
| 15278 | me = current_user() |
| 15279 | name = (request.form.get("name") or "").strip()[:64] |
| 15280 | members_raw = (request.form.get("members") or "").strip() |
| 15281 | if not name: |
| 15282 | flash("Group name required.") |
| 15283 | return redirect(url_for("groups")) |
| 15284 | |
| 15285 | members = set() |
| 15286 | if members_raw: |
| 15287 | for part in members_raw.split(","): |
| 15288 | part = part.strip() |
| 15289 | if part: |
| 15290 | members.add(part) |
| 15291 | members.add(me) |
| 15292 | |
| 15293 | valid = set(all_usernames()) |
| 15294 | members = [m for m in members if m in valid] |
| 15295 | |
| 15296 | conn = db_connect() |
| 15297 | cur = conn.cursor() |
no test coverage detected