Example #1
0
    def post(self, *uriargs):
        """
        Request: adminReceiverDesc
        Response: adminReceiverDesc
        Errors: InvalidInputFormat, ContextGusNotFound

        Create a new receiver
        """

        try:
            request = validateMessage(self.request.body, requests.adminReceiverDesc)

            receiver_iface = Receiver()

            new_receiver = yield receiver_iface.new(request)
            new_receiver_gus = new_receiver['receiver_gus']

            # 'contexts' it's a relationship between two tables, and is managed 
            # with a separate method of new()
            context_iface = Context()
            yield receiver_iface.receiver_align(new_receiver_gus, request['contexts'])
            yield context_iface.full_context_align(new_receiver_gus, request['contexts'])

            new_receiver_desc = yield receiver_iface.get_single(new_receiver_gus)

            self.set_status(201) # Created
            self.write(new_receiver_desc)

        except InvalidInputFormat, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #2
0
    def delete_receiver(self, receiver_gus):

        store = self.getStore()

        receiver_iface = Receiver(store)
        receiver_desc = receiver_iface.get_single(receiver_gus)

        receivertip_iface = ReceiverTip(store)
        # Remove Tip possessed by the receiver
        related_tips = receivertip_iface.get_tips_by_receiver(receiver_gus)
        for tip in related_tips:
            receivertip_iface.personal_delete(tip['tip_gus'])
            # Remind: the comment are kept, and the name do not use a reference
            # but is stored in the comment entry.

        context_iface = Context(store)

        # Just an alignment check that need to be removed
        contexts_associated = context_iface.get_contexts_by_receiver(receiver_gus)
        print "context associated by receiver POV:", len(contexts_associated),\
        "context associated by receiver-DB field:", len(receiver_desc['contexts'])

        context_iface.align_receiver_delete(receiver_desc['contexts'], receiver_gus)

        receiverconf_iface = ReceiverConfs(store)
        receivercfg_list = receiverconf_iface.get_confs_by_receiver(receiver_gus)
        for rcfg in receivercfg_list:
            receiverconf_iface.delete(rcfg['config_id'], receiver_gus)

        # Finally delete the receiver
        receiver_iface.receiver_delete(receiver_gus)

        self.returnData(receiver_desc)
        self.returnCode(200)
        return self.prepareRetVals()
Example #3
0
    def put(self, receiver_gus, *uriargs):
        """
        Request: adminReceiverDesc
        Response: adminReceiverDesc
        Errors: InvalidInputFormat, ReceiverGusNotFound, ContextGus

        Update information about a Receiver, return the instance updated.
        """

        try:
            # TODO parameter validation - InvalidInputFormat
            request = validateMessage(self.request.body, requests.adminReceiverDesc)

            receiver_iface = Receiver()

            yield receiver_iface.update(receiver_gus, request)

            # 'contexts' it's a relationship between two tables, and is managed 
            # with a separate method of new()
            context_iface = Context()
            yield receiver_iface.receiver_align(receiver_gus, request['contexts'])
            yield context_iface.full_context_align(receiver_gus, request['contexts'])

            receiver_description = yield receiver_iface.get_single(receiver_gus)

            self.set_status(200)
            self.write(receiver_description)

        except InvalidInputFormat, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #4
