Esempio n. 1
0
    def _ModActionMark(self, modActionResultCode):
        # Create the mod action
        newModAction = ModAction.objects.create(
            result=modActionResultCode,
            cid=Utils.UUIDToBinary(self.contentID),
            contentType=self.content.contentType)

        # Update all reports
        Report.objects.filter(cid=Utils.UUIDToBinary(self.contentID))\
                                .update(modAction=newModAction)
Esempio n. 2
0
def Report(requestData):
    
    TAG = Const.Tags.Urls.MODERATION_REPORT
    
    securityProperties = RunThroughSecurityLayer(TAG, requestData)
    if (not securityProperties.isSecure):
        return securityProperties.httpResponse
    
    try:
        clientUser = securityProperties.userObject
        clientContentId = securityProperties.jsonRequestData[Const.Views.Report.JsonRequestKey.CONTENT_ID]
        
        # check that the content exists in the database
        clientContent = QueryManager.GetObjectByID(OnlineContent, clientContentId)
        if (not clientContent):
            DataCollector.UpdateURLHit(hitID=securityProperties.hitID,
                                       responseCode=Const.HttpResponseFactory.ResponseCodes.ClientError.CODE_NOT_FOUND, 
                                       messageCode=Const.DataCollection.MessageCodes.ModerationReport.CONTENT_NOT_FOUND)  
            
            return HttpResponseFactory.MakeHttpResponse(Const.HttpResponseFactory.ResponseCodes.ClientError.CODE_NOT_FOUND, 
                                                        Const.DataCollection.MessageCodes.ModerationReport.CONTENT_NOT_FOUND)
        
        # get the content type that the user is reporting
        contentType = clientContent.contentType
        
        # check if this user has already tried to create this report
        userDupeReports = ReportModel.objects.filter(fromUser=clientUser,
                                                contentID=clientContentId)
        
        # If so, log the hit and return an error to client
        if (userDupeReports):
            DataCollector.UpdateURLHit(hitID=securityProperties.hitID,
                                       responseCode=Const.HttpResponseFactory.ResponseCodes.ClientError.CODE_CONFLICT, 
                                       messageCode=Const.DataCollection.MessageCodes.ModerationReport.REPORT_EXISTS) 
             
            return HttpResponseFactory.MakeHttpResponse(Const.HttpResponseFactory.ResponseCodes.ClientError.CODE_CONFLICT, 
                                                        Const.DataCollection.MessageCodes.ModerationReport.REPORT_EXISTS) 
        
        # Create the report
        ReportModel.objects.create(fromUser=clientUser,
                                   contentID=Utils.UUIDToBinary(clientContentId),
                                   contentType=contentType)  
        
        # Log the hit and return
        DataCollector.UpdateURLHit(hitID=securityProperties.hitID,
                                   responseCode=Const.HttpResponseFactory.ResponseCodes.Success.CODE_OK, 
                                   messageCode=Const.DataCollection.MessageCodes.ModerationReport.REQUEST_SUCCESSFUL) 
        
        return HttpResponseFactory.MakeHttpResponse(Const.HttpResponseFactory.ResponseCodes.Success.CODE_OK,
                                                    Const.DataCollection.MessageCodes.ModerationReport.REQUEST_SUCCESSFUL)    
                
    except Exception as e:
        # log and return on error
        DataCollector.logServerError(e)
        DataCollector.UpdateURLHit(hitID=securityProperties.hitID,
                                    responseCode=Const.HttpResponseFactory.ResponseCodes.ServerError.CODE_INTERNAL_SERVER_ERROR, 
                                    messageCode=Const.DataCollection.MessageCodes.ModerationReport.REQUEST_FAILED_SERVER_ERROR) 
        
        return HttpResponseFactory.MakeHttpResponse(Const.HttpResponseFactory.ResponseCodes.ServerError.CODE_INTERNAL_SERVER_ERROR, 
                                                    Const.DataCollection.MessageCodes.ModerationReport.REQUEST_FAILED_SERVER_ERROR)
Esempio n. 3
0
    def _PrintModInfo(self, contentID):
        numReports = Report.objects.filter(
            cid=Utils.UUIDToBinary(contentID)).count()
        online = False
        archived = False
        modActionType = ''

        if (QueryManager.ContentIsOnline(contentID)):
            online = True
        if (QueryManager.ContentIsArchived(contentID)):
            archived = True

        # Get the mod action associated with the piece of content, if there is one
        modActionType = QueryManager.GetMostRecentModActionResult(contentID)

        print('NumReports: ', numReports)
        print('Online: ', online)
        print('Archived: ', archived)
        print('Most recent mod action: ', 'N/A' if not modActionType else
              modActionType)  # ternary operator in python ;)
Esempio n. 4
0
 class Defaults:
     ID = Utils.UUIDToBinary('00000000000000000000000000000000')
Esempio n. 5
0
def GetThreadReplies(threadID):
    from JokrBackend.models import Reply

    return Reply.objects.filter(parentThread=Utils.UUIDToBinary(threadID))
Esempio n. 6
0
def GetObjectByID(model, uuid):
    try:
        return model.objects.get(id=Utils.UUIDToBinary(uuid))
    except model.DoesNotExist:
        return None