示例#1
0
def activate_iteration(context, request):
    docid = request.params.get('docid')
    if not docid:
        return view_iterations(context, request, validation_error=u'Missing document_id')

    #query = gdata.spreadsheet.service.CellQuery()

    #first take project names
    #query['min-col'] = '3'
    #query['max-col'] = '3'
    #query['min-row'] = '5'
    #cr_raw = get_cell_values(request, query)

    session = DBSession()

    #deactivate all CR
    #for cr in session.query(CustomerRequest):
    #    cr.active = False

    #activate selected CR
    #cr_ids = set([item for sublist in [a.split(',') for a in cr_raw] for item in sublist])
    #crs = session.query(CustomerRequest).filter(CustomerRequest.id.in_(cr_ids))
    #for cr in crs:
    #    cr.active = True

    gc = session.query(GlobalConfig).get(1)
    gc.active_iteration_url = docid

    return manage_iterations(context,request)
示例#2
0
def password_reset(request):
    email = request.params.get('email')
    try:
        session = DBSession()
        user = DBSession.query(User).filter_by(email=email).one()
        ptoken = DBSession.query(PasswordResetToken).get(user.id)
        if not ptoken:
            ptoken = PasswordResetToken(user_id=user.id)
        token = str(uuid4())
        ptoken.token = token 
        session.add(ptoken)
    except NoResultFound:
        token = None

    if token:
#        settings = request.registry.settings
        mailer = get_mailer(request)
        headers = {"header": u'Password reset',
                   "message": u'Please click on the link bellow to reset your penelope account\'s password.',
                   "link": '%s/change_password?token=%s' % (request.application_url, token),
                   "action": 'Reset password'}
        message = Message(subject=u"Password reset request",
                          recipients=[email],
                          body=u'Password reset',
                          extra_headers={'X-MC-Template': 'general',
                                         'X-MC-MergeVars': json.dumps(headers)})
        mailer.send(message)
    return {'request': request, 'token': token}
示例#3
0
def create_initial_application_acl(mapper, connection, target):
    if target.application_type == SVN:
        acl_rules = [
            ("internal_developer", "edit"),
            ("internal_developer", "view"),
            ("external_developer", "edit"),
            ("external_developer", "view"),
        ]
    else:
        acl_rules = [
            ("internal_developer", "view"),
            ("external_developer", "view"),
            ("secretary", "view"),
            ("secretary", "edit"),
        ]

    if target.application_type == "trac":
        acl_rules.append(("customer", "view"))

    for role_id, permission_name in acl_rules:
        acl = DBSession.query(ApplicationACL).get((target.id, role_id, permission_name))
        if not acl:
            acl = ApplicationACL(application_id=target.id, role_id=role_id, permission_name=permission_name)
            DBSession.add(acl)
        else:
            # XXX this should not happen.
            pass
示例#4
0
def get_user_by_email(request, email):
    """
    This method search for user using his email address
    """
    session = DBSession()
    if not isinstance(email, basestring):
        return {
                'status:': False,
                'message': u'Email parameter must be a string!',
                }
    try:
        user = session.query(User).filter_by(email=email).one()
    except orm_exc.NoResultFound:
        return {
                'status': False,
                'message': u'No user found in db for %s mail address' % email,
                }

    return {
            'status': True,
            'message': u'User found.',
            'email': user.email,
            'login': user.login,
            'openids': [x.openid for x in user.openids]
            }
示例#5
0
def get_user_by_openid(request, openid):
    """
    This method search for user using one of the possible user openids
    """
    session = DBSession()

    if not isinstance(openid, basestring):
        return {
                'status:': False,
                'message': u'Openid parameter must be a string!',
                }

    try:
        user = session.query(User).join('openids').filter_by(openid=openid).one()
    except orm_exc.NoResultFound:

        return {
                'status': False,
                'message': u'No user found in db for %s openid' % openid,
                }

    return {
            'status': True,
            'message': u'User found.',
            'email': user.email,
            'login': user.login,
            'openids': [x.openid for x in user.openids],
            }
