def _update_user_membership(self, tas_project, username, action=None): if action not in ["add", "delete"]: raise ValueError("Invalid membership action {}".format(action)) charge_code = self.get_attr(tas_project, "chargeCode") keycloak_client = KeycloakClient() keycloak_client.update_membership(charge_code, username, action)
def end_daypasses(): beyond_duration_invitations = get_invitations_beyond_duration() for invitation in beyond_duration_invitations: try: LOG.info(f"Removing user from project with invite {invitation.id}\n") project = Project.objects.get(pk=invitation.project_id) user = User.objects.get(pk=invitation.user_accepted_id) keycloak_client = KeycloakClient() keycloak_client.update_membership( project.charge_code, user.username, "delete" ) invitation.status = Invitation.STATUS_BEYOND_DURATION invitation.save() try: daypass_request = DaypassRequest.objects.get(invitation=invitation) approved_requests = ( DaypassRequest.objects.all() .filter( artifact=daypass_request.artifact, status=DaypassRequest.STATUS_APPROVED, invitation__status=Invitation.STATUS_BEYOND_DURATION, ) .count() ) if approved_requests == settings.DAYPASS_LIMIT: # Send an email handle_too_many_daypass_users(daypass_request.artifact) except DaypassRequest.DoesNotExist: pass except Exception as e: LOG.error(f"Error ending daypass invite {invitation.id}: {e}")
def _update_user_membership(self, tas_project, user_ref, action=None): if action not in ["add", "delete"]: raise ValueError("Invalid membership action {}".format(action)) UserModel = get_user_model() try: user = UserModel.objects.get(username=user_ref) except UserModel.DoesNotExist: user = UserModel.objects.get(email=user_ref) charge_code = self.get_attr(tas_project, "chargeCode") keycloak_client = KeycloakClient() keycloak_client.update_membership(charge_code, user.username, action)