Beispiel #1
0
def delegate_owner(project_id):

    form = DelegateProjectOwnerForm(request.form)
    if request.method == 'POST' and form.validate():

        from erks.models import ProjectUser
        user = User.objects.get(email=form.target_user_email.data)
        entry = ProjectUser.objects(project=g.project, user=user).first()
        entry.is_owner = True
        entry.save()

        user = current_user._get_current_object()
        entry = ProjectUser.objects(project=g.project, user=user).first()
        entry.is_owner = False
        entry.save()

        flash_success(gettext(u'소유자 이관이 완료되었습니다.'))
        return redirect(url_for('.index', project_id=project_id))

    else:
        if form.errors.get('target_user_email'):
            flash_error(form.errors['target_user_email'][0])
        else:
            flash_error(gettext(u'소유자 이관이 실패했습니다.'))

        # return redirect_back(url_for('.preference', project_id=project_id))
        return redirect(
            request.args.get('next') or request.referrer
            or url_for('.preference', project_id=project_id))
Beispiel #2
0
def _subscribe(project_id):
    from erks.models import ProjectUserReportSubscription

    project = Project.objects.get_or_404(id=project_id)
    pu = ProjectUserReportSubscription.objects(
        project=project, user=current_user._get_current_object()).first()
    if pu is None:
        pu = ProjectUserReportSubscription(
            project=project, user=current_user._get_current_object())

    if request.method == 'POST':
        form = ProjectSubscribeForm(request.form)
        form.populate_obj(pu)
        if any([
                pu.subscribed_report_model_glossary,
                pu.subscribed_report_model_schema,
                pu.subscribed_report_model_change
        ]):
            pu.save()
        elif pu.id:
            pu.delete()
        flash_success(gettext(u'저장되었습니다.'))
    else:
        form = ProjectSubscribeForm(obj=pu)

    return render_template(
        'project/_subscribe.htm.j2',
        form=form,
        subscription_cnt=ProjectUserReportSubscription.objects(
            project=project).count(),
        project=project)
Beispiel #3
0
def _post_modify(post_id):

    post = Post.objects.get_or_404(id=post_id)

    if not (post.writer == current_user._get_current_object()):
        flash_error(lazy_gettext(u'권한이 없습니다.'))
        return redirect(url_for('._post_view', post_id=post_id))

    if request.method == 'POST':
        form = BoardForm(request.form)
        if form.validate():
            form.populate_obj(post)

            # filedata = request.files["tmp_file"]
            # if (filedata is not None) or \
            #         (filedata is None and post.filename != ''):
            #     post.file = filedata
            #     # .encode('utf8')  # python3compatible
            #     post.filename = filedata.filename
            post.save()
            flash_success(lazy_gettext(u'게시글이 수정되었습니다'))
            return redirect(url_for(
                '._post_view',
                post_id=post.id))
    else:
        form = BoardForm(obj=post)

    return render_template(
        'board/_post_write.htm.j2',
        action_url=url_for('board._post_modify', post_id=post_id),
        project=g.project,
        form=form)
Beispiel #4
0
def index(project_id):

    project = Project.objects.get_or_404(id=project_id)

    # 이 화면은 비로그인 사용자도 프로젝트 설정에 따라 볼 수 있으므로
    # current_user체크를 해주어야 함
    # project.write_visit_log(current_user._get_current_object())
    # project권한체크시에 넣어줄수도 있지만 굳이 성능이슈를 야기할 필요는 없으므로
    # index에서만 방문일을 갱신
    if current_user and current_user.is_active:
        from erks.models import ProjectUser
        puser = ProjectUser.objects(
            project=project, user=current_user._get_current_object()).first()
        if puser:
            puser.visit()

    flash_success('helloworld[category-success]')
    flash_error('helloworld[category-error]')
    flash_info('helloworld[category-info]')
    flash_warning('helloworld[category-warning]')

    # if project.project_group.has_theme():
    #     return render_template(
    #         'theme/{theme_key}/project/index_{theme_key}.html'.format(theme_key=project.project_group.theme_key),
    #         project=project,
    #         portlet_summary_model=Portlet('._summary_model', project_id=project_id),
    #         portlet_summary_glossary=Portlet('._summary_glossary', project_id=project_id),
    #         portlet_subjectarea_recently_changed=Portlet('._subjectarea_recently_changed', project_id=project_id),
    #         portlet_summary_board=Portlet('._summary_board', project_id=project_id),
    #     )
    # else:
    return render_template('project/community.htm.j2', project=project)
Beispiel #5
0
def user_leave(project_user_id):
    pu = ProjectUser.objects.get_or_404(id=project_user_id)
    pu.delete()
    flash_success(
        gettext(u'%(user_email)s 사용자는 더 이상 프로젝트의 구성원이 아닙니다.',
                user_email=pu.user_email))
    return redirect(url_for('project.members', project_id=pu.project.id))