示例#6
0
def get_project_by_name(request, project_name):
    """
    This method search for project by name
    """
    session = DBSession()

    if not isinstance(project_name, basestring):
        return {
                'status:': False,
                'message': u'Project name parameter must be a string!',
                }

    try:
        project = session.query(Project).filter_by(name=project_name).one()
    except orm_exc.NoResultFound:
        return {
                'status': False,
                'message': u'No project found in db for %s name' % project_name,
                }

    return {
            'status': True,
            'message': u'Project found.',
            'name': project.name,
            'id': project.id,
            'customer': project.customer.name,
            'applications': [x.name for x in project.applications],
            'customer_requests': [(x.id, x.name,) for x in project.customer_requests],
            }
示例#7
0
def get_customer_by_name(request, customer_name):
    """
    This method search for customer by name
    """
    session = DBSession()

    if not isinstance(customer_name, basestring):
        return {
                'status:': False,
                'message': u'Customer name parameter must be a string!',
                }

    try:
        customer = session.query(Customer).filter_by(name=customer_name).one()
    except orm_exc.NoResultFound:
        return {
                'status': False,
                'message': u'No customer found in db for %s name' % customer_name,
                }

    return {
            'status': True,
            'message': u'Customer found.',
            'name': customer.name,
            'projects': [x.name for x in customer.projects],
            }
示例#8
0
 def test_add_project(self):
     project_name = u'A project'
     session = DBSession()
     project = Project(name=project_name)
     session.add(project)
     transaction.commit()
     self.assertEqual(session.query(Project).filter_by(name=project_name).first().name, 'A project')
示例#9
0
 def test_add_application_with_sa_to_project(self):
     session = DBSession()
     project = Project(name=u'My project 1')
     application = Application(name=u'Trac')
     project.add_application(application)
     session.add(project)
     transaction.commit()
     self.assertEqual(session.query(Project).filter_by(name=u'My project 1').first().applications[0].name, u'Trac')
示例#10
0
 def test_project_creation_date(self):
     session = DBSession()
     project = Project(name=u'My first project A')
     session.add(project)
     transaction.commit()
     self.assertEqual(session.query(Project)\
                             .filter_by(name=u'My first project A')\
                             .first().creation_date.strftime('%Y%m%d'), datetime.now().strftime('%Y%m%d'))
示例#11
0
 def test_add_application_to_project(self):
     session = DBSession()
     project = Project(name=u'My project 2')
     application = Application(name=u'Trac', api_uri='http://simple.api.uri')
     project.add_application(application)
     session.add(project)
     transaction.commit()
     self.assertEqual(session.query(Project).filter_by(name=u'My project 2').first().applications[0].name, u'Trac')
示例#12
0
 def test_get_user_by_attribute(self):
     session = DBSession()
     user = User(email=u'*****@*****.**')
     session.add(user)
     transaction.commit()
     #Get the user by email
     resp = self.proxy.get_user_by_email('*****@*****.**')
     self.assertEqual(resp['email'], u'*****@*****.**')
示例#13
0
    def test_get_user_by_openid(self):
        session = DBSession()
        user = User(email=u'*****@*****.**')
        user.add_openid(u'*****@*****.**')
        session.add(user)
        transaction.commit()

        resp = self.proxy.get_user_by_openid('*****@*****.**')
        self.assertTrue(u'*****@*****.**' in resp['openids'])
示例#14
0
    def test_get_customer_by_name(self):
        customer_name = u'A rich customer'
        session = DBSession()
        customer = Customer(name=customer_name)
        session.add(customer)
        transaction.commit()

        resp = self.proxy.get_customer_by_name(customer_name)
        self.assertEqual(resp['name'], customer_name)
示例#15
0
def autoregister(profile):
    session = DBSession()
    chars = string.letters + string.digits
    password = ''.join(choice(chars) for _ in range(9))
    user = User(fullname = profile.get('displayName'),
                email = profile.get('emails')[0])
    user.set_password(password)
    user.add_openid(profile.get('accounts')[0].get('username'))
    session.add(user)
    return user
