Example #1
0
def has_auth_obtain_poster(db: Session, user_id: int, poster_id: int):
    """
    是否有权限查看poster
    -> 卖家直接看不能公开部分
    -> #买家需要先评分才能看不能公开部分
    -> 公众能看公开,需要检查content是否已公开
    """
    result = False
    #---------
    m_poster = poster_usecase.obtain_simple(db, poster_id=poster_id)
    if m_poster is None:
        raise exception.NoExistPoster(poster_id)

    if m_poster.from_user_id == user_id:  # 卖家
        result = True

    elif m_poster.to_user_id == user_id:  # 买家
        # m_rate = rate_usecase.obtain_simple(
        #    db, order_no=m_poster.index_id)
        # if m_rate is not None:  # 已评分
        #    result = True
        result = True

    elif m_poster.content_visible == PublicVisible.Yes.value:  # 公众可见
        result = True

    else:
        pass
    #---------
    if not result:
        raise exception.MoretimeAuthorityException(
            where='has_auth_obtain_poster',
            which=str(poster_id),
            who=str(user_id))
Example #2
0
def has_auth_submit_reply(db: Session, user_id: int, poster_id: int):
    """
    这地方没改完,把具体逻辑移到这儿,别在其他地方实现
    是否有权限提交评论
    ->  只有卖家/家长可以评论 当role=False(非公众)
    -> 【预留】【公开状态】第三者可以评论
    -> 家长没回复之前不能卖家不能回复
    """
    result = False
    #---------
    m_poster = poster_usecase.obtain_simple(db, poster_id=poster_id)
    if m_poster is None:
        raise exception.NoExistPoster(poster_id)

    if user_id == m_poster.from_user_id:  # 卖家不能第一次评论
        reply_list = reply_usecase.obtain_simple(db, poster_id=poster_id)
        if reply_list is not None and reply_list != []:
            result = True

    elif user_id == m_poster.to_user_id:  # 买家直接评论
        result = True

    else:
        if m_poster.content_visible == PublicVisible.Yes.value:
            result = True
    #---------
    if not result:
        raise exception.MoretimeAuthorityException(
            where='has_auth_submit_reply',
            which=str(poster_id),
            who=str(user_id))
Example #3
0
def prepare_data(db: Session, req: DictObject) -> DictObject:
    """ """
    # 1. content
    content = common_usecase.clean_content(req.content)

    # 2. video
    video_id_list = video_usecase.videos_info_to_ids(db,
                                                     req.videos_info_private)
    video_sort = [idx.order_index for idx in req.videos_info_private] \
        if req.videos_info_private is not None else []

    # 3. picture
    picture_id_list = picture_usecase.pictures_info_to_ids(
        db, req.pictures_info_private)
    picture_sort = [idx.order_index for idx in req.pictures_info_private] \
        if req.pictures_info_private is not None else []

    # 4. parent_ids
    parent_ids = generate_parent_reply_id(db, req.prior_id)

    # 5. prepare sorting order
    sort_order = picture_sort + video_sort

    # 6. to_user_id
    if req.prior_id == ReplyToPoster.Prior.value:
        m_poster = poster_usecase.obtain_simple(db, poster_id=req.poster_id)

        if m_poster is None:
            raise exception.NoExistPoster(req.poster_id)
            #logworker.error(exception.NoExistPoster.error + " " + str(req.poster_id))

        to_user_id = m_poster.from_user_id  # 评论给poster的发布者

    else:
        m_reply = obtain.obtain_simple(db, reply_id=req.prior_id)

        if m_reply is None:
            raise exception.NoExistReply(req.prior_id)

        to_user_id = m_reply.from_user_id  # 评论给上一条reply的发布者

    # 7. packing
    data = DictObject(content=content,
                      video_id_list=video_id_list,
                      picture_id_list=picture_id_list,
                      sort_order=sort_order,
                      prior_id=req.prior_id,
                      parent_ids=parent_ids,
                      to_user_id=to_user_id)
    return data
Example #4
0
def has_auth_obtain_poster_public(db: Session, poster_id: int):
    """
    是否有权限查看poster
    -> 需要检查content是否已公开
    """
    result = False
    #---------
    m_poster = poster_usecase.obtain_simple(db, poster_id=poster_id)
    if m_poster is None:
        raise exception.NoExistPoster(poster_id)

    if m_poster.content_visible == PublicVisible.Yes.value:
        result = True
    #---------
    if not result:
        raise exception.MoretimeAuthorityException(
            where='has_auth_obtain_poster_public',
            which=str(poster_id),
            who='')
