Beispiel #1
0
 def dispatch(self):
     form = ClientAddForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         coordinator_id = int(form.coordinator_id.data) if form.coordinator_id.data.isdigit() else None
         client = Client(
             name=form.name.data,
             google_card=form.google_card.data,
             google_wiki=form.google_wiki.data,
             color=form.color.data,
             selector=form.selector.data,
             emails=form.emails.data,
             coordinator_id=coordinator_id,
             street=form.street.data,
             city=form.city.data,
             postcode=form.postcode.data,
             nip=form.nip.data,
             note=form.note.data,
             wiki_url=form.wiki_url.data,
             mailing_url=form.mailing_url.data
         )
         DBSession.add(client)
         DBSession.flush()
         self.flash(self._(u"New client added"))
         LOG(u"Client added")
         return HTTPFound(location=self.request.url_for("/client/view", client_id=client.id))
     return dict(form=form)
Beispiel #2
0
 def dispatch(self):
     form = SprintForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         project = Project.query.get(int(form.project_id.data))
         sprint = Sprint(
             name=form.name.data,
             client_id=project.client_id,
             project_id=project.id,
             team_id=form.team_id.data or None,
             bugs_project_ids = map(int, form.bugs_project_ids.data),
             start=form.start.data,
             end=form.end.data,
             board=form.board.data,
             goal=form.goal.data,
             retrospective_note = form.retrospective_note.data,
         )
         DBSession.add(sprint)
         DBSession.flush()
         self.flash(self._(u"New sprint added"))
         LOG(u"Sprint added")
         url = self.request.url_for('/scrum/sprint/show', sprint_id=sprint.id)
         return HTTPFound(location=url)
     return dict(
         form=form,
     )
Beispiel #3
0
 def dispatch(self):
     client_id = self.request.GET.get('client_id')
     client = Client.query.get(client_id)
     form = ProjectForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         tracker_id = form.tracker_id.data
         coordinator_id = int(form.coordinator_id.data) if form.coordinator_id.data.isdigit() else None
         project = Project(
             client=client,
             name=form.name.data,
             coordinator_id=coordinator_id,
             tracker_id=tracker_id,
             turn_off_selectors=form.turn_off_selectors.data,
             project_selector=form.project_selector.data,
             component_selector=form.component_selector.data,
             version_selector=form.version_selector.data,
             ticket_id_selector=form.ticket_id_selector.data,
             active=form.active.data,
             google_card=form.google_card.data,
             google_wiki=form.google_wiki.data,
             mailing_url=form.mailing_url.data,
             working_agreement=form.working_agreement.data,
             definition_of_done=form.definition_of_done.data,
             definition_of_ready=form.definition_of_ready.data,
             continuous_integration_url=form.continuous_integration_url.data,
             backlog_url=form.backlog_url.data,
             status = form.status.data,
         )
         DBSession.add(project)
         DBSession.flush()
         self.flash(self._(u"Project added"))
         LOG(u"Project added")
         SelectorMapping.invalidate_for(tracker_id)
         return HTTPFound(location=self.request.url_for('/client/view', client_id=project.client_id))
     return dict(client=client, form=form)
Beispiel #4
0
 def dispatch(self):
     client_id = self.request.GET.get('client_id')
     client = Client.query.get(client_id)
     form = ProjectForm(self.request.POST)
     if self.request.method == 'POST' and form.validate():
         tracker_id = form.tracker_id.data
         coordinator_id = int(
             form.coordinator_id.data) if form.coordinator_id.data.isdigit(
             ) else None
         project = Project(
             client=client,
             name=form.name.data,
             coordinator_id=coordinator_id,
             tracker_id=tracker_id,
             turn_off_selectors=form.turn_off_selectors.data,
             project_selector=form.project_selector.data,
             component_selector=form.component_selector.data,
             version_selector=form.version_selector.data,
             ticket_id_selector=form.ticket_id_selector.data,
             active=form.active.data,
             google_card=form.google_card.data,
             google_wiki=form.google_wiki.data,
             mailing_url=form.mailing_url.data,
             working_agreement=form.working_agreement.data,
             definition_of_done=form.definition_of_done.data,
             definition_of_ready=form.definition_of_ready.data,
             continuous_integration_url=form.continuous_integration_url.
             data,
             backlog_url=form.backlog_url.data,
             status=form.status.data,
         )
         DBSession.add(project)
         DBSession.flush()
         self.flash(self._(u"Project added"))
         LOG(u"Project added")
         SelectorMapping.invalidate_for(tracker_id)
         return HTTPFound(location=self.request.url_for(
             '/client/view', client_id=project.client_id))
     return dict(client=client, form=form)
