MCPcopy Create free account
hub / github.com/adobe/Marinus / add_user_to_group

Function add_user_to_group

python3_cron_scripts/setup.py:223–243  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

221
222
223def 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
246def add_admin_to_group(mongo_connector, username, group):

Callers 1

mainFunction · 0.85

Calls 2

get_users_connectionMethod · 0.80
get_groups_connectionMethod · 0.80

Tested by

no test coverage detected