Esempio n. 1
0
def check_integrity():
    def _assert(exp):
        if exp:
            pass
        else:
            import pdb
            pdb.set_trace()

    for project in Project.objects(project_group=ProjectGroup.default()).all():
        print('checking.. {} users'.format(project.id))

        # project must have one owner
        _assert(
            ProjectUser.objects(project=project, is_owner=True).count() == 1)

        # project_user - project_group_user mappring
        for pu in ProjectUser.objects(project=project):
            print('checking.. {}'.format(pu))
            _assert(
                pu.project_group_user.project_group == project.project_group)
            _assert(pu.project_group_user.user == pu.user)

        print('checking.. {} orders'.format(project.id))
        if project.is_free:
            _assert(project.product == Product.default())
        else:
            _assert(project.product != Product.default())
Esempio n. 2
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))
Esempio n. 3
0
 def _available_member_cnt(self):
     from erks.models import ProjectUser, ProjectWaitingUserOutbound
     members_cnt = ProjectUser.objects(project=self).count()
     waiting_invited_members_cnt = ProjectWaitingUserOutbound.objects(
         project=self).count()
     return (self.product.member_cnt_limit - members_cnt -
             waiting_invited_members_cnt)
Esempio n. 4
0
def is_p_owner():
    return _context_user() is not None and \
        ProjectUser.objects(
            project=_context_project(),
            user=_context_user(),
            is_owner=True
    ).first() is not None
Esempio n. 5
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)
Esempio n. 6
0
def project_layout(project_id):
    from erks.models import ProjectUser
    pu = ProjectUser.objects(project=ObjectId(project_id),
                             user=current_user._get_current_object()).first()
    pu.project_layout = request.form.get('what', 'boxed')
    pu.save()
    return jsonify(ret='ok')
Esempio n. 7
0
    def invite(self, email, inviter):
        '''email로 초대하기 (외부 사용자를 포함해야 하므로 사용자객체 아님)
        여러가지 방향이 있었지만 현재는 invite의 경우 별도의 승인없이 무조건 편입한다.
        invite는 의지적인 행동이기 때문에 별다른 검증을 거치지 않는 것으로 process 수립

        todo: code is messy. please tide up.
        '''

        from erks.models import ProjectUser, ProjectWaitingUserOutbound
        logger.debug('inviting %s', email)
        pg = self.project_group

        if (self.get_grade(inviter) == self.ORGANIZER or
                self.allow_invitation_by_member) and \
                self.is_new_member_available():

            try:
                user = User.objects.get(email=email)
                pgu = pg.queryset_member.filter(user=user).first()
                if pgu:
                    try:
                        ProjectUser(project=self,
                                    user=user,
                                    project_group_user=pgu).save()
                        ret = True
                        logger.debug('inviting process for inbound-user(%s)' %
                                     email)
                    except NotUniqueError:
                        logger.warning('already registered project-member(%s)',
                                       email)
                        ret = False
                else:
                    logger.warning('user(%s)-does-not-in-project-group(%s).',
                                   email, pg)
                    ret = False
            except User.DoesNotExist:
                if pg.can_invite_oubound_user:
                    try:
                        invitee = ProjectWaitingUserOutbound(
                            project=self, user=email).save()
                        invitee.sendmail()
                        ret = True
                        logger.debug('inviting process for outbound-user(%s)' %
                                     email)
                    except NotUniqueError:
                        logger.warning('already registered outbound-user')
                        ret = False
                else:
                    logger.warning(
                        'outbound user(%s) cannot'
                        ' join project-group(%s).'
                        ' check the pref.', email, pg)
                    ret = False
        else:
            ret = False

        return ret
Esempio n. 8
0
 def leave(self, user):
     '''Project탈퇴는 MEMBER는 가능, OWNER는 불가능하다.
     탈퇴 성공여부를 True/False로 리턴'''
     from erks.models import ProjectUser
     entry = ProjectUser.objects(project=self, user=user,
                                 is_owner=False).first()
     if entry:
         entry.delete()
         return True
     else:
         return False
Esempio n. 9
0
 def my_belonged(cls, project_group=None):
     """current_user의 소속된 프로젝트 목록. 소유를 포함한다."""
     from erks.models import ProjectUser
     if project_group is None:
         project_group = ProjectGroup.default()
     user = current_user._get_current_object()
     project_group_user = ProjectGroupUser.objects(
         project_group=project_group, user=user).first()
     return ProjectUser.objects(project_group_user=project_group_user,
                                user=user).exclude('user',
                                                   'project_group_user')
Esempio n. 10
0
 def my_visit_log(cls, limit=4, skip=0, project_group=None):
     """방문한 프로젝트 목록"""
     from erks.models import ProjectUser
     if project_group is None:
         project_group = ProjectGroup.default()
     user = current_user._get_current_object()
     project_group_user = ProjectGroupUser.objects(
         project_group=project_group, user=user).first()
     return (entry.project for entry in ProjectUser.objects(
         project_group_user=project_group_user, user=user).only('project').
             order_by('-last_visited_at').skip(skip).limit(limit))
