Пример #1
0
def invited_users(invited_badge, instance=None, joined=None, activated=None):
    """get all invited users

    joined/activated may be one of the following:

    -   True  - return only those invited users who have joined the instance/
                activated their accounts
    -   False - return only those invited users who have not joined the
                instance/activated their accounts
    -   None  - return all invited users
    """
    if instance is None and joined is not None:
        raise Exception('instance must not be None if joined specified')
    if joined is True:
        q = User.all_q(instance=instance)
    else:
        q = User.all_q(instance=None)
    q = q.join(UserBadges, UserBadges.user_id == User.id) \
         .filter(UserBadges.badge_id == invited_badge.id)
    users = q.all()
    if joined is False:
        users = filter(lambda u: instance not in u.instances, users)
    if activated is not None:
        users = filter(lambda u: u.is_email_activated() == activated, users)
    return users
Пример #2
0
def main():
    parser = create_parser(description=__doc__)
    parser.add_argument(
        "-t",
        dest="template",
        default=template,
        type=unicode,
        help=("The template to use. " "(default: '%s', possible keys: %s)" % (template, possible_attrs)),
    )
    args = parser.parse_args()
    load_from_args(args)
    instances = get_instances(args)

    query = User.all_q()

    if instances is not None:
        instance_ids = [instance.id for instance in instances]
        query = query.filter(
            User.memberships.any(
                and_(
                    Membership.instance_id.in_(instance_ids),
                    or_(Membership.expire_time == None, Membership.expire_time > datetime.utcnow()),
                )
            )
        )

    for user in query:
        userinfo = user_info(user)
        s = args.template.format(**userinfo)
        print s.encode("utf-8")
Пример #3
0
    def wrapper(self):
        allowed_sender_options = self.get_allowed_sender_options(c.user)
        sender = self.form_result.get('sender')
        if ((sender not in allowed_sender_options) or
                (not allowed_sender_options[sender]['enabled'])):
            return ret_abort(_("Sorry, but you're not allowed to set these "
                               "message options"), code=403)

        recipients = User.all_q()
        filter_instances = self.form_result.get('filter_instances')
        recipients = recipients.join(Membership).filter(
            Membership.instance_id.in_(filter_instances))
        filter_badges = self.form_result.get('filter_badges')
        if filter_badges:
            recipients = recipients.join(UserBadges,
                                         UserBadges.user_id == User.id)
            recipients = recipients.filter(
                UserBadges.badge_id.in_([fb.id for fb in filter_badges]))

        return func(self,
                    allowed_sender_options[sender]['email'],
                    self.form_result.get('subject'),
                    self.form_result.get('body'),
                    recipients,
                    )
Пример #4
0
 def _to_python(self, value, state):
     from adhocracy.model import User
     if User.all_q()\
             .filter(func.lower(User.email) == value.lower()).count():
         raise formencode.Invalid(_('That email is already registered'),
                                  value, state)
     return value
Пример #5
0
def main():
    parser = create_parser(description=__doc__)
    parser.add_argument("-t",
                        dest="template",
                        default=template,
                        type=unicode,
                        help=("The template to use. "
                              "(default: '%s', possible keys: %s)" %
                              (template, possible_attrs)))
    args = parser.parse_args()
    load_from_args(args)
    instances = get_instances(args)

    query = User.all_q()

    if instances is not None:
        instance_ids = [instance.id for instance in instances]
        query = query.filter(
            User.memberships.any(
                and_(
                    Membership.instance_id.in_(instance_ids),
                    or_(Membership.expire_time == None,
                        Membership.expire_time > datetime.utcnow()))))

    for user in query:
        userinfo = user_info(user)
        s = args.template.format(**userinfo)
        print s.encode('utf-8')
Пример #6
0
 def _to_python(self, value, state):
     from adhocracy.model import User
     if User.all_q()\
             .filter(func.lower(User.email) == value.lower()).count():
         raise formencode.Invalid(
             _('That email is already registered'),
             value, state)
     return value
Пример #7
0
 def _to_python(self, value, state):
     if c.user.email.lower() == value.lower():
         return value
     from adhocracy.model import User
     if User.all_q()\
             .filter(func.lower(User.email) == value.lower()).count():
         raise formencode.Invalid(
             _('That email is already used by another account'),
             value, state)
     return value
