예제 #1
0
파일: field.py 프로젝트: tonegas/GlobaLeaks
    def put(self, field_id):
        """
        Update a single field's attributes.

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body,
                                        requests.FieldDesc)

        # enforce difference between /admin/field and /admin/fieldtemplate
        request['is_template'] = False

        response = yield update_field(field_id, request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(202) # Updated
        self.finish(response)
예제 #2
0
    def test_handler_cache_hit(self):
        GLApiCache.invalidate()

        handler = self.request(path='/public')
        resp = yield handler.get()

        self.assertEqual(len(GLApiCache.memory_cache_dict), 1)

        cached_resp = GLApiCache.get("/public", "en")

        second_resp = yield handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)

        # Check that a different language doesn't blow away a different resource
        handler_fr = self.request(path='/public',
                                  headers={'gl-language': 'fr'})
        resp_fr = yield handler_fr.get()
        cached_resp_fr = GLApiCache.get("/public", "fr")

        self.assertEqual(resp_fr, cached_resp_fr)

        s = reduce(lambda x, y: x + len(y),
                   GLApiCache.memory_cache_dict.values(), 0)

        self.assertEqual(s, 2)
        self.assertNotEqual(resp_fr, cached_resp)
예제 #3
0
파일: l10n.py 프로젝트: sshyran/GlobaLeaks
    def put(self, lang):
        request = json.loads(self.request.body)

        yield update_custom_texts(lang, request)

        GLApiCache.invalidate()

        self.set_status(202)  # Updated
예제 #4
0
파일: l10n.py 프로젝트: Taipo/GlobaLeaks
    def put(self, lang):
        request = json.loads(self.request.body)

        yield update_custom_texts(lang, request)

        GLApiCache.invalidate()

        self.set_status(202)  # Updated
예제 #5
0
    def initialization(self):
        self.responses = []

        # we need to reset settings.session to keep each test independent
        GLSessions.clear()

        # we need to reset GLApiCache to keep each test independent
        GLApiCache.invalidate()
예제 #6
0
def set_onion_service_info(store, hostname, key):
    node_fact = NodeFactory(store)
    node_fact.set_val(u'onionservice', hostname)

    priv_fact = PrivateFactory(store)
    priv_fact.set_val(u'tor_onion_key', key)

    GLApiCache.invalidate()
예제 #7
0
    def initialization(self):
        self.responses = []

        # we need to reset settings.session to keep each test independent
        GLSessions.clear()

        # we need to reset GLApiCache to keep each test independent
        GLApiCache.invalidate()
예제 #8
0
    def delete(self, questionnaire_id):
        """
        Delete the specified questionnaire.

        Request: AdminQuestionnaireDesc
        Response: None
        Errors: InvalidInputFormat, QuestionnaireIdNotFound
        """
        yield delete_questionnaire(questionnaire_id)
        GLApiCache.invalidate()
예제 #9
0
    def delete(self, field_id):
        """
        Delete a single field template.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        """
        yield delete_field(field_id)

        GLApiCache.invalidate()
예제 #10
0
    def post(self):
        request = self.validate_message(self.request.body, requests.WizardDesc)

        # Wizard will raise exceptions if there are any errors with the request
        yield wizard(request, self.request.language)
        # cache must be updated in order to set wizard_done = True
        yield serialize_node(self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
예제 #11
0
파일: context.py 프로젝트: Taipo/GlobaLeaks
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()
예제 #12
0
    def delete(self, questionnaire_id):
        """
        Delete the specified questionnaire.

        Request: AdminQuestionnaireDesc
        Response: None
        Errors: InvalidInputFormat, QuestionnaireIdNotFound
        """
        yield delete_questionnaire(questionnaire_id)
        GLApiCache.invalidate()
예제 #13
0
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()
예제 #14
0
    def delete(self, field_id):
        """
        Delete a single field template.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        """
        yield delete_field(field_id)

        GLApiCache.invalidate()
예제 #15
0
파일: step.py 프로젝트: Taipo/GlobaLeaks
    def delete(self, step_id):
        """
        Delete the specified step.

        :param step_id:
        :raises StepIdNotFound: if there is no step with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_step(step_id)

        GLApiCache.invalidate()
예제 #16
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id)

        GLApiCache.invalidate()
예제 #17
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id)

        GLApiCache.invalidate()