Beispiel #5
0
class Boards(ApiView):
    def get(self):
        boards = [board.to_dict() for board in DBSession.query(m.SprintBoard)]
        return dict(boards=boards)

    def post(self):
        json_board = self.request.json_body
        board_schema = BoardSchema()
        try:
            board = board_schema.deserialize(json_board)
        except colander.Invalid, e:
            errors = e.asdict()
            raise HTTPBadRequest(errors)

        board = m.SprintBoard(**board)
        board.user_id = self.request.user.id
        DBSession.add(board)

        try:
            DBSession.flush()
        except IntegrityError:
            raise HTTPBadRequest('Board exists')

        return dict(id=board.id, )
Beispiel #6
0
class Teams(ApiView):

    def get(self):
        def get_worked_hours(startDate, endDate, projects_ids):
            worked_hours = DBSession.query(
                TimeEntry.project_id,
                func.sum(TimeEntry.time)
            )
            return worked_hours\
                .filter(TimeEntry.project_id.in_(projects_ids))\
                .filter(TimeEntry.date >= startDate)\
                .filter(TimeEntry.date <= endDate)\
                .group_by(TimeEntry.project_id)

        def get_project_worked_hours(project_id, worked_hours):
            worked_hours = filter(lambda x: x[0] == project_id, worked_hours)
            return worked_hours[0][1] if worked_hours else 0.0

        tickets_end_date = datetime.now()
        tickets_start_date = tickets_end_date.replace(day=1)
        tickets_end_date = tickets_end_date.replace(day=1)
        tickets_end_date += relativedelta(months=1)
        tickets_end_date -= relativedelta(days=1)

        tickets_last_month_end_date = tickets_start_date - timedelta(days=1)
        tickets_last_month_start_date = tickets_last_month_end_date.replace(
                                                                    day=1)

        teams = DBSession.query(Team_m, TeamMember.user_id)\
                            .outerjoin(TeamMember)

        team_to_project = DBSession.query(Team_m.id, Project, Client)\
                                      .filter(Sprint.team_id==Team_m.id)\
                                      .filter(Sprint.project_id==Project.id)\
                                      .filter(Project.client_id==Client.id)\
                                      .order_by(Sprint.end.desc())

        teams = h.groupby(
            teams,
            lambda x: x[0],
            lambda x: x[1]
        )
        team_to_project = h.groupby(
            team_to_project,
            lambda x: x[0],
            lambda x: x[1:]
        )

        projects_ids = []
        for value in team_to_project.values():
            for projectAndClient in value:
                projects_ids.append(projectAndClient[0].id)

        this_month_worked_hours = get_worked_hours(
            tickets_start_date, tickets_end_date, projects_ids)

        last_month_worked_hours = get_worked_hours(
            tickets_last_month_start_date, tickets_start_date,
            projects_ids)

        result = []
        for team, members in teams.iteritems():
            team = team.to_dict()
            team['users'] = members
            projects = team_to_project.get(team['id'], [])
            team['projects'] = [
                dict(
                    id=project.id,
                    name=project.name,
                    client=dict(
                        id=client.id,
                        name=client.name,
                    ),
                    this_month_worked_hours=
                        get_project_worked_hours(project.id,
                            this_month_worked_hours),
                    last_month_worked_hours=
                        get_project_worked_hours(project.id,
                            last_month_worked_hours)
                ) for project, client in projects
            ]
            result.append(team)

        return dict(
            teams=result
        )

    @has_perm('can_edit_teams')
    def post(self):
        try:
            json_team = self.request.json_body
        except ValueError:
            raise HTTPBadRequest('Expect json')

        team_schema = TeamAddSchema()
        try:
            team_des = team_schema.deserialize(json_team)
        except colander.Invalid, e:
            errors = e.asdict()
            raise HTTPBadRequest(errors)

        team = Team_m(name=team_des['name'])
        DBSession.add(team)
        try:
            DBSession.flush()
        except IntegrityError:
            raise HTTPBadRequest('Team exists')

        if team_des.get('swap_with_preview'):
            preview = Preview(self.request)
            if not preview.swap_avatar(type='teams', id=team.id):
                raise HTTPBadRequest('No preview to swap')

        return team.to_dict()