示例#16
0
    def smartadd_submit(self):
        """
        Receives a line of smart-add and performs validation/insertion.
        """
        projects = dict(
                ('%s - %s' % (p.name, p.customer.name), p.id)
                for p in self.request.filter_viewables(DBSession.query(Project).filter(Project.active))
                )

        def ticket_provider(project_id):
            if project_id:
                project = DBSession.query(Project).get(project_id)
                return [
                        t['id']
                        for t in ticket_store.get_tickets_for_project(project=project,
                                                                      not_invoiced=True,
                                                                      request=self.request)
                        ]

        parser = SmartAddParser(unicode(self.request.body, 'utf8', 'ignore'),
                                projects=projects,
                                available_tickets=ticket_provider,
                                request=self.request)

        errors = parser.validation_errors()
        if errors:
            # XXX register appropriate exception handler
            return Response(' - '.join(errors), status_int=400)

        pte = parser.parsed_time_entry
        parsed_tickets = pte['tickets']
        ticket_summaries = []

        entry_durations = list(time_chunks(pte['hours'], len(parsed_tickets)))

        for parsed_ticket, duration in zip(parsed_tickets, entry_durations):
            date = pte.get('date') or datetime.date.today()

            te = TimeEntry(date = date,
                           start = pte['start'],
                           end = pte['start'],
                           description = pte['description'],
                           ticket = parsed_ticket,
                           project_id = pte['project_id'],
                           hours = duration,
                           )
            te.request = self.request #bind for user calculation
            DBSession.add(te)
            # retrieve ticket descriptions (another trip to the store..)
            ticket_summaries.append(
                    '#%s (%s)' % (te.ticket, ticket_store.get_ticket(self.request, te.project_id, te.ticket)[3]['summary'])
                )

        return Response(u'Added to ticket(s) %s' % ', '.join(ticket_summaries))
示例#17
0
    def test_get_project_by_name(self):
        project_name = u'A nice project'
        customer_name = u'A good customer'
        session = DBSession()
        project = Project(name=project_name)
        customer = Customer(name=customer_name)
        customer.add_project(project)
        session.add(customer)
        transaction.commit()

        resp = self.proxy.get_project_by_name(project_name)
        self.assertEqual(resp['name'], project_name)
示例#18
0
 def test_password_set(self):
     email = u'*****@*****.**'
     self.add_user(email)
     session = DBSession()
     self.assertEqual(session.query(User).filter_by(email=email).one().password, None)
     token = self.generate_token(email)['token']
     from por.dashboard.security.views import change_password
     request = Request(method='POST', params={'token': token,
                                              'password': '******',
                                              'password_repeat': 'topsecret'})
     response = change_password(request)
     self.assertEqual(response.headers.get('Location'),'/login_form')
     self.assertNotEqual(session.query(User).filter_by(email=email).one().password, None)
示例#19
0
def timeentry_crstate_validation_errors(project_id, tickets, request):
    # XXX this check is deactivated for now (see #312)
    return []

    project = DBSession.query(Project).get(project_id)

    customer_requests = ticket_store.get_requests_from_tickets(project, tickets, request=request)

    for ticket_id, cr_id in customer_requests:
        cr = DBSession.query(CustomerRequest).get(cr_id)
        if cr.workflow_state != 'estimated':
            return ['Customer Request is not estimated']

    return []
示例#20
0
 def test_token_store_cleanup(self):
     email = u'*****@*****.**'
     self.add_user(email)
     self.generate_token(email)['token']
     token2 = self.generate_token(email)['token']
     session = DBSession()
     self.assertEqual(len(session.query(PasswordResetToken).join(User).filter(User.email == email).all()),1)
     from por.dashboard.security.views import change_password
     request = Request(method='POST', params={'token': token2,
                                              'password': '******',
                                              'password_repeat': 'topsecret'})
     response = change_password(request)
     self.assertEqual(response.headers.get('Location'),'/login_form')
     self.assertEqual(len(session.query(PasswordResetToken).join(User).filter(User.email == email).all()),0)