0
    def delete_context(self, context_gus):
        """
        This DELETE operation, its permanent, and remove all the reference
        a Context has within the system (Tip, File, submission...)
        """
        store = self.getStore()

        # Get context description, just to verify that context_gus is valid
        context_iface = Context(store)
        context_desc = context_iface.get_single(context_gus)

        # Collect tip by context and iter on the list
        receivertip_iface = ReceiverTip(store)
        tips_related_blocks = receivertip_iface.get_tips_by_context(context_gus)

        internaltip_iface = InternalTip(store)
        whistlebtip_iface = WhistleblowerTip(store)
        file_iface = File(store)
        comment_iface = Comment(store)

        # For every InternalTip, delete comment, wTip, rTip and Files
        for tip_block in tips_related_blocks:

            internaltip_id = tip_block.get('internaltip')['internaltip_id']

            whistlebtip_iface.delete_access_by_itip(internaltip_id)
            receivertip_iface.massive_delete(internaltip_id)
            comment_iface.delete_comment_by_itip(internaltip_id)
            file_iface.delete_file_by_itip(internaltip_id)

            # and finally, delete the InternalTip
            internaltip_iface.tip_delete(internaltip_id)

        # (Just a consistency check - need to be removed)
        receiver_iface = Receiver(store)
        receivers_associated = receiver_iface.get_receivers_by_context(context_gus)
        print "receiver associated by context POV:", len(receivers_associated),\
        "receiver associated by context DB-field:", len(context_desc['receivers'])

        # Align all the receiver associated to the context, that the context cease to exist
        receiver_iface.align_context_delete(context_desc['receivers'], context_gus)

        # Get the profile list related to context_gus and delete all of them
        profile_iface = PluginProfiles(store)
        profile_list = profile_iface.get_profiles_by_contexts([ context_gus ])
        for prof in profile_list:
            profile_iface.delete_profile(prof['profile_gus'])

        # Get the submission list under the context, and delete all of them
        submission_iface = Submission(store)
        submission_list = submission_iface.get_all()
        for single_sub in submission_list:
            submission_iface.submission_delete(single_sub['submission_gus'], wb_request=False)

        # Finally, delete the context
        context_iface.delete_context(context_gus)

        self.returnData(context_desc)
        self.returnCode(200)
        return self.prepareRetVals()
Example #5
0
    def delete(self, context_gus, *uriargs):
        """
        Request: adminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextGusNotFound
        """

        context_iface = Context()
        receivertip_iface = ReceiverTip()
        internaltip_iface = InternalTip()
        whistlebtip_iface = WhistleblowerTip()
        comment_iface = Comment()
        receiver_iface = Receiver()
        file_iface = File()

        # This DELETE operation, its permanent, and remove all the reference
        # a Context has within the system (in example: remove associated Tip,
        # remove

        try:

            context_desc = yield context_iface.get_single(context_gus)

            tips_related_blocks = yield receivertip_iface.get_tips_by_context(context_gus)

            print "Tip that need to be deleted, associated with the context",\
                context_gus, ":", len(tips_related_blocks)

            for tip_block in tips_related_blocks:

                internaltip_id = tip_block.get('internaltip')['internaltip_id']

                yield whistlebtip_iface.delete_access_by_itip(internaltip_id)
                yield receivertip_iface.massive_delete(internaltip_id)
                yield comment_iface.delete_comment_by_itip(internaltip_id)
                yield file_iface.delete_file_by_itip(internaltip_id)

                # and finally, delete the InternalTip
                yield internaltip_iface.tip_delete(internaltip_id)


            # (Just consistency check)
            receivers_associated = yield receiver_iface.get_receivers_by_context(context_gus)
            print "receiver associated by context POV:", len(receivers_associated),\
                "receiver associated by context DB-field:", len(context_desc['receivers'])

            # Align all the receiver associated to the context, that the context cease to exist
            yield receiver_iface.align_context_delete(context_desc['receivers'], context_gus)

            # TODO delete stats associated with context ?
            # TODO delete profile associated with the context

            # Finally, delete the context
            yield context_iface.delete_context(context_gus)
            self.set_status(200)

        except ContextGusNotFound, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #6
0
    def put(self, context_gus, *uriargs):
        """
        Request: adminContextDesc
        Response: adminContextDesc
        Errors: InvalidInputFormat, ContextGusNotFound, ReceiverGusNotFound
        """

        try:
            request = validateMessage(self.request.body, requests.adminContextDesc)

            context_iface = Context()
            yield context_iface.update(context_gus, request)

            # 'receivers' it's a relationship between two tables, and is managed 
            # with a separate method of new()
            receiver_iface = Receiver()
            yield context_iface.context_align(context_gus, request['receivers'])
            yield receiver_iface.full_receiver_align(context_gus, request['receivers'])

            context_description = yield context_iface.get_single(context_gus)

            self.set_status(200)
            self.write(context_description)

        except InvalidInputFormat, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #7
0
    def get_context(self, context_gus):

        context_iface = Context(self.getStore())
        context_description = context_iface.get_single(context_gus)

        self.returnData(context_description)
        self.returnCode(200)
        return self.prepareRetVals()
Example #8
0
    def get_context_list(self):

        context_iface = Context(self.getStore())
        all_contexts = context_iface.get_all()

        self.returnData(all_contexts)
        self.returnCode(200)
        return self.prepareRetVals()
