def runTest(self): """ Tests the Role object. """ try: u = User(username='******', fullname='test test', email='*****@*****.**', super_admin=True, disabled=False) PluginChannel(name='test', plugin=Plugin(name='role_plugin', activated='no'), subscription_right='restricted') c = PluginChannel.selectBy(name="test").getOne() r = Role(user=u, channel=c, permission_level=UserPermissions.channel_contributor) assert_true(r != None) assert_true( r.permission_level == UserPermissions.channel_contributor) r.permission_level = UserPermissions.channel_administrator assert_true( r.permission_level == UserPermissions.channel_administrator) Role.delete(r.id) role = Role.selectBy(user=u, channel=c).getOne(None) assert_true(role == None) PluginChannel.delete(c.id) User.delete(u.id) except DuplicateEntryError: assert_true(False)
def POST(self): form = web.input() subject = form['subject'] email_body = form['body'] to = form['to'] receivers = [] if to=="admins": receivers =[u for u in User.selectBy(admin=True, disabled=False)] elif to=="supadmins": receivers=[u for u in User.selectBy(super_admin=True).distinct()] elif to == 'contrib': id_channel=form['select_channel'] c = PluginChannel.get(id_channel) receivers = [u for u in c.get_contribs()] elif to=="channel_editor_users": pc = PluginChannel.select() for elem in pc: if elem.plugin.name=="editor": l1=[u1 for u1 in elem.get_admins()] l2=[u2 for u2 in elem.get_contribs()] list_users = l1+l2 receivers=[u for u in list_users] else: for s in Screen.select(): receivers=[u for u in s.owners] try: for u in receivers: web.sendmail(web.config.smtp_sendername, u.email, subject, email_body, headers={'Content-Type': 'text/html;charset=utf-8'}) except smtplib.SMTPException: logger.error('An error occured when sending email ', exc_info=True) return web.seeother("/")
def runTest(self): """ Tests the ChannelBundle SQLObject """ fake_plugin = Plugin.byName('fake_plugin') fake_plugin.cache_activated_default = False pc1 = PluginChannel(name='Channel1', plugin=fake_plugin, subscription_right='public') pc2 = PluginChannel(name='Channel2', plugin=fake_plugin, subscription_right='public') pc3 = PluginChannel(name='Channel3', plugin=fake_plugin, subscription_right='public') channel_bundle = ChannelBundle(name='Channel Bundle', subscription_right='public') channel_bundle2 = ChannelBundle(name='Channel Bundle 2', subscription_right='public') channel_bundle3 = ChannelBundle(name='Channel Bundle 3', subscription_right='public') # Test basic functionality channel_bundle.add_channel(pc1) channel_bundle.add_channel(pc1) channel_bundle.add_channel(pc2) channel_bundle.add_channel(pc2) channel_bundle.add_channel(pc3) channel_bundle.add_channel(pc3) assert list(channel_bundle.flatten()) == [pc1, pc2, pc3] channel_bundle.remove_channel(pc2) assert list(channel_bundle.flatten()) == [pc1, pc3] bundle_content = [ self.ictv_app.plugin_manager.get_plugin_content(pc) for pc in channel_bundle.flatten() ] channels_content = [ self.ictv_app.plugin_manager.get_plugin_content(pc1), self.ictv_app.plugin_manager.get_plugin_content(pc3) ] for content1, content2 in zip(bundle_content, channels_content): capsule1 = content1[0] capsule2 = content2[0] assert capsule1 == capsule2 channel_bundle.remove_channel(pc2) channel_bundle.remove_channel(pc3) channel_bundle.remove_channel(pc1) assert list(channel_bundle.flatten()) == [] assert channel_bundle.get_type_name() == 'Bundle' # Test cycle detection channel_bundle.add_channel(channel_bundle2) channel_bundle2.add_channel(channel_bundle3) with pytest.raises(ValueError): channel_bundle3.add_channel(channel_bundle) with pytest.raises(ValueError): channel_bundle.add_channel(channel_bundle)
def _pre_app_start(self): self.channel = PluginChannel( plugin=Plugin.selectBy(name='editor').getOne(), name='Editor API', subscription_right='public') self.channel2 = PluginChannel( plugin=Plugin.selectBy(name='editor').getOne(), name='Editor API 2', subscription_right='public', plugin_config={ 'enable_rest_api': True, 'api_key': 'aaaaaaaa' })
def assert_no_creation(status=200): assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy( name=channel_params['name']).getOne(None) is None assert ChannelBundle.selectBy( name=bundle_params['name']).getOne(None) is None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy( name=bundle_params['name']).getOne(None) is None
def assert_edition(attrs=None, channel_params=channel_params, bundle_params=bundle_params, status=200): if attrs is None: attrs = [ 'name', 'description', 'enabled', 'subscription_right', 'plugin' ] assert self.testApp.post('/channels', params=channel_params, status=status).body is not None pc = PluginChannel.get(self.pc1.id) for attr in attrs: if attr in channel_params: assert get_attr(pc, attr) == channel_params[attr] assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None bc = ChannelBundle.get(self.bundle.id) for attr in attrs: if attr in bundle_params: assert get_attr(bc, attr) == bundle_params[attr] if channel_params is not orig_plugin_channel_params and bundle_params is not orig_bundle_params: assert_edition(channel_params=orig_plugin_channel_params, bundle_params=orig_bundle_params) # Revert
def runTest(self): """ Tests the channel details page. """ PluginChannel(name='A', plugin=Plugin(name='fake_plugin', activated='notfound'), subscription_right='public') self.channels_1() self.channels_1_request()
def assert_deletion(channel_params=channel_params, bundle_params=bundle_params, status=200): assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy(id=pc1_id).getOne(None) is None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy(id=bundle_id).getOne(None) is None return (PluginChannel(plugin=self.fake_plugin, name='PC 1', subscription_right='public').id, ChannelBundle(name='Bundle', subscription_right='public').id)
def runTest(self): """ Tests the ChannelRenderer page. """ Channel.deleteMany(None) fake_plugin = Plugin.byName('fake_plugin') plugin_channel = PluginChannel(plugin=fake_plugin, name='This is a cool channel', subscription_right='public') body = self.testApp.get(plugin_channel.get_preview_link(), status=200).body assert b'This is a cool channel' in body assert b"Reveal.toggleAutoSlide(true);" in body assert self.testApp.get(plugin_channel.get_preview_link() + 'incorrect_secret', status=403) assert self.testApp.get('/preview/channels/%d/incorrect_secret' % (plugin_channel.id + 42), status=404)
def setUp(self, fake_plugin_middleware=lambda: None, ictv_middleware=lambda: None): super().setUp(fake_plugin_middleware, ictv_middleware) building = Building(name="mytestbuilding") self.screen = Screen(name="mytestscreen", building=building, secret="secret") self.other_screen = Screen(name="myothertestscreen", building=building, secret="secret") self.plugins = [Plugin(name="%s%d" % (self.plugin_name, i), activated="yes") for i in range(self.n_elements - 1)] self.plugins.append(Plugin.selectBy(name="fake_plugin").getOne()) self.plugin_channels = [PluginChannel(name="%s%d" % (self.plugin_channel_name, i), plugin=self.plugins[i], subscription_right="public") for i in range(self.n_elements)] self.bundle_channels = [ChannelBundle(name="%s%d" % (self.bundle_channel_name, i), subscription_right="public") for i in range(self.n_elements)] other_channel = PluginChannel(name="other_channel", plugin=self.plugins[0], subscription_right="public") User(email=self.user_nothing_email, disabled=False) User(email=self.user_administrator_email, disabled=False, admin=True) User(email=self.user_super_administrator_email, disabled=False, admin=True, super_admin=True) screen_owner = User(email=self.user_screen_owner_email, disabled=False) self.screen.safe_add_user(screen_owner) other_screen_owner = User(email=self.user_other_screen_owner_email, disabled=False) self.other_screen.safe_add_user(other_screen_owner) contributor = User(email=self.user_contributor_email, disabled=False) [plugin_channel.give_permission_to_user(contributor) for plugin_channel in self.plugin_channels] contributor_other_channel = User(email=self.user_contributor_of_other_channel_email, disabled=False) other_channel.give_permission_to_user(contributor_other_channel) administrator_other_channel = User(email=self.user_administrator_of_other_channel_email, disabled=False) other_channel.give_permission_to_user(administrator_other_channel, UserPermissions.channel_administrator) channel_admin = User(email=self.user_channel_admin_email, disabled=False) [plugin_channel.give_permission_to_user(channel_admin, UserPermissions.channel_administrator) for plugin_channel in self.plugin_channels]
def create_database(): Building.createTable() Channel.createTable() Plugin.createTable() User.createTable() PluginChannel.createTable() ChannelBundle.createTable() Role.createTable() Screen.createTable() ScreenMac.createTable() Subscription.createTable() Template.createTable() Asset.createTable() PluginParamAccessRights.createTable() LogStat.createTable() DBVersion.createTable() DBVersion(version=database_version) User(username="******", fullname="ICTV Admin", email="admin@ictv", super_admin=True, disabled=False)
def setUp(self): super(ChannelsPageTestCase, self).setUp() Channel.deleteMany(None) self.fake_plugin = Plugin.byName('fake_plugin') self.pc1 = PluginChannel(plugin=self.fake_plugin, name='PC 1', subscription_right='public') self.pc2 = PluginChannel(plugin=self.fake_plugin, name='PC 2', subscription_right='public') self.pc3 = PluginChannel(plugin=self.fake_plugin, name='PC 3', subscription_right='public') self.bundle = ChannelBundle(name='Bundle', subscription_right='public') self.building = Building(name='Building') self.screen = Screen(name='Screen', building=self.building) self.user_nothing = User(email='nothing@localhost', disabled=False) self.user_contrib = User(email='contrib@localhost', disabled=False) self.pc1.give_permission_to_user(self.user_contrib, UserPermissions.channel_contributor) self.user_chan_admin = User(email='chan_admin@localhost', disabled=False) self.user_chan_admin2 = User(email='chan_admin2@localhost', disabled=False) self.pc1.give_permission_to_user(self.user_chan_admin, UserPermissions.channel_administrator) self.pc2.give_permission_to_user(self.user_chan_admin2, UserPermissions.channel_administrator) self.user_screen_admin = User(email='screen_admin@locahost', disabled=False) self.screen.safe_add_user(self.user_screen_admin) self.user_admin = User(email='admin@localhost', disabled=False, admin=True) self.user_super_admin = User(email='super_admin@localhost', disabled=False, admin=True, super_admin=True) self.users = [ self.user_nothing, self.user_contrib, self.user_chan_admin, self.user_chan_admin2, self.user_screen_admin, self.user_admin, self.user_super_admin ]
def assert_no_edition(status=200): assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert orig_plugin_channel == repr(PluginChannel.get(self.pc1.id)) assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert orig_bundle_channel == repr( ChannelBundle.get(self.bundle.id))
def get_content(channel_id): channel = PluginChannel.get(channel_id) logger_extra = {'channel_name': channel.name, 'channel_id': channel.id} logger = get_logger('github_reader', channel) token = channel.get_config_param('token') duration = channel.get_config_param('duration') * 1000 repo_url = channel.get_config_param('repo_url') had_organization = channel.get_config_param('had_organization') number_organizations = channel.get_config_param('number_organizations') orga_url = channel.get_config_param('orga_url') disp_commits = channel.get_config_param('disp_commits') number_commits = channel.get_config_param('number_commits') max_days_commit = channel.get_config_param('max_days_commit') disp_contributors = channel.get_config_param('disp_contributors') number_contributors = channel.get_config_param('number_contributors') disp_issues = channel.get_config_param('disp_issues') number_issues = channel.get_config_param('number_issues') disp_stat = channel.get_config_param('disp_stat') disp_releases = channel.get_config_param('disp_releases') number_releases = channel.get_config_param('number_releases') if not token or not repo_url: logger.warning('Some of the required parameters are empty', extra=logger_extra) return [] git_obj = Github(token) capsule = GithubReaderCapsule() #if disp_stat: # stat = git_obj.get_stat() if disp_issues: capsule._slides.append( GithubReaderSlideIssue(repo_url, number_issues, duration, git_obj, logger, logger_extra)) if disp_commits: capsule._slides.append( GithubReaderSlideCommit(repo_url, number_commits, duration, git_obj, max_days_commit, logger, logger_extra)) if disp_releases: capsule._slides.append( GithubReaderSlideRelease(repo_url, number_releases, duration, git_obj, logger, logger_extra)) if disp_contributors: capsule._slides.append( GithubReaderSlideContributor(repo_url, number_contributors, duration, git_obj, logger, logger_extra)) if had_organization: capsule._slides.append( GithubReaderSlideOrganization(orga_url, number_organizations, duration, git_obj, logger, logger_extra)) return [capsule]
def setUp(self): super().setUp() self.building_id = Building(name=self.building_name).id self.building2_id = Building(name=self.second_building_name).id self.channel = PluginChannel(name=self.channel_name, plugin=Plugin(name="dummy", activated="notfound"), subscription_right="public") User(email=self.user_nothing_email, disabled=False) User(email=self.user_administrator_email, disabled=False, admin=True) User(email=self.user_super_administrator_email, disabled=False, admin=True, super_admin=True) contributor = User(email=self.user_contributor_email, disabled=False) self.channel.give_permission_to_user(contributor) channel_admin = User(email=self.user_channel_admin_email, disabled=False) self.channel.give_permission_to_user( channel_admin, UserPermissions.channel_administrator)
def runTest(self): """ Tests the cache mecanism. """ u = User(username='******', fullname='testasset test', email='*****@*****.**', super_admin=True, disabled=False) PluginChannel(name='testasset2', plugin=Plugin(name='cache_plugin', activated='no'), subscription_right='restricted') c = PluginChannel.selectBy(name="testasset2").getOne() a = Asset(plugin_channel=c, user=u) self.testApp.get('/cache/' + str(a.id), status=303) try: Asset.delete(a.id) except SQLObjectNotFound: pass finally: User.delete(u.id) PluginChannel.delete(c.id)
def invalidate_cache(channel_id): channel = PluginChannel.get(channel_id) file_hash = get_file_hash(channel_id, channel.get_config_param('link')) _, full_iframe_path, _, full_inlined_page_path = get_paths(file_hash) def safe_rm(path): if os.path.exists(path): os.remove(path) safe_rm(full_iframe_path) safe_rm(full_inlined_page_path)
def assert_no_deletion(channel_params=channel_params, bundle_params=bundle_params, status=200): assert self.testApp.post('/channels', params=channel_params, status=status).body is not None assert PluginChannel.selectBy(id=pc1_id).getOne(None) is not None assert self.testApp.post('/channels', params=bundle_params, status=status).body is not None assert ChannelBundle.selectBy( id=bundle_id).getOne(None) is not None
def _get_screens_number(self): """ Return the number of screens that are subscribed to channels of this plugin. """ plugin_channels = PluginChannel.select().filter( PluginChannel.q.plugin == self) screens = set(plugin_channels.throughTo.subscriptions.throughTo.screen. distinct()) bundles = set(c for c in ChannelBundle.select() if any(bc.plugin == self for bc in c.flatten())) for b in bundles: screens |= set(Subscription.select().filter( Subscription.q.channel == b).throughTo.screen.distinct()) return len(screens)
def post(self): form = self.form subject = form['subject'] email_body = form['body'] to = form['to'] receivers = [] if to == "admins": receivers = [u for u in User.selectBy(admin=True, disabled=False)] elif to == "supadmins": receivers = [u for u in User.selectBy(super_admin=True).distinct()] elif to == 'contrib': id_channel = form['select_channel'] c = PluginChannel.get(id_channel) receivers = [u for u in c.get_contribs()] elif to == "channel_editor_users": pc = PluginChannel.select() for elem in pc: if elem.plugin.name == "editor": l1 = [u1 for u1 in elem.get_admins()] l2 = [u2 for u2 in elem.get_contribs()] list_users = l1 + l2 receivers = [u for u in list_users] else: for s in Screen.select(): receivers = [u for u in s.owners] try: mail = Mail(self.app) msg = Message( recipients=[u.email for u in receivers], subject=subject, body=email_body, extra_headers={'Content-Type': 'text/html;charset=utf-8'}) mail.send(msg) except smtplib.SMTPException: logger.error('An error occured when sending email ', exc_info=True) resp.seeother("/")
def runTest(self): """ Tests the Asset SQLObject. """ fake_plugin = Plugin(name='fake_plugin', activated='notfound') asset_channel = PluginChannel(name='Asset Channel', plugin=fake_plugin, subscription_right='public') a1 = Asset(plugin_channel=asset_channel, user=None, filename='path_test', extension='.txt') last_ref_a1 = a1.last_reference time.sleep(1) assert a1.path == os.path.join('static', 'storage', str(asset_channel.id), str(a1.id) + '.txt') assert a1.last_reference > last_ref_a1 a2 = Asset(plugin_channel=asset_channel, user=None, filename='path_test') assert a2.path == os.path.join('static', 'storage', str(asset_channel.id), str(a2.id)) a3 = Asset(plugin_channel=asset_channel, user=None, filename='cache_test', in_flight=True) a3_path = os.path.join('static', 'storage', str(asset_channel.id), str(a3.id)) assert a3.path is None assert a3._get_path(force=True) == a3_path a3.in_flight = False assert a3.path == a3_path a4 = Asset(plugin_channel=asset_channel, user=None, filename='test_write', extension='.txt') a4_path = os.path.join(get_root_path(), 'static', 'storage', str(asset_channel.id), str(a4.id) + '.txt') a4_content = 'a4 file content'.encode() a4.write_to_asset_file(a4_content) with open(a4_path, 'rb') as f: assert f.read() == a4_content a4.destroySelf() assert not os.path.exists(a4_path)
def runTest(self): """ Tests the Role SQLObject """ Channel.deleteMany(None) fake_plugin = Plugin(name='fake_plugin', activated='notfound') plugin_channel = PluginChannel(name='Plugin Channel', plugin=fake_plugin, subscription_right='public') user = User(fullname='User', email='test@localhost') role = Role(user=user, channel=plugin_channel, permission_level=UserPermissions.channel_administrator) assert role._SO_get_permission_level() == 'channel_administrator' assert role.permission_level == UserPermissions.channel_administrator role.permission_level = UserPermissions.channel_contributor assert role._SO_get_permission_level() == 'channel_contributor' assert role.permission_level == UserPermissions.channel_contributor
def wrapper(*args, **kwargs): app = flask.current_app if len(flask.g.homepath)>0: # we are in a sub-app channelid = re.findall(r'\d+', flask.g.homepath)[0] else: channelid = re.findall(r'\d+', flask.request.path)[0] channel = PluginChannel.get(channelid) u = User.get(app.session['user']['id']) if 'real_user' in app.session: real_user = User.get(app.session['real_user']['id']) # if the real user has at least the same right as the "logged as" user if u.highest_permission_level not in real_user.highest_permission_level: resp.seeother('/logas/nobody') if UserPermissions.administrator in u.highest_permission_level or permission_level in channel.get_channel_permissions_of(u): kwargs['channel'] = channel return func(*args, **kwargs) else: resp.forbidden()
def render_page(self, channel_id): channel = PluginChannel.get(channel_id) con = sqlhub.threadConnection select_query = Select(['mime_type', 'SUM(file_size)'], where=Asset.q.plugin_channel == channel_id, staticTables=['asset'], groupBy='mime_type') labels = [] data = [] for type, size in con.queryAll(con.sqlrepr(select_query)): labels.append(type) data.append(int(size)) palette = [(0.86, 0.37119999999999997, 0.33999999999999997), (0.86, 0.7612000000000001, 0.33999999999999997), (0.56880000000000008, 0.86, 0.33999999999999997), (0.33999999999999997, 0.86, 0.50120000000000009), (0.33999999999999997, 0.82879999999999987, 0.86), (0.33999999999999997, 0.43879999999999986, 0.86), (0.63119999999999976, 0.33999999999999997, 0.86), (0.86, 0.33999999999999997, 0.69879999999999964)] background_color = [] border_color = [] for R,G,B in palette: background_color.append('rgba(%d, %d, %d, 0.95)' % (int(R*255), int(G*255), int(B*255))) border_color.append('rgba(%d, %d, %d, 1)' % (int(R*255), int(G*255), int(B*255))) chart_data = {'labels': labels, 'datasets': [{'data': data, 'backgroundColor': background_color}]} return self.renderer.storage_channel(channel=channel, chart_data=json.dumps(chart_data))
def runTest(self): fake_plugin = Plugin.byName('fake_plugin') user = User(fullname='User', email='test@localhost') assert fake_plugin.channels_number == 0 pc1 = PluginChannel(plugin=fake_plugin, name='Plugin Channel 1', subscription_right='public') assert fake_plugin.channels_number == 1 pc2 = PluginChannel(plugin=fake_plugin, name='Plugin Channel 2', subscription_right='public') assert fake_plugin.channels_number == 2 pc2.destroySelf() assert fake_plugin.channels_number == 1 pc2 = PluginChannel(plugin=fake_plugin, name='Plugin Channel 2', subscription_right='public') pc3 = PluginChannel(plugin=fake_plugin, name='Plugin Channel 3', subscription_right='public') bundle_channel = ChannelBundle(name='Bundle', subscription_right='public') bundle_channel.add_channel(pc3) building = Building(name='building') screen1 = Screen(name='Screen1', building=building) screen2 = Screen(name='Screen2', building=building) screen3 = Screen(name='Screen3', building=building) assert fake_plugin.screens_number == 0 screen1.subscribe_to(user, pc1) assert fake_plugin.screens_number == 1 screen1.subscribe_to(user, pc2) assert fake_plugin.screens_number == 1 screen2.subscribe_to(user, pc3) assert fake_plugin.screens_number == 2 screen2.subscribe_to(user, bundle_channel) assert fake_plugin.screens_number == 2 screen3.subscribe_to(user, bundle_channel) assert fake_plugin.screens_number == 3
def wrapper(*args, **kwargs): app = web.ctx.app_stack[0] if len(web.ctx.homepath) > 0: # We are in a sub-app channelid = re.findall(r'\d+', web.ctx.homepath)[0] else: # We are in the core app channelid = re.findall(r'\d+', web.ctx.path)[0] channel = PluginChannel.get(channelid) u = User.get(app.session['user']['id']) if 'real_user' in app.session: real_user = User.get(app.session['real_user']['id']) # if the real user has at least the same right as the "logged as" user if u.highest_permission_level not in real_user.highest_permission_level: raise web.seeother('/logas/nobody') if UserPermissions.administrator in u.highest_permission_level or permission_level in channel.get_channel_permissions_of( u): kwargs['channel'] = channel return func(*args, **kwargs) else: raise web.forbidden()
def get_content(channel_id): channel = PluginChannel.get(channel_id) logger_extra = {'channel_name': channel.name, 'channel_id': channel.id} logger = get_logger('i_like_trains', channel) departure_station = channel.get_config_param('departure_station') duration = channel.get_config_param('duration')*1000 language = channel.get_config_param('language') nb_train = channel.get_config_param('nb_train') logo_1 = channel.get_config_param('logo_1') if not departure_station: logger.warning('Problem with the departure station', extra=logger_extra) return [] else: base_url = "http://api.irail.be/" head = {'user-agent': 'ICTVbooyy/0.69 (ictv.github.con; [email protected])'} payload = {'station': departure_station, 'arrdep': 'departures', 'lang': language, 'format': 'json', 'alert': 'true'} r = requests.get(base_url + 'liveboard/', params=payload, headers=head) parsed = json.loads(r.text) return [ILikeTrainsCapsule(departure_station, duration, language, nb_train, parsed, logo_1)]
class BuildingTestCase(ICTVTestCase): building_name = "AlreadyThereBuilding" second_building_name = "AlreadyThereBuilding2" user_nothing_email = "*****@*****.**" user_contributor_email = "*****@*****.**" user_channel_admin_email = "*****@*****.**" user_administrator_email = "*****@*****.**" user_super_administrator_email = "*****@*****.**" channel_name = "mytestchannel" def setUp(self): super().setUp() self.building_id = Building(name=self.building_name).id self.building2_id = Building(name=self.second_building_name).id self.channel = PluginChannel(name=self.channel_name, plugin=Plugin(name="dummy", activated="notfound"), subscription_right="public") User(email=self.user_nothing_email, disabled=False) User(email=self.user_administrator_email, disabled=False, admin=True) User(email=self.user_super_administrator_email, disabled=False, admin=True, super_admin=True) contributor = User(email=self.user_contributor_email, disabled=False) self.channel.give_permission_to_user(contributor) channel_admin = User(email=self.user_channel_admin_email, disabled=False) self.channel.give_permission_to_user( channel_admin, UserPermissions.channel_administrator) def tearDown(self): try: Building.delete(self.building_id) Building.delete(self.building2_id) except SQLObjectNotFound: pass for email in [ self.user_nothing_email, self.user_contributor_email, self.user_channel_admin_email, self.user_administrator_email, self.user_super_administrator_email ]: User.deleteBy(email=email) self.channel.destroySelf() Plugin.deleteBy(name="dummy") super().tearDown()
def get_content(channelid, capsuleid=None) -> Iterable[PluginCapsule]: content = [] channel = PluginChannel.get(channelid) if 0 < len(channel.get_config_param('api_key') or '') < 8: raise MisconfiguredParameters( 'api_key', channel.get_config_param('api_key'), "The key must be at least 8-character long") if capsuleid is None: now = datetime.now() capsules = EditorCapsule.selectBy(channel=channelid).filter( AND(EditorCapsule.q.validity_to > now, EditorCapsule.q.validity_from < now)).orderBy("c_order") for c in capsules: content.append(c.to_plugin_capsule()) else: content = [EditorCapsule.get(capsuleid).to_plugin_capsule()] for capsule in content: for slide in capsule.get_slides(): if channel.get_config_param( 'force_duration') or slide.duration == -1: slide.duration = int( channel.get_config_param('duration') * 1000) return content
def authenticate(self): """ Authenticates the request according to the API key and returns the channel. """ if len(web.ctx.homepath) > 0: # We are in a sub-app channelid = re.findall(r'\d+', web.ctx.homepath)[0] else: # We are in the core app channelid = re.findall(r'\d+', web.ctx.path)[0] try: channel = PluginChannel.get(channelid) except SQLObjectNotFound: raise web.notfound() try: if not channel.get_config_param('enable_rest_api'): raise web.forbidden() if not (channel.get_config_param('api_key') or '').strip(): raise web.forbidden() if (channel.get_config_param('api_key') or '').strip() != web.ctx.env.get( 'HTTP_X_ICTV_EDITOR_API_KEY', '').strip(): raise web.forbidden() except KeyError: raise web.forbidden() return channel