コード例 #1
0
ファイル: __init__.py プロジェクト: di445/server
    def get(self):

        if not os.environ["SERVER_SOFTWARE"].startswith('Development'):
            return

        # Delete all bridges and filters so that we have a fresh testing environment
        for bridge in GandalfBridge.all():
            bridge.delete()
    
        for filter in GandalfFilter.all():
            filter.delete()

        step = self.request.get("step")
        v = None

        if step == "creating_bridge":
            v = self.creating_bridge()
        elif step == "can_cross_empty_bridge":
            v = self.can_cross_empty_bridge()
        elif step == "can_cross_all_users_whitelist":
            v = self.can_cross_all_users_whitelist()
        elif step == "can_cross_all_users_blacklist":
            v = self.can_cross_all_users_blacklist()
        elif step == "can_cross_all_users_whitelist_and_blacklist":
            v = self.can_cross_all_users_whitelist_and_blacklist()
        elif step == "can_cross_all_users_inside_percentage":
            v = self.can_cross_all_users_inside_percentage()
        elif step == "can_cross_all_users_outside_percentage":
            v = self.can_cross_all_users_outside_percentage()

        self.response.out.write(json.dumps(v))
コード例 #2
0
ファイル: __init__.py プロジェクト: johnfelipe/server
    def can_cross_empty_bridge(self):
        bridge_name = "balrog"
        filter_type = "all-users"

        bridge = GandalfBridge.get_or_insert(bridge_name)

        return gandalf(bridge_name)
コード例 #3
0
ファイル: __init__.py プロジェクト: di445/server
    def can_cross_empty_bridge(self):
        bridge_name = "balrog"
        filter_type = "all-users"

        bridge = GandalfBridge.get_or_insert(bridge_name)

        return gandalf(bridge_name)
コード例 #4
0
ファイル: __init__.py プロジェクト: johnfelipe/server
    def get(self):

        if not os.environ["SERVER_SOFTWARE"].startswith('Development'):
            return

        # Delete all bridges and filters so that we have a fresh testing environment
        for bridge in GandalfBridge.all():
            bridge.delete()

        for filter in GandalfFilter.all():
            filter.delete()

        step = self.request.get("step")
        v = None

        if step == "creating_bridge":
            v = self.creating_bridge()
        elif step == "can_cross_empty_bridge":
            v = self.can_cross_empty_bridge()
        elif step == "can_cross_all_users_whitelist":
            v = self.can_cross_all_users_whitelist()
        elif step == "can_cross_all_users_blacklist":
            v = self.can_cross_all_users_blacklist()
        elif step == "can_cross_all_users_whitelist_and_blacklist":
            v = self.can_cross_all_users_whitelist_and_blacklist()
        elif step == "can_cross_all_users_inside_percentage":
            v = self.can_cross_all_users_inside_percentage()
        elif step == "can_cross_all_users_outside_percentage":
            v = self.can_cross_all_users_outside_percentage()

        self.response.out.write(json.dumps(v))
コード例 #5
0
ファイル: __init__.py プロジェクト: di445/server
    def can_cross_all_users_blacklist(self):
        bridge_name = "balrog"
        filter_type = "all-users"

        bridge = GandalfBridge.get_or_insert(bridge_name)

        GandalfFilter(bridge=bridge, filter_type=filter_type, whitelist=False).put()

        return gandalf(bridge_name)
コード例 #6
0
    def can_cross_all_users_blacklist(self):
        bridge_name = "balrog"
        filter_type = "all-users"

        bridge = GandalfBridge.get_or_insert(bridge_name)

        GandalfFilter(bridge=bridge, filter_type=filter_type, whitelist=False).put()

        return gandalf(bridge_name)
