This adds a user to the provided group as a non-privileged member of that group. This function assumes that the group has already been verified to exist by the argparse restrictions.
(mongo_connector, username, group)
| 221 | |
| 222 | |
| 223 | def add_user_to_group(mongo_connector, username, group): |
| 224 | """ |
| 225 | This adds a user to the provided group as a non-privileged member of that group. |
| 226 | This function assumes that the group has already been verified to exist by the argparse restrictions. |
| 227 | """ |
| 228 | user_collection = mongo_connector.get_users_connection() |
| 229 | group_collection = mongo_connector.get_groups_connection() |
| 230 | now = datetime.now() |
| 231 | |
| 232 | user_exists = user_collection.count_documents({"userid": username}) |
| 233 | if user_exists == 0: |
| 234 | print("User does not yet exist. Please create the user first.") |
| 235 | return |
| 236 | |
| 237 | update_object = {} |
| 238 | update_object["$addToSet"] = {} |
| 239 | update_object["$addToSet"]["members"] = username |
| 240 | update_object["$set"] = {} |
| 241 | update_object["$set"]["updated"] = now |
| 242 | |
| 243 | group_collection.update_one({"name": group}, update_object) |
| 244 | |
| 245 | |
| 246 | def add_admin_to_group(mongo_connector, username, group): |
no test coverage detected