Esempio n. 1
0
def repo_licenses(request, repo_base, repo):
    '''
    returns the licenses linked to a particular repo.
    '''
    username = request.user.get_username()
    repo_licenses = LicenseManager.find_licenses_by_repo(repo_base, repo)

    license_applied = []
    with DataHubManager(user=username, repo_base=repo_base) as manager:
        collaborators = manager.list_collaborators(repo)
        for license in repo_licenses:
            all_applied = manager.license_applied_all(repo, license.license_id)
            license_applied.append(all_applied)

    collaborators = [c for c in collaborators if c['username']
                     not in ['', username, settings.PUBLIC_ROLE]]

    license_info_tuples = zip(repo_licenses, license_applied)

    res = {
        'login': username,
        'repo_base': repo_base,
        'repo': repo,
        'collaborators': collaborators,
        'license_info_tuples': license_info_tuples,
        'repo_licenses': repo_licenses,
        'all_licenses': LicenseManager.find_licenses(),
        }
    res.update(csrf(request))

    return render_to_response("repo-licenses.html", res)
Esempio n. 2
0
    def get_view_sql(self, repo_base, repo, table, view_params, license_id):
        # create view based on license
        license = LicenseManager.find_license_by_id(license_id)

        pii_def = license.pii_def

        if license.pii_removed:
            # remove columns
            query = ('SELECT column_name FROM information_schema.columns '
                     'WHERE table_schema = %s'
                     'AND table_name = %s')
            params = (repo, table)
            res = self.execute_sql(query, params)

            columns = [t[0] for t in res['tuples']]

            all_columns = set(columns)
            removed_columns = set(view_params['removed-columns'])
            columns_to_show = list(all_columns - removed_columns)
            # if columns_to_show < 1:
            #     #error
            #     pass

            query = 'SELECT {} FROM {}.{}'

            columns_query = ""
            for i in range(len(columns_to_show)):
                columns_query += columns_to_show[i]
                if i < len(columns_to_show) - 1:
                    columns_query += ","

            query = query.format(columns_query, repo, table)

            return query
Esempio n. 3
0
    def get_view_sql(self, repo_base, repo, table, view_params, license_id):
        # create view based on license
        license = LicenseManager.find_license_by_id(license_id)

        pii_def = license.pii_def

        if license.pii_removed:
            # remove columns
            query = ('SELECT column_name FROM information_schema.columns '
                     'WHERE table_schema = %s'
                     'AND table_name = %s'
                     )
            params = (repo, table)
            res = self.execute_sql(query, params)

            columns = [t[0] for t in res['tuples']]

            all_columns = set(columns)
            removed_columns = set(view_params['removed-columns'])
            columns_to_show = list(all_columns - removed_columns)
            # if columns_to_show < 1:
            #     #error
            #     pass

            query = 'SELECT {} FROM {}.{}'

            columns_query = ""
            for i in range(len(columns_to_show)):
                columns_query += columns_to_show[i]
                if i < len(columns_to_show) - 1:
                    columns_query += ","

            query = query.format(columns_query, repo, table)

            return query
Esempio n. 4
0
def link_license(request, repo_base, repo, license_id):
    '''
    links a license with a particular repo
    '''
    username = request.user.get_username()
    public_role = settings.PUBLIC_ROLE


    with DataHubManager(user=username, repo_base=repo_base) as manager:
        collaborators = manager.list_collaborators(repo)

    # remove the current user, public user from the collaborator list
    collaborators = [c for c in collaborators if c['username']
                     not in ['', username, settings.PUBLIC_ROLE]]

    LicenseManager.create_license_link(repo_base, repo, license_id)

    repo_licenses = LicenseManager.find_licenses_by_repo(repo_base, repo)
    all_licenses = LicenseManager.find_licenses()

    return HttpResponseRedirect(reverse('browser-repo_licenses',
                                args=(repo_base, repo)))
Esempio n. 5
0
def license_create(request):
    username = request.user.get_username()
    public_role = settings.PUBLIC_ROLE

    if request.method == 'POST':
        # creates a new license
        pii_anonymized = False
        pii_removed = False

        license_name = request.POST['license_name'] or None
        pii_def = request.POST['pii_def'] or None
        pii_anonymized = 'anonymized' in request.POST.getlist('pii_properties')
        pii_removed = 'removed' in request.POST.getlist('pii_properties')

        if not license_name:
            raise ValueError("Request missing \'license_name\' parameter.")
        if not pii_def:
            raise ValueError("Request missing \'pii definition\' parameter.")

        LicenseManager.create_license(
            license_name=license_name,
            pii_def=pii_def,
            pii_anonymized=pii_anonymized,
            pii_removed=pii_removed)

        return HttpResponseRedirect(reverse('browser-user', args=(username,)))

    elif request.method == 'GET':
        # returns page for creating a license
        res = {
            'login': username,
            'public_role': public_role,
            }
        res.update(csrf(request))

        return render_to_response("license-create.html", res)
Esempio n. 6
0
def repo_license_manage(request, repo_base, repo, license_id):
    '''
    shows all the tables for a repo,
    and checks if the given license is applied to each one
    '''
    username = request.user.get_username()
    if repo_base.lower() == 'user':
        repo_base = username

    license_applied = []
    license_views = []
    with DataHubManager(user=username, repo_base=repo_base) as manager:
        collaborators = manager.list_collaborators(repo, -1)
        # collaborators = None
        base_tables = manager.list_tables(repo)
        license_views = manager.list_license_views(repo, license_id)
        for table in base_tables:
            # check if license view exists for this license_id
            applied = manager.check_license_applied(table, repo, license_id)
            license_applied.append(applied)

    license = LicenseManager.find_license_by_id(license_id)

    table_info_tuples = [(x, y) for x in base_tables for y in license_applied]

    rls_table = 'policy'

    res = {
        'license': license,
        'login': username,
        'repo_base': repo_base,
        'repo': repo,
        'table_info_tuples': table_info_tuples,
        'license_views': license_views,
        'rls-table': rls_table,
        'collaboratoes': collaborators,
        }

    res.update(csrf(request))

    return render_to_response("repo-license-manage.html", res)
Esempio n. 7
0
def create_license_link_table(apps, schema_editor):
    LicenseManager.create_license_link_table()
Esempio n. 8
0
def create_license_schema(apps, schema_editor):
    LicenseManager.create_license_schema()