示例#21
0
 def test_project_modification_date(self):
     project_name = u'C project'
     session = DBSession()
     project = Project(name=project_name)
     session.add(project)
     transaction.commit()
     project = session.query(Project).filter_by(name=project_name).first()
     old_date = project.modification_date
     project.name = u'A modified project'
     time.sleep(0.1)
     transaction.commit()
     project = session.query(Project).filter_by(name=u'A modified project').first()
     new_date = project.modification_date
     self.assertNotEqual(old_date, new_date)
示例#22
0
    def render(self):
        result = {}
        result['main_template'] = get_renderer(
                'por.dashboard:skins/main_template.pt').implementation()
        result['main'] = get_renderer(
                'por.dashboard.forms:templates/master.pt').implementation()

        schema = WizardSchema().clone()
        wizard_fanstatic.need()
        form = WizardForm(schema,
                          formid='wizard',
                          method='POST',
                          buttons=[
                                 SubmitButton(title=u'Submit'),
                                 ResetButton(title=u'Reset'),
                          ])
        form['new_users'].widget = SequenceWidget()
        form['users'].widget = SequenceWidget(min_len=1)

        users = DBSession.query(User).order_by(User.fullname)
        form['users']['user']['usernames'].widget.values = [('', '')] + \
                                      [(str(u.id), u.fullname) for u in users]

        roles = DBSession.query(Role).order_by(Role.name)
        form['users']['user']['role'].widget.values = [('', '')] + \
                                 [(str(role.id), role.name) for role in roles]
        form['new_users']['new_user']['role'].widget.values = [('', '')] + \
                [(str(role.id), role.name) for role in roles]

        form['milestones'].widget = SequenceWidget(min_len=1)
        form['contracts'].title = ''
        form['contracts']['customer_requests'].widget = SequenceWidget(min_len=2)

        controls = self.request.POST.items()
        if controls != []:
            try:
                appstruct = form.validate(controls)
                self.handle_save(form, appstruct)
            except ValidationFailure as e:
                result['form'] = e.render()
                return result

        appstruct = {}
        appstruct['contracts'] ={'customer_requests': []}
        appstruct['contracts']['customer_requests'].append({'ticket': True,
                                                            'title': u'Analisi'})
        appstruct['contracts']['customer_requests'].append({'ticket': True,
                                                            'title': u'Supporto'})
        result['form'] = form.render(appstruct=appstruct)
        return result
示例#23
0
def report_index(context, request):
    users = DBSession.query(User).order_by(User.fullname)
    users = filter_users_with_timeentries(users)
    projects = sorted(request.filter_viewables(qry_active_projects()), key=unicodelower)
    customers = sorted(set(p.customer for p in projects), key=unicodelower)

    current_uid = request.authenticated_user.id
    saved_queries = DBSession.query(SavedQuery).filter(SavedQuery.author_id==current_uid)
    return {
            'users': users,
            'customers': customers,
            'projects': projects,
            'saved_queries': saved_queries.all()
            }
示例#24
0
    def security_save(self):
        context = self.context.get_instance()

        for acl in context.acl:
            DBSession.delete(acl)

        for checkbox_name in self.request.POST:
            role_id, permission_name = checkbox_name.split('.')
            acl = ApplicationACL(application_id=context.id,
                                 role_id=role_id,
                                 permission_name=permission_name)
            DBSession.add(acl)

        request = self.request
        return HTTPFound(location=request.fa_url(request.model_name, request.model_id, 'security'))
示例#25
0
def view_home(request):
    """
    Default home view
    """
    fanstatic_resources.dashboard_home.need()

    session = DBSession()
    user = request.authenticated_user
    projects = session.query(Project)

    active_projects = set(projects.filter(Project.active))

    my_projects = projects\
                  .filter(Project.users_favorite(user))\
                  .order_by(Project.customer_id).all()

    my_projects = request.filter_viewables(my_projects)
    other_active_projects = sorted(request.filter_viewables(active_projects.difference(my_projects)), key=unicodelower)

    boards = [
            {
                'title': 'Favorite projects',
                'custprojs': group_by_customer(my_projects),
            }
        ]

    listings = []

    max_board_projects = 20

    if not len(my_projects) and len(other_active_projects) < max_board_projects:
        boards.append({
                        'title': 'Active projects',
                        'custprojs': group_by_customer(other_active_projects),
                    })
    else:
        listing_columns = 4
        listings.append({
                        'title': 'Active projects',
                        'projgroups': tuple(chunks(tuple(other_active_projects), listing_columns)),
                    })

    return {
        'boards': boards,
        'listings': listings,
        'render_application_icon': render_application_icon,
        'get_application_link': get_application_link,
        }