예제 #18
0
파일: wizard.py 프로젝트: Taipo/GlobaLeaks
    def post(self):
        request = self.validate_message(self.request.body,
                                        requests.WizardDesc)

        # Wizard will raise exceptions if there are any errors with the request
        yield wizard(request, self.request.language)
        # cache must be updated in order to set wizard_done = True
        yield serialize_node(self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
예제 #19
0
    def delete(self, step_id):
        """
        Delete the specified step.

        :param step_id:
        :raises StepIdNotFound: if there is no step with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_step(step_id)

        GLApiCache.invalidate()
예제 #20
0
    def delete(self, user_id):
        """
        Delete the specified user.

        Parameters: user_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, UserIdNotFound
        """
        yield delete_user(user_id)

        GLApiCache.invalidate()
예제 #21
0
파일: user.py 프로젝트: Taipo/GlobaLeaks
    def delete(self, user_id):
        """
        Delete the specified user.

        Parameters: user_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, UserIdNotFound
        """
        yield delete_user(user_id)

        GLApiCache.invalidate()
예제 #22
0
파일: wizard.py 프로젝트: zhou0/GlobaLeaks
    def post(self):
        request = self.validate_message(self.request.content.read(),
                                        requests.WizardDesc)

        # Wizard will raise exceptions if there are any errors with the request
        yield wizard(request, self.request.language)

        yield serialize_node(self.request.language)

        # Invalidation is performed at this stage only after the asserts within
        # wizard have ensured that the wizard can be executed.
        GLApiCache.invalidate()
예제 #23
0
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()

        self.set_status(200) # Ok and return no content
        self.finish()
예제 #24
0
    def delete(self, questionnaire_id):
        """
        Delete the specified questionnaire.

        Request: AdminQuestionnaireDesc
        Response: None
        Errors: InvalidInputFormat, QuestionnaireIdNotFound
        """
        yield delete_questionnaire(questionnaire_id)
        GLApiCache.invalidate()

        self.set_status(200)  # Ok and return no content
        self.finish()
예제 #25
0
파일: __init__.py 프로젝트: nsfw/GlobaLeaks
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()

        self.set_status(200) # Ok and return no content
        self.finish()
    def delete(self, questionnaire_id):
        """
        Delete the specified questionnaire.

        Request: AdminQuestionnaireDesc
        Response: None
        Errors: InvalidInputFormat, QuestionnaireIdNotFound
        """
        yield delete_questionnaire(questionnaire_id)
        GLApiCache.invalidate()

        self.set_status(200) # Ok and return no content
        self.finish()
예제 #27
0
    def post(self):
        """
        """
        request = self.validate_message(self.request.body,
                                        requests.WizardFirstSetupDesc)

        yield wizard(request, self.request.language)

        # cache must be updated in particular to set wizard_done = True
        public_node_desc = yield serialize_node(self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
예제 #28
0
    def put(self):
        """
        Parameters: None
        Request: ReceiverReceiverDesc
        Response: ReceiverReceiverDesc
        Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication
        """
        request = self.validate_message(self.request.body, requests.ReceiverReceiverDesc)

        receiver_status = yield update_receiver_settings(self.current_user.user_id, request, self.request.language)

        GLApiCache.invalidate()

        self.write(receiver_status)
예제 #29
0
파일: field.py 프로젝트: nsfw/GlobaLeaks
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id)

        # get the updated list of contexts, and update the cache
        GLApiCache.invalidate('contexts')

        self.set_status(200)
예제 #30
0
    def post(self, obj_key, obj_id):
        uploaded_file = self.get_file_upload()
        if uploaded_file is None:
            self.set_status(201)
            return

        try:
            yield add_model_img(model_map[obj_key], obj_id, uploaded_file['body'].read())
        finally:
            uploaded_file['body'].close()

        GLApiCache.invalidate()

        self.set_status(201)
예제 #31
0
    def post(self, key):
        uploaded_file = self.get_file_upload()
        if uploaded_file is None:
            self.set_status(201)
            return

        try:
            yield add_file(uploaded_file['body'].read(), key)
        finally:
            uploaded_file['body'].close()

        GLApiCache.invalidate()

        self.set_status(201)
예제 #32
0
파일: files.py 프로젝트: Taipo/GlobaLeaks
    def post(self, key):
        uploaded_file = self.get_file_upload()
        if uploaded_file is None:
            self.set_status(201)
            return

        try:
            yield add_file(uploaded_file['body'].read(), key)
        finally:
            uploaded_file['body'].close()

        GLApiCache.invalidate()

        self.set_status(201)
예제 #33
0
    def test_handler_sync_cache_miss(self):
        # Asserts that the cases where the result of f returns immediately,
        # the caching implementation does not fall over and die.
        GLApiCache.invalidate()

        p = '/fake/sync/res'
        handler = self.request(handler_cls=FakeSyncHandler, path=p)
        resp = handler.get()

        cached_resp = GLApiCache.get(p, "en")

        second_resp = handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)
예제 #34
0
파일: field.py 프로젝트: nsfw/GlobaLeaks
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id)

        # get the updated list of contexts, and update the cache
        GLApiCache.invalidate('contexts')

        self.set_status(200)
예제 #35
0
파일: wizard.py 프로젝트: nyimbi/GlobaLeaks
    def post(self):
        """
        """
        request = self.validate_message(self.request.body,
                                        requests.WizardFirstSetupDesc)

        yield wizard(request, self.request.language)

        # cache must be updated in particular to set wizard_done = True
        public_node_desc = yield anon_serialize_node(self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
        self.finish()
예제 #36
0
    def test_handler_sync_cache_miss(self):
        # Asserts that the cases where the result of f returns immediately,
        # the caching implementation does not fall over and die.
        GLApiCache.invalidate()

        fake_path = '/xxx'
        fake_uri = 'https://www.globaleaks.org' + fake_path
        handler = self.request(handler_cls=FakeSyncHandler, uri=fake_uri)
        resp = handler.get()

        cached_resp = GLApiCache.get(fake_path, "en")

        second_resp = handler.get()
        self.assertEqual(resp, cached_resp)
        self.assertEqual(resp, second_resp)
예제 #37
0
    def delete(self, user_id):
        """
        Delete the specified user.

        Parameters: user_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, UserIdNotFound
        """
        yield delete_user(user_id)

        GLApiCache.invalidate()

        self.set_status(200)  # OK and return not content
        self.finish()
예제 #38
0
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: AdminFieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, self.request.language, self.request.request_type)

        GLApiCache.invalidate()

        self.write(response)
예제 #39
0
    def test_get(self):
        handler = self.request()

        yield handler.get(lang=u'en')

        self.assertNotIn('12345', self.responses[0])

        yield admin_l10n.update_custom_texts(u'en', custom_texts)

        GLApiCache.invalidate('l10n')

        yield handler.get(lang=u'en')

        self.assertIn('12345', self.responses[1])
        self.assertEqual('54321', self.responses[1]['12345'])
예제 #40
0
    def delete(self, user_id):
        """
        Delete the specified user.

        Parameters: user_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, UserIdNotFound
        """
        yield delete_user(user_id)

        GLApiCache.invalidate()

        self.set_status(200) # OK and return not content
        self.finish()
예제 #41
0
    def test_get(self):
        handler = self.request()

        yield handler.get(lang=u'en')

        self.assertNotIn('12345', self.responses[0])

        yield admin_l10n.update_custom_texts(u'en', custom_texts)

        GLApiCache.invalidate('l10n')

        yield handler.get(lang=u'en')

        self.assertIn('12345', self.responses[1])
        self.assertEqual('54321', self.responses[1]['12345'])
예제 #42
0
    def put(self):
        """
        Update the node infos.

        Request: AdminNodeDesc
        Response: AdminNodeDesc
        Errors: InvalidInputFormat
        """
        request = self.validate_message(self.request.body, requests.AdminNodeDesc)

        node_description = yield update_node(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(202)  # Updated
        self.write(node_description)
예제 #43
0
파일: __init__.py 프로젝트: nsfw/GlobaLeaks
    def post(self):
        """
        Get the specified receiver.

        Request: AdminReceiverDesc
        Response: AdminReceiverDesc
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminReceiverDesc)

        response = yield create_receiver(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
        self.finish(response)
예제 #44
0
파일: __init__.py 프로젝트: nsfw/GlobaLeaks
    def post(self):
        """
        Create a new context.

        Request: AdminContextDesc
        Response: AdminContextDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminContextDesc)

        response = yield create_context(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201) # Created
        self.finish(response)
예제 #45
0
파일: __init__.py 프로젝트: nsfw/GlobaLeaks
    def delete(self, receiver_id):
        """
        Delete the specified receiver.

        Parameters: receiver_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        yield delete_receiver(receiver_id)

        # get the updated list of receivers, and update the cache
        GLApiCache.invalidate()

        self.set_status(200) # OK and return not content
        self.finish()
예제 #46
0
파일: __init__.py 프로젝트: nsfw/GlobaLeaks
    def put(self, receiver_id):
        """
        Update the specified receiver.

        Parameters: receiver_id
        Request: AdminReceiverDesc
        Response: AdminReceiverDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound, ContextId
        """
        request = self.validate_message(self.request.body, requests.AdminReceiverDesc)

        response = yield update_receiver(receiver_id, request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)
        self.finish(response)
예제 #47
0
파일: node.py 프로젝트: pawmsf/GlobaLeaks
    def put(self):
        """
        Update the node infos.

        Request: AdminNodeDesc
        Response: AdminNodeDesc
        Errors: InvalidInputFormat
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminNodeDesc)

        node_description = yield update_node(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(202)  # Updated
        self.write(node_description)
예제 #48
0
파일: __init__.py 프로젝트: nsfw/GlobaLeaks
    def delete(self, receiver_id):
        """
        Delete the specified receiver.

        Parameters: receiver_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        yield delete_receiver(receiver_id)

        # get the updated list of receivers, and update the cache
        GLApiCache.invalidate()

        self.set_status(200)  # OK and return not content
        self.finish()
예제 #49
0
파일: field.py 프로젝트: nsfw/GlobaLeaks
    def post(self):
        """
        Create a new step.

        :return: the serialized step
        :rtype: StepDesc
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body, requests.StepDesc)

        response = yield create_step(request, self.request.language)

        GLApiCache.invalidate('contexts')

        self.set_status(201)
        self.finish(response)
예제 #50
0
파일: field.py 프로젝트: tonegas/GlobaLeaks
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id, False)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
예제 #51
0
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: AdminFieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, self.request.language,
                                   self.request.request_type)

        GLApiCache.invalidate()

        self.write(response)
예제 #52
0
    def put(self, user_id):
        """
        Update the specified user.

        Parameters: user_id
        Request: AdminUserDesc
        Response: AdminUserDesc
        Errors: InvalidInputFormat, UserIdNotFound
        """
        request = self.validate_message(self.request.body, requests.AdminUserDesc)

        response = yield admin_update_user(user_id, request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)
        self.finish(response)
예제 #53
0
 def test_invalidate(self):
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "come", "una", "catapulta!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertEqual(pdp_it, "come una catapulta!")
     yield GLApiCache.invalidate("passante_di_professione")
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
예제 #54
0
파일: __init__.py 프로젝트: nsfw/GlobaLeaks
    def post(self):
        """
        Get the specified receiver.

        Request: AdminReceiverDesc
        Response: AdminReceiverDesc
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminReceiverDesc)

        response = yield create_receiver(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201) # Created
        self.finish(response)