Example #9
0
    def post(self, *uriargs):
        """
        Request: wbSubmissionDesc
        Response: wbSubmissionDesc
        Errors: ContextGusNotFound, InvalidInputFormat, SubmissionFailFields

        This creates an empty submission for the requested context,
        and returns submissionStatus with empty fields and a Submission Unique String,
        This is the unique token used during the submission procedure.
        sessionGUS is used as authentication secret for the next interaction.
        expire after the time set by Admin (Context dependent setting)
        """

        context_iface = Context()
        try:
            request = validateMessage(self.request.body, requests.wbSubmissionDesc)

            # XXX DUMMY PATCH CLIENT USAGE -- open tiket in GLClient
            print "Before", request
            if not request.has_key('wb_fields'):
                request.update({'wb_fields' : ''})
            if not request.has_key('receivers'):
                request.update({'receivers' : []})
            if not request.has_key('files'):
                request.update({'files' : []})
            if not request.has_key('finalize'):
                request.update({'finalize' : False })
            print "After ", request
            # XXX DUMMY PATCH CLIENT USAGE -- open tiket in GLClient

            context_desc = yield context_iface.get_single(request['context_gus'])

            submission_iface = Submission()
            submission_desc = yield submission_iface.new(request)

            if not context_desc['selectable_receiver']:
                submission_iface.receivers = context_iface.receivers

            if submission_desc['finalize']:

                internaltip_iface = InternalTip()
                wb_iface = WhistleblowerTip()

                internaltip_desc = yield internaltip_iface.new(submission_desc)
                wbtip_desc = yield wb_iface.new(internaltip_desc)

                submission_desc.update({'receipt' : wbtip_desc['receipt']})
            else:
                submission_desc.update({'receipt' : ''})

            self.set_status(201) # Created
            # TODO - output processing
            self.write(submission_desc)

        except ContextGusNotFound, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #10
0
    def get(self, *uriargs):
        """
        Parameters: None
        Response: adminContextList
        Errors: None
        """

        context_iface = Context()
        all_contexts = yield context_iface.get_all()

        self.set_status(200)
        # TODO output filter would include JSON inside of the method
        self.write(json.dumps(all_contexts))
        self.finish()
Example #11
0
    def get(self, *uriargs):
        """
        Parameters: None
        Response: publicContextList
        Errors: None
        """

        context_view = Context()
        public_context_view = yield context_view.get_all()

        self.set_status(200)
        self.write(json.dumps(public_context_view))
        # TODO, output filter need to strip all the reserved information

        self.finish()
Example #12
0
    def delete(self, receiver_gus, *uriargs):
        """
        Parameter: receiver_gus
        Request: None
        Response: None
        Errors: InvalidInputFormat, ReceiverGusNotFound
        """

        receiver_iface = Receiver()

        try:
            # TODO parameter receiver_gus validation - InvalidInputFormat
            receiver_desc = yield receiver_iface.get_single(receiver_gus)

            receivertip_iface = ReceiverTip()
            # Remove Tip possessed by the receiver
            related_tips = yield receivertip_iface.get_tips_by_receiver(receiver_gus)
            for tip in related_tips:
                yield receivertip_iface.personal_delete(tip['tip_gus'])
            # Remind: the comment are kept, and the name is not referenced but stored
            # in the comment entry.

            context_iface = Context()

            # TODO make an app log
            contexts_associated = yield context_iface.get_contexts_by_receiver(receiver_gus)
            print "context associated by receiver POV:", len(contexts_associated),\
                "context associated by receiver-DB field:", len(receiver_desc['contexts'])

            yield context_iface.align_receiver_delete(receiver_desc['contexts'], receiver_gus)

            receiverconf_iface = ReceiverConfs()
            # Delete all the receiver configuration associated TODO - App log an number of RCFGs
            receivercfg_list = yield receiverconf_iface.get_confs_by_receiver(receiver_gus)
            for rcfg in receivercfg_list:
                yield receiverconf_iface.delete(rcfg['config_id'], receiver_gus)

            # Finally delete the receiver
            yield receiver_iface.receiver_delete(receiver_gus)
            self.set_status(200)

        except ReceiverGusNotFound, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #13