コード例 #7
0
ファイル: api.py プロジェクト: di445/server
    def get(self):

        if not can_control_gandalf():
            return

        bridges = GandalfBridge.all().fetch(900)

        context = {
            "bridges": bridges,
        }

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(jsonify(context))
コード例 #8
0
    def get(self):

        if not can_control_gandalf():
            return

        bridges = GandalfBridge.all().fetch(900)

        context = {
            "bridges": bridges,
        }

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(jsonify(context))
コード例 #9
0
ファイル: __init__.py プロジェクト: di445/server
    def can_cross_all_users_outside_percentage(self):
        bridge_name = "balrog"
        filter_type = "all-users"

        bridge = GandalfBridge.get_or_insert(bridge_name)

        filter = GandalfFilter(bridge=bridge, filter_type=filter_type, whitelist=True)
        filter.put()

        identity_percentage = BridgeFilter._identity_percentage(filter.key())

        filter.percentage = identity_percentage
        filter.put()

        return gandalf(bridge_name)
コード例 #10
0
    def can_cross_all_users_outside_percentage(self):
        bridge_name = "balrog"
        filter_type = "all-users"

        bridge = GandalfBridge.get_or_insert(bridge_name)

        filter = GandalfFilter(bridge=bridge, filter_type=filter_type, whitelist=True)
        filter.put()

        identity_percentage = BridgeFilter._identity_percentage(filter.key())

        filter.percentage = identity_percentage
        filter.put()

        return gandalf(bridge_name)
コード例 #11
0
ファイル: cache.py プロジェクト: lindsaymacvean/KhanAcademy
    def load_from_datastore():
        gandalf_cache = GandalfCache()

        bridges = GandalfBridge.all()

        for bridge in bridges:

            key = bridge.key().name()

            gandalf_cache.bridges[key] = db.model_to_protobuf(bridge).Encode()

            filters = bridge.gandalffilter_set

            gandalf_cache.filters[key] = []

            for filter in filters:
                gandalf_cache.filters[key].append(db.model_to_protobuf(filter).Encode())

        memcache.set(GandalfCache.MEMCACHE_KEY, gandalf_cache)

        return gandalf_cache
コード例 #12
0
ファイル: cache.py プロジェクト: stefanojames/KhanLatest
    def load_from_datastore():
        gandalf_cache = GandalfCache()

        bridges = GandalfBridge.all()

        for bridge in bridges:

            key = bridge.key().name()

            gandalf_cache.bridges[key] = db.model_to_protobuf(bridge).Encode()

            filters = bridge.gandalffilter_set

            gandalf_cache.filters[key] = []

            for filter in filters:
                gandalf_cache.filters[key].append(db.model_to_protobuf(filter).Encode())

        memcache.set(GandalfCache.MEMCACHE_KEY, gandalf_cache)

        return gandalf_cache