Esempio n. 11
0
def make_to_owner(project):
    from erks.models import ProjectUser
    if current_user and current_user.is_active:
        logger.debug('project_group_is_created and current_user_is_adding.')
        ProjectUser(project=project,
                    user=current_user._get_current_object(),
                    is_owner=True).save()
    else:
        logger.warning(
            'Not in the active-context, so cannot map the owner-project[%s]',
            project)
Esempio n. 12
0
def member_role_action(project_id):
    from erks.models import ProjectUser, ProjectUserBase
    what = request.form['action']
    if what == 'invite_member':
        user = User.objects.get_or_404(pk=request.form['user_id'])
        if g.project.invite(user.email, current_user._get_current_object()):
            project_user = ProjectUser.objects(project=g.project,
                                               user=user).get_or_404()
        else:
            project_user = user
    else:
        project_user = ProjectUserBase.objects.get_or_404(
            id=request.form['project_user_id'])

        if what == 'modeler_p':
            project_user.is_modeler = True
            project_user.save()
        elif what == 'termer_p':
            project_user.is_termer = True
            project_user.save()
        elif what == 'modeler_m':
            project_user.is_modeler = False
            project_user.save()
        elif what == 'termer_m':
            project_user.is_termer = False
            project_user.save()
        elif what == 'ban':
            project_user.delete()
            # return '<td>-</td><td colspan="6">{0} 사용자는 더 이상 프로젝트 소속이
            # 아닙니다.</td>'.format(project_user.user)
        elif what == 'approve':
            new_project_user = project_user.approve_and_get_new_project_user()
            if new_project_user:
                project_user = new_project_user
            else:
                # return '<td>-</td><td colspan="6">{0} 프로젝트의 최대 회원수를 초과하여 수락이 불가능합니다.</td>'.format(project_user.user.email)
                # flash_error(lazy_gettext(u'허용된 회원수를 초과하였습니다.'))
                pass
        elif what == 'reject':
            project_user.delete()
        elif what == 'resend':
            project_user.sendmail()
        elif what == 'cancel_invitation':
            project_user.delete()
            # return '<td>-</td><td colspan="6">{0} 사용자의 초대가
            # 취소되었습니다.</td>'.format(project_user.user)

    # return render_template(project_user.render_template_path,
    #                        project=g.project,
    #                        project_user=project_user)
    # import pdb; pdb.set_trace()
    import json
    return jsonify(json.loads(project_user.to_json()))
Esempio n. 13
0
 def context_glossary(self):
     from erks.models import ProjectUser, ProjectGroupUser
     pgu = ProjectGroupUser.objects(
         user=self, project_group=g.project_group).first()
     glossaries = []
     for pu in ProjectUser.objects(
             user=self, project_group_user=pgu, is_termer=True):
         if pu.can_manage_all_glossaries:
             glossaries.extend(pu.project.queryset_glossary.all())
         else:
             glossaries.extend(pu.manageable_glossaries)
     return glossaries
Esempio n. 14
0
    def my(cls, project_group=None):
        """current_user의 소유 프로젝트 목록."""
        from erks.models import ProjectUser
        if project_group is None:
            project_group = ProjectGroup.default()
        user = current_user._get_current_object()

        pgu = ProjectGroupUser.objects(project_group=project_group,
                                       user=user).first()
        return (entry.project for entry in ProjectUser.objects(
            project_group_user=pgu, user=user, is_owner=True).only(
                'project').all())
Esempio n. 15
0
def is_p_modeler(model_obj=None):
    q = (Q(project=_context_project()) & Q(user=_context_user())
         & Q(is_modeler=True))
    if model_obj == 'all':
        q = q & Q(can_manage_all_models=True)
    elif model_obj is None:
        pass
    else:
        q = q & (
            (Q(manageable_models=model_obj.root_object) if model_obj else True)
            | Q(can_manage_all_models=True))

    return _context_user() is not None and \
        ProjectUser.objects(q).first() is not None
Esempio n. 16
0
    def check_to_enter(self, user=None):
        from erks.models import (
            ProjectUser, )
        '''project에 입장할 수 있는지를 검사'''
        if self.demo:
            return True

        # TODO: 이게 맞나요?
        if not current_user.is_active:
            return False

        if user is None:
            user = current_user._get_current_object()

        is_member = ProjectUser.objects(
            project=self,
            user=user).only('id').no_dereference().first() is not None
        return not self.private or is_member
Esempio n. 17
0
def is_p_termer(glossary_obj=None):

    glossary = glossary_obj
    if not glossary:
        try:
            glossary = _context_glossary()
        except:  # noqa
            pass

    return _context_user() is not None and \
        ProjectUser.objects(
            Q(project=_context_project()) &
            Q(user=_context_user()) &
            Q(is_termer=True) &
            (
                Q(manageable_glossaries=glossary) |
                Q(can_manage_all_glossaries=True)
            )
    ).first() is not None
Esempio n. 18
0
 def queryset_project_user(self):
     from erks.models import ProjectUser
     return ProjectUser.objects(user=self)
Esempio n. 19
0
 def queryset_member(self):
     from erks.models import ProjectUser
     return ProjectUser.objects(project=self)
Esempio n. 20
0
def is_p_member():
    return _context_user() is not None and \
        ProjectUser.objects(
            project=_context_project(),
            user=_context_user()
    ).first() is not None