0
    def post(self, *uriargs):
        """
        Request: wbSubmissionDesc
        Response: wbSubmissionDesc
        Errors: ContextGusNotFound, InvalidInputFormat, SubmissionFailFields

        This creates an empty submission for the requested context,
        and returns submissionStatus with empty fields and a Submission Unique String,
        This is the unique token used during the submission procedure.
        sessionGUS is used as authentication secret for the next interaction.
        expire after the time set by Admin (Context dependent setting)
        """

        try:
            request = validateMessage(self.request.body, requests.wbSubmissionDesc)

            submission = Submission()
            context_iface = Context()

            context_info = context_iface.public_get_single(request['context_gus'])
            # use requested context, for defaults and so on

            status = yield submission.new(request['context_gus'])
            submission_gus = status['submission_gus']

            # submission.receivers = context_iface.

            if request.has_key('fields'):
                log.debug("Fields present in creation: %s" % request['fields'])
                yield submission.update_fields(submission_gus, request['fields'])

            # TODO check if context supports receiver_selection
            if request.has_key('receivers'):
                yield submission.select_receiver(submission_gus, request['receivers'])

            self.set_status(201) # Created
            # TODO - output processing
            self.write(status)

        except ContextGusNotFound, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #14
0
    def update_receiver(self, receiver_gus, request):

        store = self.getStore()

        receiver_iface = Receiver(store)
        receiver_iface.update(receiver_gus, request)

        # 'contexts' it's a relationship between two tables, and is managed
        # with a separate method of update()

        context_iface = Context(store)
        receiver_iface.receiver_align(receiver_gus, request['contexts'])
        context_iface.full_context_align(receiver_gus, request['contexts'])

        receiver_description = receiver_iface.get_single(receiver_gus)

        self.returnData(receiver_description)
        self.returnCode(200)
        return self.prepareRetVals()
Example #15
0
    def get(self, context_gus, *uriargs):
        """
        Parameters: context_gus
        Response: adminContextDesc
        Errors: ContextGusNotFound, InvalidInputFormat
        """

        try:
            # TODO REMIND XXX - context_gus validation - InvalidInputFormat
            context_iface = Context()
            context_description = yield context_iface.get_single(context_gus)

            self.set_status(200)
            self.write(context_description)

        except ContextGusNotFound, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #16
0
    def put(self, submission_gus, *uriargs):
        """
        Parameter: submission_gus
        Request: wbSubmissionDesc
        Response: wbSubmissionDesc
        Errors: ContextGusNotFound, InvalidInputFormat, SubmissionFailFields, SubmissionGusNotFound, SubmissionConcluded

        PUT update the submission and finalize if requested.
        """

        context_iface = Context()
        try:
            request = validateMessage(self.request.body, requests.wbSubmissionDesc)

            context_desc = yield context_iface.get_single(request['context_gus'])

            submission_iface = Submission()
            submission_desc = yield submission_iface.update(submission_gus, request)

            if not context_desc['selectable_receiver']:
                submission_iface.receivers = context_iface.receivers

            if submission_desc['finalize']:

                internaltip_iface = InternalTip()
                wb_iface = WhistleblowerTip()

                internaltip_desc = yield internaltip_iface.new(submission_desc)
                wbtip_desc = yield wb_iface.new(internaltip_desc)

                submission_desc.update({'receipt' : wbtip_desc['receipt']})
            else:
                submission_desc.update({'receipt' : ''})

            self.set_status(202) # Updated
            # TODO - output processing
            self.write(submission_desc)

        except ContextGusNotFound, e:

            self.set_status(e.http_status)
            self.write({'error_message': e.error_message, 'error_code' : e.error_code})
Example #17
0
    def create_receiver(self, request):

        store = self.getStore()

        receiver_iface = Receiver(store)

        new_receiver = receiver_iface.new(request)
        new_receiver_gus = new_receiver['receiver_gus']

        # 'contexts' it's a relationship between two tables, and is managed
        # with a separate method of new()
        context_iface = Context(store)
        receiver_iface.receiver_align(new_receiver_gus, request['contexts'])
        context_iface.full_context_align(new_receiver_gus, request['contexts'])

        new_receiver_desc = receiver_iface.get_single(new_receiver_gus)

        self.returnData(new_receiver_desc)
        self.returnCode(201)
        return self.prepareRetVals()
Example #18
0
    def get(self, *uriargs):
        """
        Parameters: None
        Response: publicContextList
        Errors: None
        """

        try:
            context_view = Context()
            public_context_view = yield context_view.admin_get_all()

            self.set_status(200)
            self.write(json.dumps(public_context_view))
            # TODO output filter + json

        except KeyError: # TODO there are some error that can be returned ?

            self.set_status(444)
            self.write({'error_message': 'do not exist but TODO', 'error_code' : 12345})

        self.finish()