示例#26
0
    def state_contract_change(self):
        new_state = self.request.POST['new_state']
        new_contract = self.request.POST['new_contract']
        invoice_number = self.request.POST['invoice_number']

        te_ids = set(int(s[3:])
                     for s, checkbox_state in self.request.POST.iteritems()
                     if s.startswith('te_') and checkbox_state=='on')

        qry = DBSession.query(TimeEntry).filter(TimeEntry.id.in_(te_ids))

        done_state = set()
        done_contract = set()
        errors = {}

        for te in qry:
            if new_state:
                try:
                    workflow = get_workflow(te, te.__class__.__name__)
                    workflow.transition_to_state(te, self.request, new_state, skip_same=True)
                    done_state.add(te.id)
                    if new_state == 'invoiced' and invoice_number:
                        te.invoice_number = invoice_number
                except WorkflowError as msg:
                    errors[te.id] = msg
            if new_contract:
                done_contract.add(te.id)
                te.contract_id = new_contract

        return done_state, done_contract, errors
示例#27
0
 def smartadd_projects(self):
     """
     Returns a json list of project tags
     """
     qry = self.request.filter_viewables(DBSession.query(Project).filter(Project.active))
     projects = sorted((u'%s - %s' % (p.name, p.customer.name) for p in qry), key=unicodelower)
     return projects
示例#28
0
def view_iterations(context, request, **params):
    session = DBSession()
    gc = session.query(GlobalConfig).get(1)
    docid = gc.active_iteration_url
    folder_iteration = get_iteration_folder(request)

    params.update({'context':context,
                   'doc_url': None,
                   'request':request})

    if folder_iteration and docid:
        log.info("Iteration folder found: %s" % folder_iteration.resource_id.text)
        document = request.gclient['DocsClient'].get_doc(docid)
        params.update({'doc_url': '%s&rm=minimal' % document.get_html_link().href})

    return SkinObject('view_iterations')(**params)
示例#29
0
def project_tree(context, request):
    """
    This view is used by the customer-project-request javascript filter.
    """
    all_projects = request.filter_viewables(DBSession.query(Project))

    all_projects = [
            project for project in request.filter_viewables(qry_active_projects())
            if request.has_permission('reports_all_entries_for_project', project)
            ]

    customers = request.filter_viewables(set(p.customer for p in all_projects if p.active))

    return [
            {
                'id': str(c.id),
                'name': c.name,
                'projects': [
                    {
                        'id': str(p.id),
                        'name': p.name,
                        'customer_requests': [
                            {
                                'id': str(cr.id),
                                'name': cr.name,
                                }
                            for cr in p.customer_requests
                            ],
                        }
                    for p in c.projects if p in all_projects
                    ]
                }
            for c in customers
            ]
示例#30
0
def latest_entries(context, request):
    """
    Returns an HTML fragment with tables of the latest time entries
    """

    qry = DBSession.query(TimeEntry)

    current_user = request.environ.get('repoze.who.identity')['user']
    qry = qry.filter(TimeEntry.author_id==current_user.id)

    qry = qry.order_by(sa.desc(TimeEntry.date), sa.desc(TimeEntry.start), sa.desc(TimeEntry.creation_date))
    time_entries_today = qry.filter(TimeEntry.date==datetime.date.today()).all()
    today_total = timedelta_as_human_str(sum([a.hours for a in time_entries_today], datetime.timedelta()))

    latest_limit = 20
    time_entries_latest = qry.limit(latest_limit)

    return {
            'context': context,
            'request': request,
            'time_entries_today': time_entries_today,
            'today_total': today_total,
            'time_entries_latest': time_entries_latest,
            'time_entries_latest_limit': latest_limit,
            'report_my_from_date': datetime.date.today() - datetime.timedelta(days=6),
            'today': datetime.date.today(),
            }