コード例 #1
0
from __future__ import with_statement
from time import sleep, time

from pyramid.view import view_config
from pyramid.renderers import render

from intranet3.utils.views import BaseView
from intranet3.models import User, TimeEntry, Tracker, TrackerCredentials, Project, Client, ApplicationConfig
from intranet3.forms.times import ProjectsTimeForm, TimeEntryForm
from intranet3.asyncfetchers import get_fetcher
from intranet3.helpers import groupby, partition
from intranet3.log import INFO_LOG, WARN_LOG, ERROR_LOG, DEBUG_LOG, EXCEPTION_LOG
from intranet3.lib.times import TimesReportMixin, HTMLRow, dump_entries_to_excel

LOG = INFO_LOG(__name__)
WARN = WARN_LOG(__name__)
ERROR = ERROR_LOG(__name__)
DEBUG = DEBUG_LOG(__name__)
EXCEPTION = EXCEPTION_LOG(__name__)

MAX_TIMEOUT = 20  # DON'T WAIT LONGER THAN DEFINED TIMEOUT
MAX_TICKETS_PER_REQUEST = 50  # max number of ticket ids to include in a single request to tracker


@view_config(route_name='times_tickets_excel', permission='client')
class Excel(BaseView):
    def get(self):
        client = self.request.user.get_client()
        form = ProjectsTimeForm(formdata=self.request.GET, client=client)
        if not form.validate():
            return render('time/tickets_report/projects_report.html',
コード例 #2
0
ファイル: auth.py プロジェクト: KenjiTakahashi/intranet
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',
                                                 '').split('\n')
    config = ApplicationConfig.get_current_config(allow_empty=True)
    freelancers = config.get_freelancers()
    clients_emails = Client.get_emails()
    if email.endswith('@%s' % request.registry.settings['COMPANY_DOMAIN']
                      ) or email in EXTRA_EMAILS:
        group = 'user'
    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()

    session = request.db_session
    user = session.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
            session.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],
        )

        session.add(user)
        session.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,
    )