Пример #8
0
 def _to_python(self, value, state):
     if (c.user is not None and c.user.email is not None
        and c.user.email.lower() == value.lower()):
         return value
     from adhocracy.model import User
     if User.all_q()\
             .filter(func.lower(User.email) == value.lower()).count():
         raise formencode.Invalid(
             _('That email is already used by another account'),
             value, state)
     return value
Пример #9
0
def invited_users(invited_badge, instance=None, joined=None, activated=None):
    """get all invited users

    joined/activated may be one of the following:

    -   True  - return only those invited users who have joined the instance/
                activated their accounts
    -   False - return only those invited users who have not joined the
                instance/activated their accounts
    -   None  - return all invited users
    """
    if instance is None and joined is not None:
        raise Exception("instance must not be None if joined specified")
    if joined is True:
        q = User.all_q(instance=instance)
    else:
        q = User.all_q(instance=None)
    q = q.join(UserBadges, UserBadges.user_id == User.id).filter(UserBadges.badge_id == invited_badge.id)
    users = q.all()
    if joined is False:
        users = filter(lambda u: instance not in u.instances, users)
    if activated is not None:
        users = filter(lambda u: u.is_email_activated() == activated, users)
    return users
Пример #10
0
    def wrapper(self):
        allowed_sender_options = self._get_allowed_sender_options(c.user)
        sender_email = self.form_result.get('sender_email')
        if ((sender_email not in allowed_sender_options)
                or (not allowed_sender_options[sender_email]['enabled'])):
            return ret_abort(_("Sorry, but you're not allowed to set these "
                               "message options"),
                             code=403)
        sender_name = None
        if has('global.message'):
            sender_name = self.form_result.get('sender_name')
        if not sender_name:
            sender_name = c.user.name

        recipients = User.all_q()
        filter_instances = self.form_result.get('filter_instances')
        recipients = recipients.join(Membership).filter(
            Membership.instance_id.in_(filter_instances))
        filter_badges = self.form_result.get('filter_badges')
        if filter_badges:
            recipients = recipients.join(UserBadges,
                                         UserBadges.user_id == User.id)
            recipients = recipients.filter(
                UserBadges.badge_id.in_([fb.id for fb in filter_badges]))

        if has('global.admin'):
            include_footer = self.form_result.get('include_footer')
        else:
            include_footer = True

        if len(filter_instances) == 1:
            instance = Instance.find(filter_instances[0])
        else:
            instance = None

        return func(
            self,
            self.form_result.get('subject'),
            self.form_result.get('body'),
            recipients.all(),
            sender_email=allowed_sender_options[sender_email]['email'],
            sender_name=sender_name,
            instance=instance,
            include_footer=include_footer,
        )
Пример #11
0
    def wrapper(self):
        allowed_sender_options = self._get_allowed_sender_options(c.user)
        sender_email = self.form_result.get('sender_email')
        if ((sender_email not in allowed_sender_options) or
                (not allowed_sender_options[sender_email]['enabled'])):
            return ret_abort(_("Sorry, but you're not allowed to set these "
                               "message options"), code=403)
        sender_name = None
        if has('global.message'):
            sender_name = self.form_result.get('sender_name')
        if not sender_name:
            sender_name = c.user.name

        recipients = User.all_q()
        filter_instances = self.form_result.get('filter_instances')
        recipients = recipients.join(Membership).filter(
            Membership.instance_id.in_(filter_instances))
        filter_badges = self.form_result.get('filter_badges')
        if filter_badges:
            recipients = recipients.join(UserBadges,
                                         UserBadges.user_id == User.id)
            recipients = recipients.filter(
                UserBadges.badge_id.in_([fb.id for fb in filter_badges]))

        if has('global.admin'):
            include_footer = self.form_result.get('include_footer')
        else:
            include_footer = True

        if len(filter_instances) == 1:
            instance = Instance.find(filter_instances[0])
        else:
            instance = None

        return func(self,
                    self.form_result.get('subject'),
                    self.form_result.get('body'),
                    recipients.all(),
                    sender_email=allowed_sender_options[sender_email]['email'],
                    sender_name=sender_name,
                    instance=instance,
                    include_footer=include_footer,
                    )