<commit_before>"""This module contains gn2 decorators"""
from flask import g
from typing import Dict
from functools import wraps
from utility.hmac import hmac_creation

import json
import requests


def edit_access_required(f):
    """Use this for endpoints where admins are required"""
    @wraps(f)
    def wrap(*args, **kwargs):
        resource_id: str = ""
        if kwargs.get("inbredset_id"):  # data type: dataset-publish
            resource_id = hmac_creation("dataset-publish:"
                                        f"{kwargs.get('inbredset_id')}:"
                                        f"{kwargs.get('name')}")
        if kwargs.get("dataset_name"):  # data type: dataset-probe
            resource_id = hmac_creation("dataset-probeset:"
                                        f"{kwargs.get('dataset_name')}")
        response: Dict = {}
        try:
            _user_id = g.user_session.record.get(b"user_id",
                                                 "").decode("utf-8")
            response = json.loads(
                requests.get("http://localhost:8080/"
                             "available?resource="
                             f"{resource_id}&user={_user_id}").content)
        except:
            response = {}
        if "edit" not in response.get("data", []):
            return "You need to be admin", 401
        return f(*args, **kwargs)
    return wrap<commit_msg>Replace hardcoded GN proxy URL in decorators.py with one pulled from settings<commit_after>"""This module contains gn2 decorators"""
from flask import g
from typing import Dict
from functools import wraps
from utility.hmac import hmac_creation
from utility.tools import GN_PROXY_URL

import json
import requests


def edit_access_required(f):
    """Use this for endpoints where admins are required"""
    @wraps(f)
    def wrap(*args, **kwargs):
        resource_id: str = ""
        if kwargs.get("inbredset_id"):  # data type: dataset-publish
            resource_id = hmac_creation("dataset-publish:"
                                        f"{kwargs.get('inbredset_id')}:"
                                        f"{kwargs.get('name')}")
        if kwargs.get("dataset_name"):  # data type: dataset-probe
            resource_id = hmac_creation("dataset-probeset:"
                                        f"{kwargs.get('dataset_name')}")
        response: Dict = {}
        try:
            _user_id = g.user_session.record.get(b"user_id",
                                                 "").decode("utf-8")
            response = json.loads(
                requests.get(GN_PROXY_URL + "available?resource="
                                f"{resource_id}&user={_user_id}").content)
        except:
            response = {}

        if "edit" not in response.get("data", []):
            return "You need to be admin", 401
        return f(*args, **kwargs)
    return wrap
{'fraction_non_alphanumeric': 0.11341632088520055, 'fraction_numerical': 0.004840940525587829, 'mean_word_length': 1.7951690821256039, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1856284', 'n_tokens_mistral': 778, 'n_tokens_neox': 759, 'n_words': 190}