Beispiel #6
0
def _report_subscription(slug='default'):
    # pgu = current_user.queryset_project_group_user(project_group=g.project_group).first()
    project_user_objs = list(
        current_user.queryset_project_user_report_subscription)

    if request.method == 'POST':
        '''on처리한 project-user데이터만 들어온다.
        전부 끄고, 데이터기준으로 on한다.'''
        for subscription in project_user_objs:
            wanted = request.form.getlist(str(subscription.id))
            subscription.subscribed_report_model_glossary = 'model_glossary' in wanted
            subscription.subscribed_report_model_schema = 'model_schema' in wanted
            subscription.subscribed_report_model_change = 'model_change' in wanted
            # current_app.logger.debug(f'{subscription.subscribed_report_model_glossary}')
            if any([
                    subscription.subscribed_report_model_glossary,
                    subscription.subscribed_report_model_schema,
                    subscription.subscribed_report_model_change
            ]):
                subscription.save()
            elif subscription.id:
                subscription.delete()
        flash_success(gettext('정상적으로 처리되었습니다.'))

        # reload (삭제된것은 지우기)
        project_user_objs = list(
            current_user.queryset_project_user_report_subscription)

    return render_template(
        '_report_subscription.htm.j2',
        project_user_objs=project_user_objs,
        slug=slug,
    )
Beispiel #7
0
def user_leave(project_group_user_id):
    pgu = ProjectGroupUser.objects.get_or_404(id=project_group_user_id)
    # 권한체크
    project_group_current_user = pgu.project_group.queryset_project_group_user.get(
        user=current_user._get_current_object())
    if project_group_current_user.is_moderator or project_group_current_user.is_owner:
        pgu.delete()
        flash_success(gettext(u'%(user_email)s 사용자는 더 이상 프로젝트그룹의 구성원이 아닙니다.', user_email=pgu.user_email))
        return redirect(url_for(
            'project_group.preference_members',
            slug=pgu.project_group.slug))
    else:
        abort(403)  # forbidden
Beispiel #8
0
def convert_to_free(project_id):
    project = g.project

    if not project.is_expired:
        flash_warning(lazy_gettext(u'아직 전환할 수 있는 시기가 아닙니다.'))
    elif project.available_to_convert_free_project():
        project.convert_free_project()
        flash_success(
            lazy_gettext(u'이용해주셔서 감사합니다. '
                         u'무료프로젝트로 전환되어 계속 사용하실 수 있습니다.'))
    else:
        flash_error(lazy_gettext(u'이미 무료프로젝트가 존재합니다.'))

    return redirect(url_for('project.index', project_id=project.id))
Beispiel #9
0
def _user_role_changer(project_group_user_id):
    pgu = ProjectGroupUser.objects.get_or_404(id=project_group_user_id)
    if request.method == 'POST':
        form = ProjectGroupUserRoleForm(request.form)
        if form.validate():
            flash_success(gettext('정상적으로 처리되었습니다.'))
            form.populate_obj(pgu)
            pgu.save()
    else:
        form = ProjectGroupUserRoleForm(obj=pgu)

    return render_template(
        'project_group/_role_changer.html',
        form=form,
        project_group_user=pgu)
Beispiel #10
0
def _post_delete(post_id):

    post = Post.objects.get_or_404(id=post_id)

    if not (post.writer == current_user._get_current_object()):
        flash_error(lazy_gettext(u'권한이 없습니다.'))
        return redirect(url_for('._post_view', post_id=post_id))
    else:
        post.use_yn = False
        post.save()
        flash_success(lazy_gettext(u'게시글이 삭제되었습니다'))
        if isinstance(post, ProjectPost):
            return redirect(url_for('._posts', project_id=g.project.id))
        else:
            return redirect(url_for('._notice_view', post_id=post_id))
Beispiel #11
0
def _user_role_changer(project_user_id):
    pu = ProjectUser.objects.get_or_404(id=project_user_id)
    if request.method == 'POST':
        form = ProjectUserRoleForm(request.form)
        if form.validate():
            # import pdb; pdb.set_trace()
            form.populate_obj(pu)
            pu.save()
            flash_success(lazy_gettext(u'성공적으로 저장되었습니다.'))
    else:
        form = ProjectUserRoleForm(obj=pu)

    return render_template('project/_role_changer.htm.j2',
                           form=form,
                           project_user=pu)
Beispiel #12
0
def _preference(project_id):
    project = Project.objects.get_or_404(id=project_id)
    if request.method == 'POST':
        form = ProjectEditForm(request.form)
        if form.validate():
            form.populate_obj(project)
            project.save()
            flash_success(lazy_gettext(u'프로젝트 설정이 저장되었습니다'))
    else:
        form = ProjectEditForm(obj=project)

    return render_template(
        'project/_preference.htm.j2',
        form=form,
        project_delete_form=ProjectDeleteForm(obj=project),
        project_owner_delegate_form=DelegateProjectOwnerForm(),
        project=project)
