"""This module contains gn2 decorators"""
from flask import g
from functools import wraps


def edit_access_required(f):
    """Use this for endpoints where admins are required"""
    @wraps(f)
    def wrap(*args, **kwargs):
        if g.user_session.record.get(b"user_email_address") not in [
                b"labwilliams@gmail.com"]:
            return "You need to be admin", 401
        return f(*args, **kwargs)
    return wrap

"""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

Replace hard-coded e-mails with gn-proxy queries
Replace hard-coded e-mails with gn-proxy queries

* wqflask/wqflask/decorators.py (edit_access_required.wrap): Query the
proxy to see the access rights of a given user.

  """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):
-         if g.user_session.record.get(b"user_email_address") not in [
-                 b"labwilliams@gmail.com"]:
+         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
  
Replace hard-coded e-mails with gn-proxy queries
## Code Before:
"""This module contains gn2 decorators"""
from flask import g
from functools import wraps


def edit_access_required(f):
    """Use this for endpoints where admins are required"""
    @wraps(f)
    def wrap(*args, **kwargs):
        if g.user_session.record.get(b"user_email_address") not in [
                b"labwilliams@gmail.com"]:
            return "You need to be admin", 401
        return f(*args, **kwargs)
    return wrap

## Instruction:
Replace hard-coded e-mails with gn-proxy queries
## Code After:
"""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