예제 #55
0
파일: __init__.py 프로젝트: nsfw/GlobaLeaks
    def post(self):
        """
        Create a new context.

        Request: AdminContextDesc
        Response: AdminContextDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminContextDesc)

        response = yield create_context(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)  # Created
        self.finish(response)
예제 #56
0
    def put(self):
        """
        Parameters: None
        Request: ReceiverReceiverDesc
        Response: ReceiverReceiverDesc
        Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication
        """
        request = self.validate_message(self.request.body,
                                        requests.ReceiverReceiverDesc)

        receiver_status = yield update_receiver_settings(
            self.current_user.user_id, request, self.request.language)

        GLApiCache.invalidate()

        self.write(receiver_status)
예제 #57
0
    def post(self):
        """
        Create a new field.

        :return: the serialized field
        :rtype: AdminFieldDesc
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body, requests.AdminFieldDesc)

        response = yield create_field(request, self.request.language, self.request.request_type)

        GLApiCache.invalidate()

        self.set_status(201)
        self.write(response)
예제 #58
0
파일: field.py 프로젝트: nsfw/GlobaLeaks
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, self.request.language)

        GLApiCache.invalidate('contexts')

        self.set_status(200)
        self.finish(response)
예제 #59
0
파일: field.py 프로젝트: nsfw/GlobaLeaks
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, self.request.language)

        GLApiCache.invalidate('contexts')

        self.set_status(200)
        self.finish(response)