Example #1
0
 def check_question_author(user, content):
     """ Check if the given user is the author of the original question for both threads and comments. """
     if not content:
         return False
     try:
         request_cache_dict = DEFAULT_REQUEST_CACHE.data
         if content["type"] == "thread":
             cache_key = "django_comment_client.permissions._check_condition.check_question_author.{}.{}".format(
                 user.id, content['id'])
             if cache_key in request_cache_dict:
                 return request_cache_dict[cache_key]
             else:
                 result = content["thread_type"] == "question" and content[
                     "user_id"] == str(user.id)
                 request_cache_dict[cache_key] = result
                 return result
         else:
             cache_key = "django_comment_client.permissions._check_condition.check_question_author.{}.{}".format(
                 user.id, content['thread_id'])
             if cache_key in request_cache_dict:
                 return request_cache_dict[cache_key]
             else:
                 # make the now-unavoidable comments service query
                 thread = Thread(id=content['thread_id']).to_dict()
                 return check_question_author(user, thread)
     except KeyError:
         return False
Example #2
0
 def check_question_author(user, content):
     """ Check if the given user is the author of the original question for both threads and comments. """
     if not content:
         return False
     try:
         if content["type"] == "thread":
             return content["thread_type"] == "question" and content["user_id"] == str(user.id)
         else:
             # N.B. This will trigger a comments service query
             return check_question_author(user, Thread(id=content["thread_id"]).to_dict())
     except KeyError:
         return False
Example #3
0
 def check_question_author(user, content):
     if not content:
         return False
     try:
         if content["type"] == "thread":
             return content["thread_type"] == "question" and content[
                 "user_id"] == str(user.id)
         else:
             # N.B. This will trigger a comments service query
             return check_question_author(
                 user,
                 Thread(id=content["thread_id"]).to_dict())
     except KeyError:
         return False