コード例 #13
0
    def post(self):

        if not can_control_gandalf():
            return

        action = self.request.get('action')
        bridge_name = self.request.get('bridge_name')

        if not bridge_name:
            raise Exception("Must include 'bridge_name' parameter")

        bridge = GandalfBridge.get_or_insert(bridge_name)

        if action == 'delete':
            bridge.delete()

        context = {
            "success": True,
        }

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(jsonify(context))
コード例 #14
0
ファイル: api.py プロジェクト: di445/server
    def post(self):

        if not can_control_gandalf():
            return

        action = self.request.get('action')
        bridge_name = self.request.get('bridge_name')

        if not bridge_name:
            raise Exception("Must include 'bridge_name' parameter")

        bridge = GandalfBridge.get_or_insert(bridge_name)

        if action == 'delete':
            bridge.delete()

        context = {
            "success": True,
        }

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(jsonify(context))
コード例 #15
0
    def get(self):

        if not can_control_gandalf():
            return

        bridge_name = self.request.get('bridge_name')

        if not bridge_name:
            raise Exception("Must include 'bridge_name' parameter")

        bridge = GandalfBridge.get_by_key_name(bridge_name)

        if not bridge:
            raise Exception("Bridge '%s' does not exist" % bridge_name)

        filters = bridge.gandalffilter_set

        whitelist_filters = filter(lambda f: f.whitelist, filters)
        blacklist_filters = filter(lambda f: not f.whitelist, filters)

        if whitelist_filters:
            whitelist_filters[0].whitelist_message = True

        if blacklist_filters:
            blacklist_filters[0].blacklist_message = True

        filters = whitelist_filters + blacklist_filters

        context = {
            'filters': filters,
            'filter_types': BridgeFilter.get_filter_types(),
            'bridge': bridge,
        }

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(jsonify(context))
コード例 #16
0
ファイル: api.py プロジェクト: di445/server
    def get(self):

        if not can_control_gandalf():
            return

        bridge_name = self.request.get('bridge_name')

        if not bridge_name:
            raise Exception("Must include 'bridge_name' parameter")

        bridge = GandalfBridge.get_by_key_name(bridge_name)

        if not bridge:
            raise Exception("Bridge '%s' does not exist" % bridge_name)

        filters = bridge.gandalffilter_set

        whitelist_filters = filter(lambda f: f.whitelist, filters)
        blacklist_filters = filter(lambda f: not f.whitelist, filters)

        if whitelist_filters:
            whitelist_filters[0].whitelist_message = True

        if blacklist_filters:
            blacklist_filters[0].blacklist_message = True

        filters = whitelist_filters + blacklist_filters

        context = {
            'filters': filters,
            'filter_types': BridgeFilter.get_filter_types(),
            'bridge': bridge,
        }

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(jsonify(context))
コード例 #17
0
    def post(self):

        if not can_control_gandalf():
            return

        action = self.request.get('action')

        if action == "new":

            filter_type = self.request.get('filter_type')
            bridge_name = self.request.get('bridge_name')
            whitelist = self.request.get('whitelist') == "1"

            if not filter_type:
                raise Exception("Must include 'filter_type' parameter")

            if not bridge_name:
                raise Exception("Must include 'bridge_name' parameter")

            bridge = GandalfBridge.get_by_key_name(bridge_name)

            if not bridge:
                raise Exception("Bridge '%s' does not exist" % bridge_name)

            context = BridgeFilter.find_subclass(filter_type).initial_context()

            filter = GandalfFilter(bridge=bridge,
                                   filter_type=filter_type,
                                   context=context,
                                   whitelist=whitelist)
            filter.put()

        else:

            filter_key = self.request.get('filter_key')

            if not filter_key:
                raise Exception("Must include 'filter_key' parameter")

            filter = GandalfFilter.get(filter_key)

            if action == "delete":

                filter.delete()

            elif action == "save":

                try:
                    percentage = int(self.request.get('percentage'))

                    if 0 <= percentage <= 100:
                        filter.percentage = percentage

                except ValueError:
                    pass

                for key in filter.context:
                    value = self.request.get(key)
                    if value is not None:
                        filter.context[key] = value

                filter.put()

        context = {
            "success": True,
        }

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(jsonify(context))
コード例 #18
0
ファイル: __init__.py プロジェクト: derekzhang79/khan-website
    def can_cross_empty_bridge(self):
        bridge_name = "balrog"

        GandalfBridge.get_or_insert(bridge_name)

        return gandalf(bridge_name)
コード例 #19
0
ファイル: api.py プロジェクト: di445/server
    def post(self):

        if not can_control_gandalf():
            return

        action = self.request.get('action')

        if action == "new":

            filter_type = self.request.get('filter_type')
            bridge_name = self.request.get('bridge_name')
            whitelist = self.request.get('whitelist') == "1"

            if not filter_type:
                raise Exception("Must include 'filter_type' parameter")

            if not bridge_name:
                raise Exception("Must include 'bridge_name' parameter")

            bridge = GandalfBridge.get_by_key_name(bridge_name)

            if not bridge:
                raise Exception("Bridge '%s' does not exist" % bridge_name)

            context = BridgeFilter.find_subclass(filter_type).initial_context()

            filter = GandalfFilter(bridge=bridge, filter_type=filter_type, context=context, whitelist=whitelist)
            filter.put()

        else:

            filter_key = self.request.get('filter_key')

            if not filter_key:
                raise Exception("Must include 'filter_key' parameter")

            filter = GandalfFilter.get(filter_key)

            if action == "delete":

                filter.delete()

            elif action == "save":

                try:
                    percentage = int(self.request.get('percentage'))

                    if 0 <= percentage <= 100:
                        filter.percentage = percentage

                except ValueError:
                    pass

                for key in filter.context:
                    value = self.request.get(key)
                    if value is not None:
                        filter.context[key] = value

                filter.put()

        context = {
            "success": True,
        }

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(jsonify(context))