Example #19
0
    def get(self, what, *uriargs):
        """
        Parameters: None
        Response: Unknown
        Errors: None

        /dump/overview GET should return up to all the tables of GLBackend
        """

        expected = [ 'itip', 'wtip', 'rtip', 'receivers', 'comment',
                     'profiles', 'rcfg', 'file', 'submission', 'contexts', 'plugins', 'all', 'count' ]

        outputDict = {}

        if what == 'receivers' or what == 'all' or what == 'count':
            receiver_iface = Receiver()
            receiver_list = yield receiver_iface.get_all()

            if what != 'count':
                outputDict.update({ 'receivers_elements' : len(receiver_list), 'receivers' : receiver_list})
            else:
                outputDict.update({ 'receivers_elements' : len(receiver_list)})

        if what == 'itip' or what == 'all' or what == 'count':
            itip_iface = InternalTip()
            itip_list = yield itip_iface.get_all()

            if what != 'count':
                outputDict.update({ 'internaltips_elements' : len(itip_list), 'internaltips' : itip_list })
            else:
                outputDict.update({ 'internaltips_elements' : len(itip_list)})

        if what == 'rtip' or what == 'all' or what == 'count':
            rtip_iface = ReceiverTip()
            rtip_list = yield rtip_iface.get_all()

            if what != 'count':
                outputDict.update({ 'rtip_elements' : len(rtip_list), 'receivers_tips' : rtip_list })
            else:
                outputDict.update({ 'rtip_elements' : len(rtip_list)})

        if what == 'wtip' or what == 'all' or what == 'count':
            wtip_iface = WhistleblowerTip()
            wtip_list = yield wtip_iface.get_all()

            if what != 'count':
                outputDict.update({ 'wtip_elements' : len(wtip_list), 'whistleblower_tips' : wtip_list })
            else:
                outputDict.update({ 'wtip_elements' : len(wtip_list)})

        if what == 'comment' or what == 'all' or what == 'count':
            comment_iface = Comment()
            comment_list = yield comment_iface.get_all()

            if what != 'count':
                outputDict.update({ 'comment_elements' : len(comment_list), 'comments' : comment_list })
            else:
                outputDict.update({ 'comment_elements' : len(comment_list)})

        if what == 'profiles' or what == 'all' or what == 'count':
            profile_iface = PluginProfiles()
            profile_list = yield profile_iface.get_all()

            if what != 'count':
                outputDict.update({ 'profiles_elements' : len(profile_list), 'profiles' : profile_list })
            else:
                outputDict.update({ 'profiles_elements' : len(profile_list)})

        if what == 'plugins' or what == 'all' or what == 'count':
            plugin_list = yield PluginManager.get_all()

            if what != 'count':
                outputDict.update({ 'plugins_elements' : len(plugin_list), 'plugins' : plugin_list })
            else:
                outputDict.update({ 'plugins_elements' : len(plugin_list) })

        if what == 'rcfg' or what == 'all' or what == 'count':
            rconf_iface = ReceiverConfs()
            rconf_list = yield rconf_iface.get_all()

            if what != 'count':
                outputDict.update({ 'rcfg_elements' : len(rconf_list), 'settings' : rconf_list })
            else:
                outputDict.update({ 'rcfg_elements' : len(rconf_list)})

        if what == 'submission' or what == 'all' or what == 'count':
            submission_iface = Submission()
            submission_list = yield submission_iface.get_all()

            if what != 'count':
                outputDict.update({ 'submission_elements' : len(submission_list), 'submissions' : submission_list })
            else:
                outputDict.update({ 'submission_elements' : len(submission_list)})

        if what == 'file' or what == 'all' or what == 'count':
            file_iface = File()
            file_list = yield file_iface.get_all()

            if what != 'count':
                outputDict.update({ 'file_elements' : len(file_list), 'files' : file_list })
            else:
                outputDict.update({ 'file_elements' : len(file_list)})

        if what == 'contexts' or what == 'all' or what == 'count':
            context_iface = Context()
            context_list = yield context_iface.get_all()

            if what != 'count':
                outputDict.update({ 'contexts_elements' : len(context_list), 'contexts' : context_list })
            else:
                outputDict.update({ 'contexts_elements' : len(context_list)})


        if not what in expected:
            self.set_status(405)
        else:
            self.set_status(200)
            self.write(outputDict)

        self.finish()