Example #5
0
def has_auth_change_visible(db, user_id: int, poster_id: int):
    """
    是否有权限改变poster可见性
    -> 家长能改变可见性
    """
    result = False
    #---------
    m_poster = poster_usecase.obtain_simple(db, poster_id=poster_id)

    if m_poster is None:
        raise exception.NoExistPoster(poster_id)

    if m_poster.to_user_id == user_id:
        result = True
    #---------
    if not result:
        raise exception.MoretimeAuthorityException(
            where='has_auth_change_visible',
            which=str(poster_id),
            who=str(user_id))
Example #6
0
def visible(db: Session, poster_id: int, is_content: bool, new_visible: int):
    """ """
    # is_content: 是否是更改content_visible字段 --  true: 是,false: 不是

    # 1. check authority
    auth_usecase.has_authority(db, 'change_visible', poster_id)

    # 2. get basic
    m_poster = obtain.obtain_simple(db, poster_id=poster_id)
    if m_poster is None:
        raise exception.NoExistPoster(poster_id)

    # 3. update content || update picvid
    if is_content == VisiblePart.Content.value:

        org_visible = m_poster.content_visible
        update_content_visible(db, m_poster, org_visible, new_visible)

    else:
        org_visible = m_poster.picvid_visible
        update_picvid_visible(db, m_poster, org_visible, new_visible)
Example #7
0
def has_auth_obtain_reply(db: Session, user_id: int, reply_id: int):
    """
    是否有权限查看这条评论
    -> 是否是卖家/买家  还是 公众
    -> poster属于公开状态
    """
    result = False
    #---------
    m_reply = reply_usecase.obtain_simple(db, reply_id=reply_id)
    if m_reply is None:
        raise exception.NoExistReply(reply_id)

    m_poster = poster_usecase.obtain_simple(db, poster_id=m_reply.poster_id)
    if m_poster is None:
        raise exception.NoExistPoster(m_reply.poster_id)

    result = visible_usecase.check_visible(m_poster, role=True, content=True)
    #---------
    if not result:
        raise exception.MoretimeAuthorityException(
            where='has_auth_obtain_reply',
            which=str(reply_id),
            who=str(user_id))
Example #8
0
def obtain_by_id(
        db: Session,
        poster_id: int, visible_choose: int=None)->Dict:
    """ 通过poster的id来找到并包装poster
        0. basic information
        1. child_nickname & start_ts
        2. 
    """
    # 0. basic information
    m_poster = obtain_simple(db, poster_id=poster_id)
    if m_poster is None:
        raise exception.NoExistPoster(poster_id)

    # 1. child_nickname
    m_order = order_usecase.retrieve_order(db, m_poster.index_id)
    if m_order is None:
        raise exception.NoExistOrder(m_poster.index_id)
    child_nickname = m_order.child_nickname

    # 1. 订单时间
    m_timeshare = order_usecase.retrieve_timeshare(db, m_order.time_sharing_id)
    if m_timeshare is None:
        raise exception.NoExistTimeSharing(m_order.time_sharing_id)
    start_ts = m_timeshare.start_ts

    # 2. visible
    if visible_choose is None:
        visible_choose = visible_usecase.obtain_visible_choose(
            m_poster)

    # 3. packing video
    video_obj_list = video_usecase.video_ids_to_objs(
        db, m_poster, visible_choose)

    # 4. packing picture
    picture_obj_list = picture_usecase.picture_ids_to_objs(
        db, m_poster, visible_choose)

    # 5. sort media
    media_obj_list = []
    if m_poster.sort_order != '' or m_poster.sort_order is not None and (video_obj_list is not None or picture_obj_list is not None):

        order_list = [int(i) for i in m_poster.sort_order.split(',')] \
            if m_poster.sort_order is not None and m_poster.sort_order != '' else []

        media_obj_list = common_usecase.prepare_sort_object(
            order_list, picture_obj_list, video_obj_list)

    # 6. user 头像信息
    user = user_usecase.obtain_user(db, m_poster.from_user_id)
    if user is None:
        raise exception.NoExistUser(m_poster.from_user_id)

    # 7. 评分
    rate = MoretimeRate.Default.value
    m_rate = rate_orm.find_rate_by_order_no(db, m_poster.index_id)
    if m_rate is not None:
        rate = m_rate.rate

    # 8. packing poster
    poster = packing(m_poster, child_nickname, start_ts,
                     media_obj_list, user, rate)

    return poster