def join_project(project_id, request_user, reason=None): project = get_project_for_update(project_id) join_project_checks(project) try: membership = get_membership(project.id, request_user.id) if not membership.check_action("join"): msg = _(astakos_messages.MEMBERSHIP_ASSOCIATED) raise ProjectConflict(msg) membership.perform_action("join", actor=request_user, reason=reason) except ProjectNotFound: membership = new_membership(project, request_user, actor=request_user, reason=reason) join_policy = project.application.member_join_policy if (join_policy == AUTO_ACCEPT_POLICY and (not project.violates_members_limit(adding=1))): membership.perform_action("accept", actor=request_user, reason=reason) qh_sync_user(request_user) logger.info("User %s joined %s." % (request_user.log_display, project)) else: membership_request_notify(project, membership.person) logger.info("User %s requested to join %s." % (request_user.log_display, project)) return membership
def leave_project(project_id, request_user): get_chain_for_update(project_id) membership = get_membership(project_id, request_user.id) if not membership.can_leave(): m = _(astakos_messages.NOT_ACCEPTED_MEMBERSHIP) raise PermissionDenied(m) project = membership.project leave_project_checks(project) auto_accepted = False leave_policy = project.application.member_leave_policy if leave_policy == AUTO_ACCEPT_POLICY: membership.remove() qh_sync_user(request_user) logger.info("User %s has left %s." % (request_user.log_display, project)) auto_accepted = True else: membership.leave_request() logger.info("User %s requested to leave %s." % (request_user.log_display, project)) membership_leave_request_notify(project, membership.person) return auto_accepted
def enroll_member(project_id, user, request_user=None, reason=None): try: project = get_project_for_update(project_id) except ProjectNotFound as e: raise ProjectConflict(e.message) accept_membership_project_checks(project, request_user) try: membership = get_membership(project_id, user.id) if not membership.check_action("enroll"): m = _(astakos_messages.MEMBERSHIP_ACCEPTED) raise ProjectConflict(m) membership.perform_action("enroll", actor=request_user, reason=reason) except ProjectNotFound: membership = new_membership(project, user, actor=request_user, enroll=True) qh_sync_user(user) logger.info("User %s has been enrolled in %s." % (membership.person.log_display, project)) membership_enroll_notify(project, membership.person) return membership
def join_project(project_id, request_user, reason=None): project = get_project_for_update(project_id) join_project_checks(project) try: membership = get_membership(project.id, request_user.id) if not membership.check_action("join"): msg = _(astakos_messages.MEMBERSHIP_ASSOCIATED) raise ProjectConflict(msg) membership.perform_action("join", actor=request_user, reason=reason) except ProjectNotFound: membership = new_membership(project, request_user, actor=request_user, reason=reason) join_policy = project.application.member_join_policy if (join_policy == AUTO_ACCEPT_POLICY and ( not project.violates_members_limit(adding=1))): membership.perform_action("accept", actor=request_user, reason=reason) qh_sync_user(request_user) logger.info("User %s joined %s." % (request_user.log_display, project)) else: membership_request_notify(project, membership.person) logger.info("User %s requested to join %s." % (request_user.log_display, project)) return membership
def join_project(project_id, request_user): get_chain_for_update(project_id) project = get_project_by_id(project_id) join_project_checks(project) membership, created = ProjectMembership.objects.get_or_create( project=project, person=request_user) if not created: msg = _(astakos_messages.MEMBERSHIP_REQUEST_EXISTS) raise PermissionDenied(msg) auto_accepted = False join_policy = project.application.member_join_policy if (join_policy == AUTO_ACCEPT_POLICY and (not project.violates_members_limit(adding=1))): membership.accept() qh_sync_user(request_user) logger.info("User %s joined %s." % (request_user.log_display, project)) auto_accepted = True else: membership_request_notify(project, membership.person) logger.info("User %s requested to join %s." % (request_user.log_display, project)) return auto_accepted
def join_project(project_id, request_user): get_chain_for_update(project_id) project = get_project_by_id(project_id) join_project_checks(project) membership, created = ProjectMembership.objects.get_or_create( project=project, person=request_user) if not created: msg = _(astakos_messages.MEMBERSHIP_REQUEST_EXISTS) raise PermissionDenied(msg) auto_accepted = False join_policy = project.application.member_join_policy if (join_policy == AUTO_ACCEPT_POLICY and ( not project.violates_members_limit(adding=1))): membership.accept() qh_sync_user(request_user) logger.info("User %s joined %s." % (request_user.log_display, project)) auto_accepted = True else: membership_request_notify(project, membership.person) logger.info("User %s requested to join %s." % (request_user.log_display, project)) return auto_accepted
def remove_membership(memb_id, request_user=None, reason=None): project = get_project_of_membership_for_update(memb_id) membership = get_membership_by_id(memb_id) remove_membership_checks(membership, request_user) user = membership.person membership.perform_action("remove", actor=request_user, reason=reason) qh_sync_user(user) logger.info("User %s has been removed from %s." % (user.log_display, project)) membership_change_notify(project, user, 'removed') return membership
def new_user(): email = random_email() defaults = {'first_name': random_name(), 'last_name': random_name(), 'is_active': True, } u, created = AstakosUser.objects.get_or_create( email=email, defaults=defaults) if created: quotas.qh_sync_user(u) return u.id, u.email return None
def new_user(): email = random_email() defaults = { 'first_name': random_name(), 'last_name': random_name(), 'is_active': True, } u, created = AstakosUser.objects.get_or_create(email=email, defaults=defaults) if created: quotas.qh_sync_user(u) return u.id, u.email return None
def remove_membership(project_id, memb_id, request_user=None): get_chain_for_update(project_id) membership = get_membership_by_id(project_id, memb_id) if not membership.can_remove(): m = _(astakos_messages.NOT_ACCEPTED_MEMBERSHIP) raise PermissionDenied(m) project = membership.project remove_membership_checks(project, request_user) user = membership.person membership.remove() qh_sync_user(user) logger.info("User %s has been removed from %s." % (user.log_display, project)) membership_change_notify(project, user, 'removed') return membership
def accept_membership(project_id, memb_id, request_user=None): get_chain_for_update(project_id) membership = get_membership_by_id(project_id, memb_id) if not membership.can_accept(): m = _(astakos_messages.NOT_MEMBERSHIP_REQUEST) raise PermissionDenied(m) project = membership.project accept_membership_checks(project, request_user) user = membership.person membership.accept() qh_sync_user(user) logger.info("User %s has been accepted in %s." % (user.log_display, project)) membership_change_notify(project, user, 'accepted') return membership
def enroll_member(project_id, user, request_user=None): get_chain_for_update(project_id) project = get_project_by_id(project_id) accept_membership_checks(project, request_user) membership, created = ProjectMembership.objects.get_or_create( project=project, person=user) if not membership.can_accept(): m = _(astakos_messages.NOT_MEMBERSHIP_REQUEST) raise PermissionDenied(m) membership.accept() qh_sync_user(user) logger.info("User %s has been enrolled in %s." % (membership.person.log_display, project)) membership_enroll_notify(project, membership.person) return membership
def leave_project(memb_id, request_user, reason=None): project = get_project_of_membership_for_update(memb_id) membership = get_membership_by_id(memb_id) leave_project_checks(membership, request_user) auto_accepted = False leave_policy = project.application.member_leave_policy if leave_policy == AUTO_ACCEPT_POLICY: membership.perform_action("remove", actor=request_user, reason=reason) qh_sync_user(request_user) logger.info("User %s has left %s." % (request_user.log_display, project)) auto_accepted = True else: membership.perform_action("leave_request", actor=request_user, reason=reason) logger.info("User %s requested to leave %s." % (request_user.log_display, project)) membership_leave_request_notify(project, membership.person) return auto_accepted
def accept_user(self, user, policy='manual'): logger.info("Moderating user: %s", user.log_display) if user.moderated and user.is_active: logger.warning("User already accepted, moderation" " skipped: %s", user.log_display) msg = _(astakos_messages.ACCOUNT_ALREADY_MODERATED) return ActivationResult(self.Result.ERROR, msg) if not user.email_verified: logger.warning("Cannot accept unverified user: %s", user.log_display) msg = _(astakos_messages.ACCOUNT_NOT_VERIFIED) return ActivationResult(self.Result.ERROR, msg) # store a snapshot of user details by the time he # got accepted. if not user.accepted_email: user.accepted_email = user.email user.accepted_policy = policy user.moderated = True user.moderated_at = datetime.datetime.now() user.moderated_data = json.dumps(user.__dict__, default=lambda obj: str(obj)) user.save() qh_sync_user(user) if user.is_rejected: logger.warning("User has previously been " "rejected, reseting rejection state: %s", user.log_display) user.is_rejected = False user.rejected_at = None user.save() logger.info("User accepted: %s", user.log_display) self.activate_user(user) return ActivationResult(self.Result.ACCEPTED)
def accept_user(self, user, policy='manual'): logger.info("Moderating user: %s", user.log_display) if user.moderated and user.is_active: logger.warning("User already accepted, moderation" " skipped: %s", user.log_display) msg = _(astakos_messages.ACCOUNT_ALREADY_MODERATED) return ActivationResult(self.Result.ERROR, msg) if not user.email_verified: logger.warning("Cannot accept unverified user: %s", user.log_display) msg = _(astakos_messages.ACCOUNT_NOT_VERIFIED) return ActivationResult(self.Result.ERROR, msg) # store a snapshot of user details by the time he # got accepted. if not user.accepted_email: user.accepted_email = user.email user.accepted_policy = policy user.moderated = True user.moderated_at = datetime.datetime.now() user.moderated_data = json.dumps(user.__dict__, default=lambda obj: str(obj)) user.save() qh_sync_user(user) if user.is_rejected: logger.warning( "User has previously been " "rejected, reseting rejection state: %s", user.log_display) user.is_rejected = False user.rejected_at = None user.save() logger.info("User accepted: %s", user.log_display) self.activate_user(user) return ActivationResult(self.Result.ACCEPTED)