def add_authorization(user_id, channel_id, permission): auth = Authorization() auth.user_id = user_id auth.channel_id = channel_id auth.permission = permission db.session.add(auth) db.session.commit()
def authorizations(): if request.method == "GET": if session["admin"]: rw_channels = Channel.query.all() ro_channels = [] else: channels = Channel.query.join(Authorization).filter( Authorization.user_id == session["user_id"]) rw_channels = Channel.query.join(Authorization).filter( Authorization.user_id == session["user_id"]).filter( Authorization.permission == Permission.MODERATOR.value).all() ro_channels = Channel.query.join(Authorization).filter( Authorization.user_id == session["user_id"]).filter( Authorization.permission == Permission.AUTHOR.value).all() return render_template("authorizations.html", rw_channels=rw_channels, ro_channels=ro_channels, permissions=Permission) elif request.method == "POST": i = 1 while i <= (round(len(request.form) / 3)): user_id = request.form.get('username' + str(i)) if user_id is not "": channel_id = request.form.get('channel_id' + str(i)) permission = request.form.get('permission' + str(i)) a = Authorization(channel_id=channel_id, user_id=user_id, permission=permission) print(a) db.session.add(a) i = i + 1 edit_list = [[elem, elem.split('#')] for elem in request.form if elem.startswith("permission_edit")] for e in edit_list: auth = request.form.get(e[0]) chan_id = e[1][2] user = e[1][1] a = Authorization.query.filter( Authorization.user_id == user, Authorization.channel_id == chan_id).first() a.permission = auth db.session.commit() return redirect(url_for('authorizations.authorizations'))
def test_is_moderator(): user = User(id=1, name="test", first_name="utilisateur", email="*****@*****.**") db.session.add(user) u = User.query.get(1) assert is_moderator(u) == False a= Authorization(channel_id=1,user_id=1,permission=2) db.session.add(a) assert is_moderator(u) == True
def test_get_moderate_channels_for_user(): u = User.query.get(1) channel = Channel(name="test", module=get_module_full_name("mail"), config="{}") db.session.add(channel) assert get_moderate_channels_for_user(u) is not None user = User(id=2, name="test", first_name="utilisateur2", email="*****@*****.**") db.session.add(user) assert len(get_moderate_channels_for_user(user)) == 0 a = Authorization(channel_id=1, user_id=2, permission=2) db.session.add(a) assert len(get_moderate_channels_for_user(user)) == 1
def test_search_unlogged_client_post_search(client): create_user(id="test", name="test", first_name="utilisateur", email="*****@*****.**") create_channel("test_search", "mail", {'sender': 'noOne', 'receiver': 'noOne'}) a = Authorization(channel_id=1, user_id="test", permission=2) db.session.add(a) r = client.post("http://127.0.0.1:5000/search_post", data={ "subject": "", "body": "", "sorted": "" }) assert r.status_code == 403 # 200
def test_search_publishing_valid_client(client): create_user(id="test", name="test", first_name="utilisateur", email="*****@*****.**") create_channel("test_search", "mail", {'sender': 'noOne', 'receiver': 'noOne'}) a = Authorization(channel_id=1, user_id="test", permission=2) db.session.add(a) login(client, "test") r = client.post("http://127.0.0.1:5000/search_publishings", data={ "subject": "", "body": "", "author": "", "channels": "test" }) assert r.status_code == 200 # 403
def test_search_unlogged_client_publishing_search(client): user = User(id=6, name="test", first_name="utilisateur", email="*****@*****.**") db.session.add(user) channel = Channel(name="test", module=get_module_full_name("TestTwitter"), config="{}") db.session.add(channel) a = Authorization(channel_id=1, user_id=6, permission=2) db.session.add(a) r = requests.post("http://127.0.0.1:5000/search_publishings", { "subject": "", "body": "", "author": "", "channels": "test" }) assert int(r.status_code) == 403
def setup_db(channelName, pluginName): global user_admin myself_user = db.session.query(User).get('myself') if not myself_user: myself_user = create_user(id="myself", name="myself", first_name="myself", email="myself") user_admin = myself_user.admin myself_user.admin = 1 id_channel = 0 channel = Channel(id=id_channel, name=channelName, module=pluginName, config="{}") db.session.add(channel) authorization = Authorization(user_id="myself", channel_id=id_channel, permission=2) db.session.add(authorization) id_post = 0 post = Post( id=id_post, user_id="myself", title="first title", description= "That know ask case sex ham dear her spot. Weddings followed the all marianne nor whatever settling. Perhaps six prudent several her had offence. Did had way law dinner square tastes. Recommend concealed yet her procuring see consulted depending. Adieus hunted end plenty are his she afraid. Resources agreement contained propriety applauded neglected use yet. ", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-07-01"), date_until=datetime_converter("2018-07-01")) db.session.add(post) try: db.session.commit() except Exception as e: print(str(e)) db.session.rollback() return id_channel, id_post
def test_edit_new_publishing(client): login(client, "myself") channel = Channel(id=0, name="test", module=get_module_full_name("mail"), config="{}") db.session.add(channel) a = Authorization(channel_id=channel.id, user_id="myself", permission=1) db.session.add(a) db.session.commit() datadict = dict(titlepost='A new test post', descriptionpost="A description", linkurlpost="http://www.test.com", imagepost="image.jpg", datefrompost="2018-07-01", dateuntilpost="2018-07-01") datadict[str(channel.name) + '_titlepost'] = "mail title" datadict[str(channel.name) + '_descriptionpost'] = 'mail description' datadict[str(channel.name) + '_linkurlpost'] = "http://www.test.com" datadict[str(channel.name) + '_imagepost'] = "image.jpg" datadict[str(channel.name) + '_datefrompost'] = "2018-07-01" datadict[str(channel.name) + '_dateuntilpost'] = "2018-07-01" rv = client.post('/new', data=datadict) assert rv.status_code == 302 posts = db.session.query(Post).all() last_add = posts[-1] url = '/edit/publish_edit_post/' + str(last_add.id) datadict2 = dict(title='An edited test post', description="A description", link_url="http://www.test.com", image="image.jpg", date_from="2018-07-01", date_until="2018-07-01") datadict3 = dict(title='mail title', description='edited mail description', date_from="2018-07-01", date_until="2018-07-01") rv = client.post(url, data=json.dumps([{ "name": "General", "fields": datadict2 }, { "name": "test", "fields": datadict3 }])) assert rv.status_code == 200 edited_posts = db.session.query(Post).all() assert len(posts) == len(edited_posts) edited_post = edited_posts[-1] assert edited_post.title == 'An edited test post' assert last_add.id == edited_post.id assert edited_post.description == "A description" edited_publishing = db.session.query(Publishing).filter( Publishing.post_id == last_add.id) assert edited_publishing[0].title == "mail title" assert edited_publishing[0].description == "edited mail description" # cleaning up db.session.query(Post).filter(Post.id == last_add.id).delete() db.session.query(Publishing).filter( Publishing.post_id == last_add.id).delete() db.session.delete(a) db.session.delete(channel) db.session.commit()
def create_auth(channel_id, user_id, permission): auth = Authorization(channel_id=channel_id, user_id=user_id, permission=permission) write_to_db(auth) return auth
def setup_db(): global user_admin myself_user = db.session.query(User).get('myself') user_admin = myself_user.admin myself_user.admin = 1 id_channels = [0, -1, -2] id_posts = [0, -1, -2] channel = Channel(id=id_channels[0], name="Test_channel_1", module="superform.plugins.Twitter", config="{}") db.session.add(channel) channel = Channel(id=id_channels[1], name="Test_channel_2", module="superform.plugins.Twitter", config="{}") db.session.add(channel) channel = Channel(id=id_channels[2], name="Test_channel_3", module="superform.plugins.Twitter", config="{}") db.session.add(channel) authorization = Authorization(user_id="myself", channel_id=id_channels[0], permission=2) db.session.add(authorization) authorization = Authorization(user_id="myself", channel_id=id_channels[1], permission=2) db.session.add(authorization) authorization = Authorization(user_id="myself", channel_id=id_channels[2], permission=2) db.session.add(authorization) post = Post(id=id_posts[0], user_id="myself", title="first title #123456789123456789123456789title", description="This is a test, yes it really is. #123456789123456789123456789descr", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-08-08"), date_until=datetime_converter("2018-08-10")) db.session.add(post) post = Post(id=id_posts[1], user_id="myself", title="first title #123456789123456789123456789title ", description="This is a test, yes it really is. #123456789123456789123456789descr", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-10-08"), date_until=datetime_converter("2018-11-10")) db.session.add(post) post = Post(id=id_posts[2], user_id="myself", title="first title #98765410987654321876543223456title notvisible", description="This is a test, yes it really is. #98765410987654321876543223456title notvisible", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-10-08"), date_until=datetime_converter("2018-11-10")) db.session.add(post) publishing = Publishing(post_id=id_posts[0], channel_id=id_channels[0], state=1, title="first title #123456789123456789123456789title published", description="This is a test, yes it really is. #123456789123456789123456789descr published", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-08-08"), date_until=datetime_converter("2018-08-10"), extra="{}") db.session.add(publishing) publishing = Publishing(post_id=id_posts[0], channel_id=id_channels[1], state=0, title="first title #123456789123456789123456789title waitingforapproval", description="This is a test, yes it really is. #123456789123456789123456789descr waitingforapproval", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-11-11"), date_until=datetime_converter("2018-11-12"), extra="{}") db.session.add(publishing) publishing = Publishing(post_id=id_posts[0], channel_id=id_channels[2], state=2, title="first title #123456789123456789123456789title archived", description="This is a test, yes it really is. #123456789123456789123456789descr archived", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-12-11"), date_until=datetime_converter("2018-12-12"), extra="{}") db.session.add(publishing) try: db.session.commit() except Exception as e: print(str(e)) db.session.rollback() return id_channels, id_posts
def populate_db(): User.query.delete() user = User(id="michouchou", email="*****@*****.**", name="t", first_name="est", admin=False) db.session.add(user) user = User(id="googleplusmoderator", email="*****@*****.**", name="Press F", first_name="To pay respect", admin=False) db.session.add(user) user = User(id="mr_inutile69", email="*****@*****.**", name="MR", first_name="PS", admin=False) db.session.add(user) user = User(id="channelwriter", email="*****@*****.**", name="Channel", first_name="von LECRIVAIN", admin=False) db.session.add(user) user = User(id="channelmoder", email="*****@*****.**", name="Channel", first_name="van Moderate", admin=False) db.session.add(user) user = User(id="admin", email="*****@*****.**", name="Admin", first_name="van Ze Broek", admin=True) db.session.add(user) Channel.query.delete() channel = Channel(id=1, name="Twitter", module="superform.plugins.Twitter", config="{}") db.session.add(channel) channel = Channel(id=2, name="GPlus", module="superform.plugins.Gplus", config="{}") db.session.add(channel) channel = Channel(id=3, name="RSS", module="superform.plugins.RSS", config="{}") db.session.add(channel) channel = Channel(id=4, name="GMoins", module="superform.plugins.Gmoins", config="{}") db.session.add(channel) Authorization.query.delete() authorization = Authorization(user_id="michouchou", channel_id=1, permission=1) db.session.add(authorization) authorization = Authorization(user_id="admin", channel_id=1, permission=2) db.session.add(authorization) authorization = Authorization(user_id="admin", channel_id=2, permission=2) db.session.add(authorization) authorization = Authorization(user_id="admin", channel_id=3, permission=2) db.session.add(authorization) authorization = Authorization(user_id="admin", channel_id=4, permission=2) db.session.add(authorization) authorization = Authorization(user_id="googleplusmoderator", channel_id=2, permission=2) db.session.add(authorization) authorization = Authorization(user_id="channelwriter", channel_id=4, permission=1) db.session.add(authorization) authorization = Authorization(user_id="channelmoder", channel_id=1, permission=2) db.session.add(authorization) authorization = Authorization(user_id="channelmoder", channel_id=3, permission=1) db.session.add(authorization) Post.query.delete() post = Post( id=1, user_id="channelmoder", title="first title", description= "That know ask case sex ham dear her spot. Weddings followed the all marianne nor whatever settling. Perhaps six prudent several her had offence. Did had way law dinner square tastes. Recommend concealed yet her procuring see consulted depending. Adieus hunted end plenty are his she afraid. Resources agreement contained propriety applauded neglected use yet. ", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-07-01"), date_until=datetime_converter("2018-07-01")) db.session.add(post) post = Post( id=2, user_id="michouchou", title="second title", description= "first title Him rendered may attended concerns jennings reserved now. Sympathize did now preference unpleasing mrs few. Mrs for hour game room want are fond dare. For detract charmed add talking age. Shy resolution instrument unreserved man few. She did open find pain some out. If we landlord stanhill mr whatever pleasure supplied concerns so. Exquisite by it admitting cordially september newspaper an. Acceptance middletons am it favourable.", link_url="http://twitter.com/", image_url="", date_from=datetime_converter("2018-11-13"), date_until=datetime_converter("2018-11-14")) db.session.add(post) post = Post( id=3, user_id="michouchou", title="third title", description= "Man request adapted spirits set pressed. Up to denoting subjects sensible feelings it indulged directly. We dwelling elegance do shutters appetite yourself diverted. Our next drew much you with rank. Tore many held age hold rose than our. She literature sentiments any contrasted. Set aware joy sense young now tears china shy. ", link_url="http://google.com/", image_url="de", date_from=datetime_converter("2018-11-15"), date_until=datetime_converter("2018-11-16")) db.session.add(post) post = Post(id=4, user_id="channelmoder", title="fourth nottitle", description="Man request adapted spirits set pressed. ", link_url="http://google.com/", image_url="", date_from=datetime_converter("2018-11-10"), date_until=datetime_converter("2018-11-17")) db.session.add(post) post = Post( id=5, user_id="michouchou", title="first title", description= "Not him old music think his found enjoy merry. Listening acuteness dependent at or an. Apartments thoroughly unsatiable terminated sex how themselves. She are ten hours wrong walls stand early. Domestic perceive on an ladyship extended received do. Why jennings our whatever his learning gay perceive.", link_url="http://youtube.com/", image_url="recherche", date_from=datetime_converter("2018-11-18"), date_until=datetime_converter("2018-11-19")) db.session.add(post) post = Post( id=7, user_id="channelmoder", title="lorem ipsum", description= "Add you viewing ten equally believe put. Separate families my on drawings do oh offended strictly elegance. Perceive jointure be mistress by jennings properly. An admiration at he discovered difficulty continuing. We in building removing possible suitable friendly on. ", link_url="http://instagram.com/", image_url="{}", date_from=datetime_converter("2018-11-20"), date_until=datetime_converter("2018-11-21")) db.session.add(post) post = Post(id=8, user_id="channelmoder", title="frè§iyu title", description="", link_url="", image_url="", date_from=datetime_converter("2018-11-22"), date_until=datetime_converter("2018-11-23")) db.session.add(post) post = Post( id=9, user_id="channelwriter", title="him men instrument saw", description= "It prepare is ye nothing blushes up brought. Or as gravity pasture limited evening on. Wicket around beauty say she. Frankness resembled say not new smallness you discovery. Noisier ferrars yet shyness weather ten colonel. Too him himself engaged husband pursuit musical.", link_url="http://linkedin.com/", image_url="http://wordpress.com/", date_from=datetime_converter("2018-11-24"), date_until=datetime_converter("2018-11-25")) db.session.add(post) post = Post(id=10, user_id="channelwriter", title="men instrument", description="", link_url="", image_url="", date_from=datetime_converter("2018-11-26"), date_until=datetime_converter("2018-11-27")) db.session.add(post) post = Post( id=11, user_id="channelwriter", title="", description= "Him rendered may attended concerns jennings reserved now. Sympathize did now preference unpleasing mrs few. Mrs for hour game room want are fond dare. For detract charmed add talking age. Shy resolution instrument unreserved man few. She did open find pain some out. ", link_url="http://wordpress.com/", image_url="sur", date_from=datetime_converter("2018-11-28"), date_until=datetime_converter("2018-11-29")) db.session.add(post) Publishing.query.delete() publishing = Publishing( post_id=1, channel_id=1, state=0, title="first title", description= "That know ask case sex ham dear her spot. Weddings followed the all marianne nor whatever settling. Perhaps six prudent several her had offence. Did had way law dinner square tastes. Recommend concealed yet her procuring see consulted depending. Adieus hunted end plenty are his she afraid. Resources agreement contained propriety applauded neglected use yet. ", link_url="http://facebook.com/", image_url="pas", date_from=datetime_converter("2018-11-11"), date_until=datetime_converter("2018-11-12"), extra="{}") db.session.add(publishing) publishing = Publishing( post_id=2, channel_id=1, state=1, title="second title", description= "first title Him rendered may attended concerns jennings reserved now. Sympathize did now preference unpleasing mrs few. Mrs for hour game room want are fond dare. For detract charmed add talking age. Shy resolution instrument unreserved man few. She did open find pain some out. If we landlord stanhill mr whatever pleasure supplied concerns so. Exquisite by it admitting cordially september newspaper an. Acceptance middletons am it favourable.", link_url="http://twitter.com/", image_url="", date_from=datetime_converter("2018-11-13"), date_until=datetime_converter("2018-11-14"), extra="{ce champs}") db.session.add(publishing) publishing = Publishing( post_id=3, channel_id=1, state=2, title="third title", description= "Man request adapted spirits set pressed. Up to denoting subjects sensible feelings it indulged directly. We dwelling elegance do shutters appetite yourself diverted. Our next drew much you with rank. Tore many held age hold rose than our. She literature sentiments any contrasted. Set aware joy sense young now tears china shy. ", link_url="http://google.com/", image_url="de", date_from=datetime_converter("2018-11-15"), date_until=datetime_converter("2018-11-16"), extra='{"est sans"}') db.session.add(publishing) publishing = Publishing( post_id=4, channel_id=1, state=0, title="fourth nottitle", description="Man request adapted spirits set pressed. ", link_url="http://google.com/", image_url="", date_from=datetime_converter("2018-11-10"), date_until=datetime_converter("2018-11-17"), extra="{'importance':mais}") db.session.add(publishing) publishing = Publishing( post_id=5, channel_id=1, state=1, title="first title", description= "Not him old music think his found enjoy merry. Listening acuteness dependent at or an. Apartments thoroughly unsatiable terminated sex how themselves. She are ten hours wrong walls stand early. Domestic perceive on an ladyship extended received do. Why jennings our whatever his learning gay perceive.", link_url="http://youtube.com/", image_url="recherche", date_from=datetime_converter("2018-11-18"), date_until=datetime_converter("2018-11-19"), extra="") db.session.add(publishing) publishing = Publishing( post_id=1, channel_id=3, state=0, title="lorem ipsum", description= "Add you viewing ten equally believe put. Separate families my on drawings do oh offended strictly elegance. Perceive jointure be mistress by jennings properly. An admiration at he discovered difficulty continuing. We in building removing possible suitable friendly on. ", link_url="http://instagram.com/", image_url="{}", date_from=datetime_converter("2018-11-11"), date_until=datetime_converter("2018-11-12"), extra="verifions") db.session.add(publishing) publishing = Publishing(post_id=7, channel_id=3, state=0, title="", description="", link_url="", image_url="", date_from=datetime_converter("2018-11-20"), date_until=datetime_converter("2018-11-21"), extra="{}") db.session.add(publishing) publishing = Publishing( post_id=8, channel_id=3, state=0, title="him men instrument saw", description= "It prepare is ye nothing blushes up brought. Or as gravity pasture limited evening on. Wicket around beauty say she. Frankness resembled say not new smallness you discovery. Noisier ferrars yet shyness weather ten colonel. Too him himself engaged husband pursuit musical.", link_url="http://linkedin.com/", image_url="http://wordpress.com/", date_from=datetime_converter("2018-11-22"), date_until=datetime_converter("2018-11-23"), extra="{}") db.session.add(publishing) publishing = Publishing(post_id=4, channel_id=3, state=2, title="men instrument", description="", link_url="", image_url="", date_from=datetime_converter("2018-11-10"), date_until=datetime_converter("2018-11-17"), extra="que ça n'as pas") db.session.add(publishing) publishing = Publishing( post_id=9, channel_id=4, state=1, title="", description= "Him rendered may attended concerns jennings reserved now. Sympathize did now preference unpleasing mrs few. Mrs for hour game room want are fond dare. For detract charmed add talking age. Shy resolution instrument unreserved man few. She did open find pain some out. ", link_url="http://wordpress.com/", image_url="sur", date_from=datetime_converter("2018-11-24"), date_until=datetime_converter("2018-11-25"), extra="[]") db.session.add(publishing) publishing = Publishing( post_id=10, channel_id=4, state=1, title="explained middleton am", description= "Entire any had depend and figure winter. Change stairs and men likely wisdom new happen piqued six. Now taken him timed sex world get. Enjoyed married an feeling delight pursuit as offered. As admire roused length likely played pretty to no. Means had joy miles her merry solid order. ", link_url="http://linkedin.com/", image_url="les images", date_from=datetime_converter("2018-11-26"), date_until=datetime_converter("2018-11-27"), extra="") db.session.add(publishing) publishing = Publishing( post_id=11, channel_id=4, state=2, title="first title", description= "Perhaps far exposed age effects. Now distrusts you her delivered applauded affection out sincerity. As tolerably recommend shameless unfeeling he objection consisted. She although cheerful perceive screened throwing met not eat distance.", link_url="http://youtube.com/", image_url="h", date_from=datetime_converter("2018-11-28"), date_until=datetime_converter("2018-11-29"), extra="'d'influence'") db.session.add(publishing)