예제 #1
0
파일: query.py 프로젝트: weko3-dev35/weko
def get_permission_filter(comm_id=None):
    """Get permission filter."""
    # check permission
    is_perm = search_permission.can()
    match = Q('match', publish_status='0')
    version = Q('match', relation_version_is_last='true')
    rng = Q('range', **{'publish_date': {'lte': 'now/d'}})
    term_list = []
    mst = []
    is_perm_paths = Indexes.get_browsing_tree_paths()
    search_type = request.values.get('search_type')

    if comm_id:
        if search_type == config.WEKO_SEARCH_TYPE_DICT['FULL_TEXT']:
            self_path = Indexes.get_self_path(comm_id)
            if self_path and self_path.path in is_perm_paths:
                term_list.append(self_path.path)

            path = term_list[0] + '*'
            should_path = []
            wildcard_path = Q("wildcard", path=path)
            should_path.append(wildcard_path)

            mst.append(match)
            mst.append(rng)
            terms = Q('bool', should=should_path)
        else:  # In case search_type is keyword or index
            self_path = Indexes.get_self_path(comm_id)
            if self_path and self_path.path in is_perm_paths:
                term_list.append(self_path.path)

            mst.append(match)
            mst.append(rng)
            terms = Q('terms', path=term_list)
    else:
        mst.append(match)
        mst.append(rng)
        terms = Q('terms', path=is_perm_paths)

    mut = []
    if is_perm:
        user_id, result = check_admin_user()
        if result:
            shuld = [
                Q('match', weko_creator_id=user_id),
                Q('match', weko_shared_id=user_id)
            ]
            shuld.append(Q('bool', must=mst))
            mut.append(Q('bool', should=shuld, must=[terms]))
            mut.append(Q('bool', must=version))
    else:
        mut = mst
        mut.append(terms)
        base_mut = [match, version]
        mut.append(Q('bool', must=base_mut))

    return mut
예제 #2
0
파일: query.py 프로젝트: weko3-dev15/weko
def get_index_filter():

    paths = Indexes.get_browsing_tree_paths()
    mst = []
    q_list = []
    for path in paths:
        match_q = Q('match', path=path)
        q_list.append(match_q)
    mst.append(Q('bool', should=q_list))

    return mst
예제 #3
0
파일: query.py 프로젝트: mhaya/weko
def get_permission_filter(comm_id=None):
    """Get permission filter."""
    # check permission
    is_perm = search_permission.can()
    match = Q('match', publish_status='0')
    version = Q('match', relation_version_is_last='true')
    rng = Q('range', **{'publish_date': {'lte': 'now/d'}})
    term_list = []
    mst = []
    is_perm_paths = Indexes.get_browsing_tree_paths()
    if comm_id is not None:
        self_path = Indexes.get_self_path(comm_id)
        if self_path.path in is_perm_paths:
            term_list.append(self_path.path)

        mst.append(match)
        mst.append(rng)
        terms = Q('terms', path=term_list)
    else:
        mst.append(match)
        mst.append(rng)
        terms = Q('terms', path=is_perm_paths)

    mut = []
    if is_perm:
        user_id, result = check_admin_user()
        if result:
            shuld = [
                Q('match', weko_creator_id=user_id),
                Q('match', weko_shared_id=user_id)
            ]
            shuld.append(Q('bool', must=mst))
            mut.append(Q('bool', should=shuld, must=[terms]))
            mut.append(Q('bool', must=version))
    else:
        mut = mst
        mut.append(terms)
        base_mut = [match, version]
        mut.append(Q('bool', must=base_mut))

    return mut