Beispiel #1
0
    def get_user_city_ids(cls):

        if current_user.has_groups(['activity_manager', 'marketing_manager']):
            return {city.id: city.name for city in
                    city_base.get_all_cities()}

        elif current_user.has_groups(['city_director']):
            return city_base.get_city_id_name_pairs_by_user()

        return []
        def wrapper(*args, **kwargs):
            if current_app.login_manager._login_disabled:
                return func(*args, **kwargs)
            elif not current_user.is_authenticated():
                return current_app.login_manager.unauthorized()

            if all and not current_user.has_groups(groups):
                return current_app.login_manager.unauthorized()
            elif not current_user.has_groups(groups, all=False):
                return current_app.login_manager.unauthorized()

            return func(*args, **kwargs)
Beispiel #3
0
 def decorated_view(*args, **kwargs):
     if not current_app.config['LOGIN_REQUIRED']:
         check_result = True
     else:
         check_result = current_user.has_groups(groups, is_strict)
     if check_result:
         return fn(*args, **kwargs)
     else:
         return no_permission()
Beispiel #4
0
 def decorated_view(*args, **kwargs):
     if not current_app.config['LOGIN_REQUIRED']:
         check_result = True
     else:
         check_result = current_user.has_groups(groups, is_strict)
     if check_result:
         return fn(*args, **kwargs)
     else:
         return no_permission()
Beispiel #5
0
        def wrapper(*args, **kwargs):
            auth_groups = AUTH_MAP.get(endpoint)

            if config.LOGIN['enabled'] and \
                    not current_user.has_groups(auth_groups):
                # TODO rase exception here
                return no_permission()

            return func(*args, **kwargs)
Beispiel #6
0
    def _get_modify_permission(cls, banner_id):
        banner = banner_client.get(banner_id)
        if not banner:
            raise_user_exc(BANNER_NOT_EXISTS_ERR, banner_id=banner_id)

        banner_regions = banner.regions
        if not banner_regions or not banner_regions.keys():
            return True

        banner_city_ids = banner_regions.keys()

        if current_user.has_groups(['activity_manager', 'marketing_manager']):
            return True
        elif current_user.has_groups(['city_director']):
            user_city_ids = city_base.get_city_ids_by_user()
            return all([banner_city_id in user_city_ids
                        for banner_city_id in banner_city_ids])

        return False
Beispiel #7
0
        def wrapper(*args, **kwargs):

            # If authentication stuff is disabled, do nothing.
            if current_app.login_manager._login_disabled:
                return func(*args, **kwargs)

            # If the user is NOT authenticated, this user is unauthorized.
            elif not current_user.is_authenticated():
                return current_app.login_manager.unauthorized()

            # If the user authenticated, and the all flag is set, we need to
            # see if the user is a member of *ALL* groups.
            if all and not current_user.has_groups(groups):
                return current_app.login_manager.unauthorized()

            # If the all flag is NOT set, we need to make sure the user is a
            # member of at least one group.
            elif not current_user.has_groups(groups, all=False):
                return current_app.login_manager.unauthorized()

            # Lastly, if the user has successfully passsed all authentication /
            # authorization challenges, we'll allow them in.
            return func(*args, **kwargs)
Beispiel #8
0
        def wrapper(self, *args, **kwargs):
            permission_key = permission_name
            if permission_name is None:
                permission_key = ':'.join(
                    [self.__class__.__name__, func.__name__])

            p_groups = permission_map.get(permission_key)

            is_permitted = False
            if 'superadmin' in p_groups and current_user.is_super_admin():
                is_permitted = True

            if not is_permitted:
                if p_groups is None:
                    return no_permission()

                if config.LOGIN['enabled'] and \
                        not current_user.has_groups(p_groups):
                    return no_permission()

            return func(self, *args, **kwargs)
Beispiel #9
0
def get_all_by_user_with_alphabet():
    """
    [GET] get all the cities by current-user
    return: first alphabet with city_id and city_name
        e.g. : {b:{1:北京, 12:北宁}, s:{2:上海}, ...}
    """
    city_query = thirdparty_svc.ers.TCityQuery()
    city_query.is_valid = True
    with thrift_client('ers') as ers_client:
        city_list = ers_client.query_city(city_query)

    # if not activity manager, find out his cities.
    if not current_user.has_groups(['activity_manager'],
                                   is_strict=False):
        city_list = filter(lambda city: city.id in (current_user.all_city_ids or []),
                           city_list)

    city_map = defaultdict(list)
    for city in city_list:
        alphabet = city.abbr[0].upper()
        city_map[alphabet].append({city.id: city.name})

    return dict(city_map)
Beispiel #10
0
def get_all_by_user_with_alphabet():
    """
    [GET] get all the cities by current-user
    return: first alphabet with city_id and city_name
        e.g. : {b:{1:北京, 12:北宁}, s:{2:上海}, ...}
    """
    city_query = thirdparty_svc.ers.TCityQuery()
    city_query.is_valid = True
    with thrift_client('ers') as ers_client:
        city_list = ers_client.query_city(city_query)

    # if not activity manager, find out his cities.
    if not current_user.has_groups(['activity_manager'], is_strict=False):
        city_list = filter(
            lambda city: city.id in (current_user.all_city_ids or []),
            city_list)

    city_map = defaultdict(list)
    for city in city_list:
        alphabet = city.abbr[0].upper()
        city_map[alphabet].append({city.id: city.name})

    return dict(city_map)