Beispiel #1
0
def get_tags_info_from_tag_ids(tag_ids, keys_to_pluck=None, conn=None):

    if not keys_to_pluck:
        tags = list(r.expr(tag_ids).map(lambda tag_id: r.table(TagsCollection).get(tag_id)).run(conn))

    else:
        tags = list(
            r.expr(tag_ids).map(lambda tag_id: r.table(TagsCollection).get(tag_id).pluck(keys_to_pluck)).run(conn)
        )

    return tags
Beispiel #2
0
def get_tags_info_from_tag_ids(tag_ids, keys_to_pluck=None, conn=None):

    if not keys_to_pluck:
        tags = list(
            r.expr(tag_ids).map(
                lambda tag_id: r.table(TagsCollection).get(tag_id)).run(conn))

    else:
        tags = list(
            r.expr(tag_ids).map(lambda tag_id: r.table(TagsCollection).get(
                tag_id).pluck(keys_to_pluck)).run(conn))

    return (tags)
Beispiel #3
0
def get_app_data_by_appids(appids,
                           table=AppsCollection,
                           fields_to_pluck=None,
                           conn=None):

    if fields_to_pluck and appids:
        apps = list(
            r.expr(appids).map(lambda app_id: r.table(table).get(app_id).pluck(
                fields_to_pluck)).run(conn))

    elif not fields_to_pluck and appids:
        apps = list(
            r.expr(appids).map(lambda app_id: r.table(table).get(app_id)).run(
                conn))

    return (apps)
    def get_sending_emails(self, notif_rules, conn=None):
        try:
            email_sender_list = []
            for notif in notif_rules:
                if notif[NotificationKeys.Group]:
                    users_list = (r.table(Collection.Groups).filter({
                        'name':
                        notif['group']
                    }).filter(lambda x: x['customer']['name'] == notif[
                        'customer_name']).map(lambda x: x['users']).run(conn))
                    if users_list:
                        users = map(lambda x: x['name'], user_list[0])
                        email_sender_list += (r.expr(users).map(
                            lambda user: r.table('users').get(user)).map(
                                lambda x: x['email']).run(conn))

                elif notif[NotificationKeys.User]:
                    email = (r.table(Collection.Users).get(
                        notif[NotificationKeys.User]).pluck(
                            UserKey.Email).run(conn))
                    if email:
                        email_sender_list.append(email[UserKey.Email])

        except Exception as e:
            logger.exception(e)

        return (email_sender_list)
Beispiel #5
0
def update_hidden_status(username,
                         customer_name,
                         uri,
                         method,
                         app_ids,
                         hidden='yes',
                         table=AppsCollection,
                         conn=None):
    if table == AppsCollection:
        CurrentAppsKey = AppsKey

    elif table == CustomAppsCollection:
        CurrentAppsKey = CustomAppsKey

    elif table == SupportedAppsCollection:
        CurrentAppsKey = SupportedAppsKey

    elif table == AgentAppsPerAgentCollection:
        CurrentAppsKey = AgentAppsKey

    try:
        if hidden == YES or hidden == NO:
            (r.expr(app_ids).for_each(lambda app_id: r.table(table).get(
                app_id).update({CurrentAppsKey.Hidden: hidden})).run(conn))
        elif hidden == 'toggle':
            for app_id in app_ids:
                toggled = (r.table(table).get(app_id).update({
                    CurrentAppsKey.Hidden:
                    (r.branch(r.row[CurrentAppsKey.Hidden] == YES, NO, YES))
                }).run(conn))

        results = (PackageResults(username, uri,
                                  method).toggle_hidden(app_ids, hidden))

    except Exception as e:
        logger.exception(e)
        results = (GenericResults(username, uri, method).something_broke(
            app_ids, 'toggle hidden on os_apps', e))

    return (results)