Esempio n. 1
0
def index(request):
    # Get the current user's Business Units
    user = request.user
    # Count the number of users. If there is only one, they need to be made a GA
    if User.objects.count() == 1:
        # The first user created by syncdb won't have a profile. If there isn't
        # one, make sure they get one.
        try:
            profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            profile = UserProfile(user=user)

        profile.level = ProfileLevel.global_admin
        profile.save()

    user_is_ga = is_global_admin(user)

    if not user_is_ga:
        # user has many BU's display them all in a friendly manner
        if user.businessunit_set.count() == 0:
            c = {
                'user': request.user,
            }
            return render(request, 'server/no_access.html', c)
        if user.businessunit_set.count() == 1:
            # user only has one BU, redirect to it
            return redirect('bu_dashboard',
                            bu_id=user.businessunit_set.all()[0].id)

    # Load in the default plugins if needed
    utils.load_default_plugins()
    plugins = sal.plugin.PluginManager().get_all_plugins()

    reports = utils.get_report_names(plugins)
    output = utils.get_plugin_placeholder_markup(plugins)

    # If the user is GA level, and hasn't decided on a data sending
    # choice, template will reflect this.
    data_choice = False if (
        user_is_ga and utils.get_setting('send_data') is None) else True

    # get the user level - if they're a global admin, show all of the
    # machines. If not, show only the machines they have access to
    if user_is_ga:
        business_units = BusinessUnit.objects.all()
    else:
        business_units = user.businessunit_set.all()

    context = {
        'user': request.user,
        'business_units': business_units,
        'output': output,
        'data_setting_decided': data_choice,
        'reports': reports
    }

    context.update(utils.check_version())

    return render(request, 'server/index.html', context)
Esempio n. 2
0
def update_notify_date(request, length='never'):
    # Don't notify about a new version until there is a new one
    version_report = utils.check_version()
    if version_report['new_version_available']:
        if isinstance(length, int):
            next_notify_date = utils.get_setting('next_notify_date', time.time()) + length
        else:
            next_notify_date = length
        utils.set_setting('next_notify_date', next_notify_date)
Esempio n. 3
0
def update_notify_date(request, length='never'):
    # Don't notify about a new version until there is a new one
    version_report = utils.check_version()
    if version_report['new_version_available']:
        if isinstance(length, int):
            next_notify_date = utils.get_setting('next_notify_date', time.time()) + length
        else:
            next_notify_date = length
        utils.set_setting('next_notify_date', next_notify_date)
Esempio n. 4
0
def index(request):
    # Get the current user's Business Units
    user = request.user
    # Count the number of users. If there is only one, they need to be made a GA
    if User.objects.count() == 1:
        # The first user created by syncdb won't have a profile. If there isn't
        # one, make sure they get one.
        try:
            profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            profile = UserProfile(user=user)

        profile.level = ProfileLevel.global_admin
        profile.save()

    user_is_ga = is_global_admin(user)

    if not user_is_ga:
        # user has many BU's display them all in a friendly manner
        if user.businessunit_set.count() == 0:
            c = {'user': request.user, }
            return render(request, 'server/no_access.html', c)
        if user.businessunit_set.count() == 1:
            # user only has one BU, redirect to it
            return redirect('bu_dashboard', bu_id=user.businessunit_set.all()[0].id)

    # Load in the default plugins if needed
    utils.load_default_plugins()
    plugins = sal.plugin.PluginManager().get_all_plugins()

    reports = utils.get_report_names(plugins)
    output = utils.get_plugin_placeholder_markup(plugins)

    # If the user is GA level, and hasn't decided on a data sending
    # choice, template will reflect this.
    data_choice = False if (user_is_ga and utils.get_setting('send_data') is None) else True

    # get the user level - if they're a global admin, show all of the
    # machines. If not, show only the machines they have access to
    if user_is_ga:
        business_units = BusinessUnit.objects.all()
    else:
        business_units = user.businessunit_set.all()

    context = {
        'user': request.user,
        'business_units': business_units,
        'output': output,
        'data_setting_decided': data_choice,
        'reports': reports}

    context.update(utils.check_version())

    return render(request, 'server/index.html', context)