def handle(self, *args, **options): try: initialize_cosinnus_after_startup() send_digest_for_current_portal(UserNotificationPreference.SETTING_WEEKLY) except Exception as e: logger.error('An critical error occured during weekly digest generation and bubbled up completely! Exception was: %s' % force_text(e), extra={'exception': e, 'trace': traceback.format_exc()}) if settings.DEBUG: raise
def handle(self, *args, **options): try: initialize_cosinnus_after_startup() (ended_subscriptions, booked_subscriptions) = process_due_subscription_payments() logger.info('Manual subscription payment processing finished.', extra={'ended_subscriptions': ended_subscriptions, 'booked_subscriptions': booked_subscriptions}) except Exception as e: logger.error('A critical error occured during daily subscription payment processing and bubbled up completely! Exception was: %s' % force_text(e), extra={'exception': e, 'trace': traceback.format_exc()}) if settings.DEBUG: raise
def handle(self, *args, **options): try: initialize_cosinnus_after_startup() self.stdout.write( "Checking active users and creating any missing nextcloud user accounts." ) counter = 0 created = 0 errors = 0 all_users = filter_active_users(filter_portal_users(get_user_model().objects.all())) # retrieve all existing users so we don't create them anew existing_nc_users = list_all_users() total_users = len(all_users) for user in all_users: counter += 1 # only add user if not already in NC user DB with their id if not get_nc_user_id(user) in existing_nc_users: try: create_user_from_obj(user) created += 1 except OCSException as e: if not e.statuscode == 102: # 102: user already exists errors += 1 self.stdout.write( f"Error: OCSException: '{e.message}' ({e.statuscode})" ) except Exception as e: if settings.DEBUG: raise errors += 1 self.stdout.write("Error: Exception: " + str(e)) self.stdout.write( f"{counter}/{total_users} users checked, {created} nextcloud users created ({errors} Errors)", ending="\r", ) self.stdout.flush() self.stdout.write( f"Done! {counter}/{total_users} users checked, {created} nextcloud users created ({errors} Errors)." ) except Exception as e: if settings.DEBUG: raise
def handle(self, *args, **options): if not settings.COSINNUS_CONFERENCES_ENABLED: self.stdout.write( 'COSINNUS_CONFERENCES_ENABLED is not True, aborting.') return try: initialize_cosinnus_after_startup() portal = CosinnusPortal.get_current() self.stdout.write( f"Checking active users and creates any missing group memberships for portal {portal.slug}." ) counter = 0 errors = 0 users_added = 0 portal_groups = get_cosinnus_group_model().objects.all_in_portal() total_groups = len(portal_groups) for group in portal_groups: counter += 1 # only run this for groups that have the cloud app activated if not 'cosinnus_cloud' in group.get_deactivated_apps(): # add members to group nextcloud_user_ids = [ get_nc_user_id(member) for member in group.actual_members ] # always add admin to groups nextcloud_user_ids.append( settings.COSINNUS_CLOUD_NEXTCLOUD_ADMIN_USERNAME) for nc_uid in nextcloud_user_ids: try: nextcloud.add_user_to_group( nc_uid, group.nextcloud_group_id) users_added += 1 except OCSException as e: errors += 1 self.stdout.write( f"Error (add user to group): OCSException: '{e.message}' ({e.statuscode})" ) except Exception as e: if settings.DEBUG: raise errors += 1 self.stdout.write( "Error (add user to group): Exception: " + str(e)) logger.error( "Error (nextcloud group user add): Exception: " + str(e), extra={"exc": e}) self.stdout.write( f"{counter}/{total_groups} groups processed, {users_added} groups members added ({errors} Errors)", ) self.stdout.write( f"Done! {counter}/{total_groups} groups processed, {users_added} groups members added ({errors} Errors)." ) except Exception as e: if settings.DEBUG: raise
def handle(self, *args, **options): try: initialize_cosinnus_after_startup() self.stdout.write( "Checking active users and creating any missing nextcloud user accounts." ) counter = 0 created = 0 folders_created = 0 users_added = 0 errors = 0 # TODO: only run the actual API calls for entries that are not yet set! portal_groups = get_cosinnus_group_model().objects.all_in_portal() total_groups = len(portal_groups) for group in portal_groups: counter += 1 # only run this for groups that have the cloud app activated if not 'cosinnus_cloud' in group.get_deactivated_apps(): # create and validate group and groupfolder name current_group_created = False if not group.nextcloud_group_id: generate_group_nextcloud_id(group, save=False) generate_group_nextcloud_groupfolder_name(group, save=False) group.save(update_fields=[ 'nextcloud_group_id', 'nextcloud_groupfolder_name' ]) if group.nextcloud_group_id and not group.nextcloud_groupfolder_name: group.nextcloud_groupfolder_name = group.nextcloud_group_id group.save( update_fields=["nextcloud_groupfolder_name"]) # create group try: response = nextcloud.create_group( group.nextcloud_group_id) if response: created += 1 current_group_created = True except OCSException as e: if not e.statuscode == 102: # 102: group already exists errors += 1 self.stdout.write( f"Error (group create): OCSException: '{e.message}' ({e.statuscode})" ) except Exception as e: if settings.DEBUG: raise errors += 1 self.stdout.write("Error (group create): Exception: " + str(e)) logger.error( "Error (nextcloud group create): Exception: " + str(e), extra={"exc": e}) # Creating a group folder in a group with an existing one is safe and will not create a new one if current_group_created: # create group folder and save its id try: nextcloud.create_group_folder( group.nextcloud_groupfolder_name, group.nextcloud_group_id, group, raise_on_existing_name=False, ) folders_created += 1 except OCSException as e: errors += 1 self.stdout.write( f"Error (group folder create): OCSException: '{e.message}' ({e.statuscode})" ) except Exception as e: if settings.DEBUG: raise errors += 1 self.stdout.write( "Error (group folder create): Exception: " + str(e)) logger.error( "Error (nextcloud group folder create): Exception: " + str(e), extra={"exc": e}) # add members to group nextcloud_user_ids = [ get_nc_user_id(member) for member in group.actual_members ] # always add admin to groups nextcloud_user_ids.append( settings.COSINNUS_CLOUD_NEXTCLOUD_ADMIN_USERNAME) for nc_uid in nextcloud_user_ids: try: nextcloud.add_user_to_group( nc_uid, group.nextcloud_group_id) users_added += 1 except OCSException as e: errors += 1 self.stdout.write( f"Error (add user to group): OCSException: '{e.message}' ({e.statuscode})" ) except Exception as e: if settings.DEBUG: raise errors += 1 self.stdout.write( "Error (add user to group): Exception: " + str(e)) logger.error( "Error (nextcloud group user add): Exception: " + str(e), extra={"exc": e}) self.stdout.write( f"{counter}/{total_groups} groups processed, {created} groups created, {folders_created} group folders created, {users_added} groups members added ({errors} Errors)", ) self.stdout.write( f"Done! {counter}/{total_groups} groups processed, {created} groups created, {folders_created} group folders created, {users_added} groups members added ({errors} Errors)." ) except Exception as e: if settings.DEBUG: raise
def __init__(self, *args, **kwargs): super(CosinnusCronJobBase, self).__init__(*args, **kwargs) initialize_cosinnus_after_startup()