Beispiel #13
0
def join_request(project_id):
    """사용자의 가입요청"""

    project = Project.objects.get_or_404(id=project_id)
    form = RequestMemberForm(request.form)

    if request.method == 'POST' and form.validate():
        if current_user in project.members:
            flash_warning(lazy_gettext(u'이미 등록된 사용자입니다.'))
        elif current_user in project.waiting_requested_members:
            flash_warning(lazy_gettext(u'관리자의 승인을 기다리고 있는 사용자입니다.'))
        else:
            request_message = form.request_message.data or u''
            project.request_to_join(current_user._get_current_object(),
                                    request_message)
            flash_success(lazy_gettext(u'요청되었습니다. 관리자 승인 후 사용 가능합니다.'))

    return redirect(
        request.args.get('next') or request.referrer
        or url_for('.index', project_id=project_id))
Beispiel #14
0
def _profile_edit():
    from erks.erks_bps.project.models import ProjectGroup
    user = current_user._get_current_object()
    form = ProfileEditForm(request.form, obj=user)

    # choices = [('', 'default'), ]
    # choices.extend([(str(g.id), g.title) for g in ProjectGroup.my()])
    choices = [(str(g.id), g.title) for g in ProjectGroup.my()]
    form.default_project_group_id.choices = choices

    if request.method == 'POST':
        if form.validate():
            form.populate_obj(user)
            user.save()
            flash_success(lazy_gettext(u'사용자 정보가 변경되었습니다.'))
            return redirect(url_for('login._profile'))
        else:
            current_app.logger.warning(form.errors)

    return render_template('login/_profile_edit.htm.j2', form=form)
Beispiel #15
0
def create_project(slug='default'):

    project_create_form = ProjectCreateForm(request.form)

    project_group = ProjectGroup.objects.get_or_404(slug=slug)
    project_create_form.project_group.data = project_group

    d = {}
    d['form'] = project_create_form
    d['project_group'] = project_group
    # if project_group.is_not_default:
    #     grade = project_group.get_grade(current_user._get_current_object())
    #     if not project_group.ban_create_project or grade in ('owner', 'manager'):
    #         pass
    #     else:
    #         flash_warning(gettext(u'신규 프로젝트 생성 제한 설정중입니다. 그룹관리자에게 문의해주세요.'))
    #         return redirect(url_for('project_group.index', slug=slug))

    # if not current_user.can_make_project_for(project_group):
    #     flash_warning(lazy_gettext(u'더 이상 무료 프로젝트를 생성할 수 없습니다.'))
    #     if current_app.config['BILLING']:
    #         return redirect(url_for('portal.services'))
    #     else:
    #         return redirect(url_for('portal.index'))

    if request.method == 'POST':
        if project_create_form.validate():
            # del project_create_form.subscription_months
            # del project_create_form.billed
            flash_success(gettext(u'프로젝트가 생성되었습니다.'))
            prj = project_create_form.save(commit=False)
            prj.visible = True
            prj.save()
            return redirect(url_for('project.index', project_id=prj.id))
        else:
            flash_error(gettext('프로젝트 생성에 실패했습니다.'))
            return redirect(url_for('portal.index'))
    return render_template('portal/project_create.htm.j2', **d)
Beispiel #16
0
def _invite(project_id):

    if request.method == 'POST':
        form = InviteMemberForm(request.form)
        project = g.project
        project_group = g.project_group

        if form.validate():
            count_emails = form.count_invitations()
            if count_emails > 20:
                return jsonify(ret=False,
                               message=gettext(u'초대는 최대 20명까지 처리가능합니다.')), 500
            elif not project.is_new_member_available(
                    new_member_cnt=count_emails):
                return jsonify(
                    ret=False,
                    message=gettext(u'허용된 회원 수를 초과하여 초대할 수 없습니다.')), 500

            receivers = form.review_invitations()

            # 초대시작
            ret_ok = Counter([
                project.invite(r['user_email'],
                               inviter=current_user._get_current_object())
                for r in receivers if r['ok']
            ])
            ret_ok_count = ret_ok.get(True, 0)

            # outbound초대시작
            if project_group.can_invite_oubound_user:
                ret_email = Counter([
                    project.invite(r['user_email'],
                                   inviter=current_user._get_current_object())
                    for r in receivers if r['user'] is None
                ])
                ret_ok_count += ret_email.get(True, 0)

            if ret_ok_count:
                # return jsonify(
                #     ret=True,
                #     message=lazy_gettext(
                #         u'감사합니다. '
                #         u'%(ret_ok_count)d명의 사용자가 초대되었습니다.',
                #         ret_ok_count=ret_ok_count))
                flash_success(
                    gettext(u'%(ret_ok_count)d명의 사용자가 초대되었습니다.',
                            ret_ok_count=ret_ok_count))
                return redirect(url_for('._invite', project_id=project_id))
            else:
                # return jsonify(
                #     ret=False,
                #     message=gettext(u'사용자 초대가 실패했습니다.')), 500
                flash_error(gettext(u'사용자 초대가 실패했습니다.'))
        else:
            # import pdb; pdb.set_trace()
            # return jsonify(
            #     ret=False,
            #     message=lazy_gettext(u'잘못된 폼 요청입니다.')), 400
            flash_error(gettext(u'잘못된 폼 요청입니다.'))
    else:
        form = InviteMemberForm()

    return render_template('project/_invite.htm.j2',
                           project=g.project,
                           form=form)