Example #1
0
    def save(self, domain):
        domain.restrict_superusers = self.cleaned_data.get('restrict_superusers', False)
        try:
            secure_submissions = self.cleaned_data.get(
                'secure_submissions', False)
            apps_to_save = []
            if secure_submissions != domain.secure_submissions:
                for app in get_apps_in_domain(domain.name):
                    if app.secure_submissions != secure_submissions:
                        app.secure_submissions = secure_submissions
                        apps_to_save.append(app)
            domain.secure_submissions = secure_submissions
            domain.save()

            if apps_to_save:
                apps = [app for app in apps_to_save if isinstance(app, Application)]
                remote_apps = [app for app in apps_to_save if isinstance(app, RemoteApp)]
                if apps:
                    Application.bulk_save(apps)
                if remote_apps:
                    RemoteApp.bulk_save(remote_apps)

            return True
        except Exception:
            return False
Example #2
0
    def setUpClass(cls):
        super(DBAccessorsTest, cls).setUpClass()
        cls.project = Domain(name=cls.domain)
        cls.project.save()
        cls.first_saved_version = 2
        cls.apps = [
            # .wrap adds lots of stuff in, but is hard to call directly
            # this workaround seems to work
            Application.wrap(Application(domain=cls.domain, name='foo', version=1, modules=[Module()]).to_json()),
            RemoteApp.wrap(RemoteApp(domain=cls.domain, version=1, name='bar').to_json()),
        ]
        for app in cls.apps:
            app.save()

        cls.decoy_apps = [
            # this one is a build
            Application(
                domain=cls.domain,
                copy_of=cls.apps[0].get_id,
                version=cls.first_saved_version,
                has_submissions=True,
            ),
            # this one is another build
            Application(domain=cls.domain, copy_of=cls.apps[0].get_id, version=12),

            # this one is another app
            Application(domain=cls.domain, copy_of='1234', version=12),
            # this one is in the wrong domain
            Application(domain='decoy-domain', version=5)
        ]
        for app in cls.decoy_apps:
            app.save()
Example #3
0
    def handle(self, *args, **options):
        path, build_slug = args

        app_slugs = []
        perfpath = os.path.join(path, '{}-performance.txt'.format(build_slug))
        if os.path.exists(perfpath):
            os.remove(perfpath)

        for name in os.listdir(os.path.join(path, 'src')):
            _JSON = '.json'
            if name.endswith(_JSON):
                app_slugs.append(name[:-len(_JSON)])

        for slug in app_slugs:
            print 'Fetching %s...' % slug
            source_path = os.path.join(path, 'src', '%s.json' % slug)
            with open(source_path) as f:
                j = json.load(f)
                if j['doc_type'] == 'Application':
                    app = Application.wrap(j)
                elif j['doc_type'] == 'RemoteApp':
                    app = RemoteApp.wrap(j)

            app.version = 1
            if not app.domain:
                app.domain = "test"
            build_path = os.path.join(path, build_slug, slug)
            print ' Creating files...'
            if options.get('track_perf'):
                with record_performance_stats(perfpath, slug):
                    files = app.create_all_files()
            else:
                files = app.create_all_files()

            self.write_files(files, build_path)
Example #4
0
    def handle(self, *args, **options):
        path, build_slug = args

        app_slugs = []
        perfpath = os.path.join(path, '{}-performance.txt'.format(build_slug))
        if os.path.exists(perfpath):
            os.remove(perfpath)

        for name in os.listdir(os.path.join(path, 'src')):
            _JSON = '.json'
            if name.endswith(_JSON):
                app_slugs.append(name[:-len(_JSON)])

        for slug in app_slugs:
            print 'Fetching %s...' % slug
            source_path = os.path.join(path, 'src', '%s.json' % slug)
            with open(source_path) as f:
                j = json.load(f)
                if j['doc_type'] == 'Application':
                    app = Application.wrap(j)
                elif j['doc_type'] == 'RemoteApp':
                    app = RemoteApp.wrap(j)

            app.version = 1
            if not app.domain:
                app.domain = "test"
            build_path = os.path.join(path, build_slug, slug)
            print ' Creating files...'
            if track_perf:
                with record_performance_stats(perfpath, slug):
                    files = app.create_all_files()
            else:
                files = app.create_all_files()

            self.write_files(files, build_path)
Example #5
0
    def setUpClass(cls):
        cls.project = Domain(name=cls.domain)
        cls.project.save()
        cls.first_saved_version = 2
        cls.apps = [
            # .wrap adds lots of stuff in, but is hard to call directly
            # this workaround seems to work
            Application.wrap(Application(domain=cls.domain, name="foo", version=1, modules=[Module()]).to_json()),
            RemoteApp.wrap(RemoteApp(domain=cls.domain, version=1, name="bar").to_json()),
        ]
        for app in cls.apps:
            app.save()

        cls.decoy_apps = [
            # this one is a build
            Application(
                domain=cls.domain, copy_of=cls.apps[0].get_id, version=cls.first_saved_version, has_submissions=True
            ),
            # this one is another build
            Application(domain=cls.domain, copy_of=cls.apps[0].get_id, version=12),
            # this one is another app
            Application(domain=cls.domain, copy_of="1234", version=12),
            # this one is in the wrong domain
            Application(domain="decoy-domain", version=5),
        ]
        for app in cls.decoy_apps:
            app.save()
