示例#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():
    args = parse_args()
    load_config(args.conf_file)

    if args.instance is None:
        instance = None
    else:
        instance = valid_instance(args.instance)
    invited_badge = valid_userbadge(args.badge.decode('utf-8'), instance)
    creator = User.find(u'admin')

    if args.action == u'invite':
        template = valid_template(args.template)
        csv_data = valid_csv(args.csv_file)
        for user_info in csv_data:
            user_info[u'user_badges'].add(invited_badge)

        ret = user_import(csv_data, args.subject, template, creator, instance)
        print_invite_result(ret)
    elif args.action == u'reinvite':
        template = valid_template(args.template)

        users = invited_users(invited_badge, activated=False)
        csv_data = [{
            u'email': u.email,
            u'user_name': u.user_name,
            u'display_name': u.display_name,
            u'user_badges': set(),
        } for u in users]

        ret = user_import(csv_data,
                          args.subject,
                          template,
                          creator,
                          instance,
                          reinvite=True)
        print_invite_result(ret, reinvite=True)
    elif args.action == u'revoke':
        users = invited_users(invited_badge, activated=False)
        if len(users) != 0:
            for user in users:
                revoke(user)
        else:
            print(u"No users to revoke")
    elif args.action == u'uninvite':
        if len(args.users) != 0:
            for name in args.users:
                user = User.find(name)
                uninvite(user, invited_badge, revoke=args.revoke)
        else:
            print(u"No users to uninvite")

    meta.Session.commit()
示例#3
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")
示例#4
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,
                    )
示例#5
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
示例#6
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')
示例#7
0
文件: invite.py 项目: alkadis/vcv
def main():
    args = parse_args()
    load_config(args.conf_file)

    if args.instance is None:
        instance = None
    else:
        instance = valid_instance(args.instance)
    invited_badge = valid_userbadge(args.badge.decode("utf-8"), instance)
    creator = User.find(u"admin")

    if args.action == u"invite":
        template = valid_template(args.template)
        csv_data = valid_csv(args.csv_file)
        for user_info in csv_data:
            user_info[u"user_badges"].add(invited_badge)

        ret = user_import(csv_data, args.subject, template, creator, instance)
        print_invite_result(ret)
    elif args.action == u"reinvite":
        template = valid_template(args.template)

        users = invited_users(invited_badge, activated=False)
        csv_data = [
            {u"email": u.email, u"user_name": u.user_name, u"display_name": u.display_name, u"user_badges": set()}
            for u in users
        ]

        ret = user_import(csv_data, args.subject, template, creator, instance, reinvite=True)
        print_invite_result(ret, reinvite=True)
    elif args.action == u"revoke":
        users = invited_users(invited_badge, activated=False)
        if len(users) != 0:
            for user in users:
                revoke(user)
        else:
            print (u"No users to revoke")
    elif args.action == u"uninvite":
        if len(args.users) != 0:
            for name in args.users:
                user = User.find(name)
                uninvite(user, invited_badge, revoke=args.revoke)
        else:
            print (u"No users to uninvite")

    meta.Session.commit()
示例#8
0
 def _to_python(self, value, state):
     from adhocracy.model import User
     user = User.find(value)
     if not user:
         raise formencode.Invalid(
             _("No user with the user name '%s' exists") % value, value,
             state)
     return user
示例#9
0
文件: common.py 项目: whausen/part
 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
示例#10
0
文件: common.py 项目: whausen/part
 def _to_python(self, value, state):
     from adhocracy.model import User
     user = User.find(value)
     if not user:
         raise formencode.Invalid(
             _("No user with the user name '%s' exists") % value,
             value, state)
     return user
示例#11
0
文件: common.py 项目: whausen/part
 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
示例#12
0
文件: common.py 项目: alkadis/vcv
 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
示例#13
0
文件: invite.py 项目: alkadis/vcv
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
示例#14
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,
        )
示例#15
0
def main():
    parser = create_parser(description=__doc__, use_instance=False)
    parser.add_argument(
        "username",
        help=("The name of the user who should become a global admin"))
    args = parser.parse_args()
    load_from_args(args)

    user = User.find(args.username)
    if user is None:
        print 'Cannot find user %s\n' % args.username
        parser.exit()

    global_membership = [membership for membership in user.memberships if
                         membership.instance is None][0]
    admin_group = Group.by_code(Group.CODE_ADMIN)
    global_membership.group = admin_group
    meta.Session.commit()
示例#16
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,
                    )