Beispiel #7
0
def callback(request):
    code = request.params.get('code', '')
    try:
        credentials = flow.step2_exchange(code)
    except FlowExchangeError:
        raise HTTPForbidden
    data = requests.get(USER_INFO_URI % credentials.access_token, verify=False)
    google_profile = data.json()
    email = google_profile['email']

    EXTRA_EMAILS = request.registry.settings.get('GOOGLE_EXTRA_EMAILS', '')
    EXTRA_EMAILS = EXTRA_EMAILS.split('\n')
    config = ApplicationConfig.get_current_config(allow_empty=True)
    freelancers = config.get_freelancers()
    clients_emails = Client.get_emails()

    is_employee = (
        email.endswith('@%s' % request.registry.settings['COMPANY_DOMAIN']) or
        email in EXTRA_EMAILS
    )

    if is_employee:
        group = 'employee'
    elif email in freelancers:
        group = 'freelancer'
    elif email in clients_emails:
        group = 'client'
    else:
        WARN_LOG(u"Forbidden acccess for profile:\n%s\n client's emails:\n%s\nfreelancer's emails:\n%s" % (google_profile, clients_emails, freelancers))
        return HTTPForbidden()

    user = DBSession.query(User).filter(User.email==email).first()
    if user is not None:
        if credentials.refresh_token:
            DEBUG(u'Adding refresh token %s for user %s' % (
                credentials.refresh_token, user.name,
            ))
            user.refresh_token = credentials.refresh_token
            DBSession.add(user)
        DEBUG(u'Signing in existing user %s' % (user.name, ))
    else:
        LOG(u'Creating new user with name %s and email %s, group: %s' % (google_profile['name'], google_profile['email'], group))
        user = User(
            name=google_profile['name'],
            email=email,
            refresh_token=credentials.refresh_token or '',
            groups=[group],
            roles=[],
        )

        DBSession.add(user)
        DBSession.flush()
    headers = remember(request, user.id)
    DEBUG(u'User %s set' % user.name)
    if group == 'client':
        location = request.url_for('/scrum/sprint/list')
    else:
        location = '/'
    return HTTPFound(
        location=location,
        headers=headers,
    )
Beispiel #8
0
def callback(request):
    code = request.params.get('code', '')
    try:
        credentials = flow.step2_exchange(code)
    except FlowExchangeError:
        raise HTTPForbidden
    data = requests.get(USER_INFO_URI % credentials.access_token, verify=False)
    google_profile = data.json()
    email = google_profile['email']

    EXTRA_EMAILS = request.registry.settings.get('GOOGLE_EXTRA_EMAILS', '')
    EXTRA_EMAILS = EXTRA_EMAILS.split('\n')
    config = ApplicationConfig.get_current_config(allow_empty=True)
    freelancers = config.get_freelancers()
    clients_emails = Client.get_emails()

    is_employee = (email.endswith(
        '@%s' % request.registry.settings['COMPANY_DOMAIN'])
                   or email in EXTRA_EMAILS)

    if is_employee:
        group = 'employee'
    elif email in freelancers:
        group = 'freelancer'
    elif email in clients_emails:
        group = 'client'
    else:
        WARN_LOG(
            u"Forbidden acccess for profile:\n%s\n client's emails:\n%s\nfreelancer's emails:\n%s"
            % (google_profile, clients_emails, freelancers))
        return HTTPForbidden()

    user = DBSession.query(User).filter(User.email == email).first()
    if user is not None:
        if credentials.refresh_token:
            DEBUG(u'Adding refresh token %s for user %s' % (
                credentials.refresh_token,
                user.name,
            ))
            user.refresh_token = credentials.refresh_token
            DBSession.add(user)
        DEBUG(u'Signing in existing user %s' % (user.name, ))
    else:
        LOG(u'Creating new user with name %s and email %s, group: %s' %
            (google_profile['name'], google_profile['email'], group))
        user = User(
            name=google_profile['name'],
            email=email,
            refresh_token=credentials.refresh_token or '',
            groups=[group],
            roles=[],
        )

        DBSession.add(user)
        DBSession.flush()
    headers = remember(request, user.id)
    DEBUG(u'User %s set' % user.name)
    if group == 'client':
        location = request.url_for('/scrum/sprint/list')
    else:
        location = '/'
    return HTTPFound(
        location=location,
        headers=headers,
    )