Example #6
0
    def setUpClass(cls):
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        cls.apps = [
            # .wrap adds lots of stuff in, but is hard to call directly
            # this workaround seems to work
            Application.wrap(
                Application(domain=cls.domain,
                            name='foo',
                            version=1,
                            modules=[Module()]).to_json()),
            RemoteApp.wrap(
                RemoteApp(domain=cls.domain, version=1, name='bar').to_json()),
        ]
        for app in cls.apps:
            app.save()
Example #7
0
 def setUpClass(cls):
     cls.project = create_domain(cls.domain)
     cls.apps = [
         Application(domain=cls.domain),
         RemoteApp(domain=cls.domain),
     ]
     for app in cls.apps:
         app.save()
Example #8
0
 def setUp(self):
     self.project = create_domain(self.domain)
     self.apps = [
         Application(domain=self.domain),
         RemoteApp(domain=self.domain),
     ]
     for app in self.apps:
         app.save()
    def setUpClass(cls):
        cls.project = Domain(name=cls.domain)
        cls.project.save()

        cls.apps = [
            # .wrap adds lots of stuff in, but is hard to call directly
            # this workaround seems to work
            Application.wrap(Application(domain=cls.domain, name="foo", version=1, modules=[Module()]).to_json()),
            RemoteApp.wrap(RemoteApp(domain=cls.domain, version=1, name="bar").to_json()),
        ]
        for app in cls.apps:
            app.save()
Example #10
0
    def setUpClass(cls):
        super(DBAccessorsTest, cls).setUpClass()
        cls.project = Domain.get_or_create_with_name(cls.domain, is_active=True)
        cls.first_saved_version = 2

        cls.normal_app = Application.wrap(
            Application(domain=cls.domain, name='foo', version=1, modules=[Module()]).to_json()
        )
        cls.normal_app.save()

        cls.remote_app = RemoteApp.wrap(RemoteApp(domain=cls.domain, version=1, name='bar').to_json())
        cls.remote_app.save()

        cls.linked_app = LinkedApplication.wrap(
            LinkedApplication(domain=cls.domain, version=1, name='linked-app', upstream_app_id='abc123').to_json()
        )
        cls.linked_app.save()

        cls.decoy_apps = [
            # this one is a build
            Application(
                domain=cls.domain,
                copy_of=cls.normal_app.get_id,
                version=cls.first_saved_version,
                has_submissions=True,
            ),
            # this one is another build
            Application(domain=cls.domain, copy_of=cls.normal_app.get_id, version=12),

            # this one is another app
            Application(domain=cls.domain, copy_of='1234', version=12),
            # this one is in the wrong domain
            Application(domain='decoy-domain', version=5)
        ]
        for app in cls.decoy_apps:
            app.save()
Example #11
0
    def handle(self, *args, **options):
        path, build_slug = args

        app_slugs = []
        for name in os.listdir(os.path.join(path, 'src')):
            _JSON = '.json'
            if name.endswith(_JSON):
                app_slugs.append(name[:-len(_JSON)])

        for slug in app_slugs:
            print 'Fetching %s...' % slug
            source_path = os.path.join(path, 'src', '%s.json' % slug)
            with open(source_path) as f:
                j = json.load(f)
                if j['doc_type'] == 'Application':
                    app = Application.wrap(j)
                elif j['doc_type'] == 'RemoteApp':
                    app = RemoteApp.wrap(j)

            app.version = 1
            build_path = os.path.join(path, build_slug, slug)
            print ' Creating files...'
            self.create_files(app, build_path)
Example #12
0
    def remote_forms(self):
        """
            These are forms with an xmlns that can be matched to a RemoteApp or RemoteApp-Deleted id or
            they have an xmlns which follows our remote app namespacing pattern.
        """
        result = {}

        all_forms = set(self.all_forms)
        std_app_forms = set(self.application_forms)
        other_forms = list(all_forms.difference(std_app_forms))

        key = ["", self.domain]
        remote_app_data = RemoteApp.get_db().view('reports_apps/remote',
            reduce=False,
            startkey=key,
            endkey=key+[{}],
        ).all()
        remote_apps = dict([(d['id'], d['value']) for d in remote_app_data])

        for form in other_forms:
            if form:
                xmlns, app_id = self.split_xmlns_app_key(form)
                remote_xmlns = re.search(REMOTE_APP_WILDCARD, xmlns)
                if app_id in remote_apps.keys() or remote_xmlns:
                    if app_id in remote_apps.keys():
                        app_info = copy.copy(remote_apps[app_id])
                    else:
                        app_info = {
                            'app': {
                                'is_unknown': True,
                                'id': self.unknown_remote_app_id,
                                'names': 'Name Unknown',
                                'langs': None,
                            },
                            'is_deleted': False,
                        }

                    # A little hokey, but for the RemoteApps that follow our expected namespacing we can lift
                    # the module and form names from the xmlns.
                    module_desc = xmlns.split('/')
                    form_name = self.get_unknown_form_name(xmlns, app_id=app_id if app_id else None, none_if_not_found=True)
                    if remote_xmlns:
                        module_name = module_desc[-2] if len(module_desc) > 1 else None
                        if not form_name:
                            form_name = module_desc[-1] if module_desc else None
                    else:
                        module_name = None

                    app_info.update({
                        'module': {
                            'names': module_name or "Unknown Module",
                            'id': module_name or "unknown_module",
                        },
                        'form': {
                            'names': form_name or "Unknown Name",
                            'id': form_name or 'unknown_form',
                        },
                        'xmlns': xmlns,
                    })
                    result[form] = app_info
        return result