Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
61ede65
Update channel.py
LouisLombaert Dec 14, 2021
90bd8ad
Chgmt mongo certif pour usage perso
creativezigzz Dec 14, 2021
4b90f5e
ajout id channel
creativezigzz Dec 14, 2021
1810753
Update channel.py
LouisLombaert Dec 14, 2021
b4c07c0
Chgmt mongo certif pour usage perso
creativezigzz Dec 14, 2021
6ed3808
ajout id channel
creativezigzz Dec 14, 2021
f4e17ac
Ajout de l'id unique + group
LouisLombaert Dec 15, 2021
7ffb02f
Génere l'id automatiquement
LouisLombaert Dec 15, 2021
0e3bd8b
id à la place de identifier
LouisLombaert Dec 15, 2021
ee893ba
modif pour que ça corresponde avec Channel
LouisLombaert Dec 15, 2021
bf0bae8
ajout message pour db
creativezigzz Dec 15, 2021
48c122d
Merge remote-tracking branch 'origin/develop' into develop
creativezigzz Dec 15, 2021
633e301
ajout de la ligne pour le group
LouisLombaert Dec 18, 2021
e37bfa3
Merge branch 'develop' of https://github.com/creativezigzz/noyau_devI…
creativezigzz Dec 19, 2021
83a5acc
Chgmt dans plusieurs fichiers pour l'ajout de messages dans la db.
creativezigzz Dec 19, 2021
ea9665e
récupération des team de la db fonctionnelle
vbrichant Dec 21, 2021
0800bb7
Ajout d'un channel dans la DB + récupération dans channelContainer du…
vbrichant Dec 21, 2021
ca2953f
Ajout d'un nouvel utilisteur a la db non fonctionnel (faire update)
vbrichant Dec 22, 2021
5916188
Ajout d'un nouvel utilisteur a la db non fonctionnel (faire update)
vbrichant Dec 22, 2021
99017e2
Ajout d'un id persistant dans la db pour les channels
vbrichant Dec 22, 2021
f7d4334
Test de récupération de la conversation sur la DB
NathanGregoar Dec 22, 2021
a9ce712
Merge remote-tracking branch 'origin/develop' into develop
vbrichant Dec 22, 2021
e9ebdc1
Ajout d'un id persistant dans la db pour les channels
vbrichant Dec 22, 2021
ddf63ec
ajout d'un nouveau channel
LouisLombaert Dec 22, 2021
284074b
indentation
LouisLombaert Dec 23, 2021
5ad2533
correction depot_id
vbrichant Dec 23, 2021
7086520
Ajout de docstring
vbrichant Dec 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 119 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@

from kivy.app import App
from kivy.lang import Builder
from pymongo import MongoClient

import src.config.config as config
import pymongo as pymongo
import os

from src.models.mongo_connector import MongoConnector
from src.models.screens_manager import ScreensManager
Expand All @@ -38,6 +35,119 @@

Builder.load_file("{0}/common.kv".format(config.VIEWS_DIR))

def verification_collection():
try:
with MongoConnector() as connector:
print(connector.db.list_collection_names())
# print(connector.db["messages"].find_one())
#delete = connector.db["teams"].delete_many({})
#print(delete.deleted_count, " documents deleted.")
if connector.db["teams"].find_one() is None:
print("team est vide")
set_collection_team()
if connector.db["group"].find_one() is None:
print("groupe est vide")
# set_collection_group()
if connector.db["channel"].find_one() is None:
print("channel est vide")
# set_collection_channel()
for x in connector.db["teams"].find():
print(x)

try:
with MongoConnector() as connector:
collection = connector.db["messages"].find()
for document in collection:
print(document)
except Exception as e:
print(e)

except Exception as e:
print(e)


def set_collection_team():
# données qui sont en Db utilisé lors de la recréation de la collection
data = [{
"_id": "0000000",
"data": {
"name": "Pis",
"icon_path": "",
"participants": [
{"pseudo": "SerialMatcher"},
{"pseudo": "Bilou"},
{"pseudo": "Babar"},
{"pseudo": "Jacques"},
],
"channels": [
{"id": "a11b4ee7-8743-4607-b838-acc1298a5f7a",
"name": "pis",
"admin": "Bilou",
"group": "group_test1",
"membres": [{"pseudo": "SerialMatcher"},
{"pseudo": "Jacques"}]},
{"id": "a11b4ee7-8743-4607-b838-acc1298a5fer",
"name": "channel_de_test1",
"admin": "Bilou",
"group": "group_test1",
"membres": [{"pseudo": "SerialMatcher"},
{"pseudo": "Jacques"}]},
{"id": "a11b4ee7-8743-4607-b838-acc1298arrr",
"name": "channel_de_test2",
"admin": "Bilou",
"group": "group_test2",
"membres": [{"pseudo": "SerialMatcher"},
{"pseudo": "Jacques"}]},
{"id": "a11b4ee7-8743-4607-b838-acc1298a5f7b",
"name": "channel_de_test3",
"admin": "Bilou",
"group": "group_test2",
"membres": [{"pseudo": "SerialMatcher"},
{"pseudo": "Jacques"},
{"pseudo": "SerialMatcher"}]}
]
}
}]
data2 = [{
"_id": "0000001",
"data": {
"name": "Pan",
"icon_path": "",
"participants": [
{"pseudo": "SerialMatcher"},
{"pseudo": "Bilou"},
{"pseudo": "Babar"},
{"pseudo": "Jacques"},
],
"channels": [
{"id": "b816ef54-7a5c-448a-972c-78267ae371c6",
"name": "channel_de_test1",
"admin": "Bilou",
"group": "group_test1",
"membres": [{"pseudo": "SerialMatcher"},
{"pseudo": "Jacques"}]},
{"id": "b816ef54-7a5c-448a-972c-78267ae371az",
"name": "channel_de_test2",
"admin": "Bilou",
"group": "group_test1",
"membres": [{"pseudo": "SerialMatcher"},
{"pseudo": "Jacques"}]},
{"id": "b816ef54-7a5c-448a-972c-78267ae371tb",
"name": "channel_de_test3",
"admin": "Bilou",
"group": "group_test2",
"membres": [{"pseudo": "SerialMatcher"},
{"pseudo": "Babar"}]}
]
}}]
try:
with MongoConnector() as connector:
db = connector.db
collection = db["teams"]
collection.insert_many(data)
collection.insert_many(data2)
except Exception as e:
print(e)

class Main(App):
title = 'EpheCom'
Expand All @@ -49,21 +159,24 @@ def build(self):
landing_screen = LandingScreen()
sm.add_widget(landing_screen)
sm.current = "landing"
verification_collection()
landing_screen.set_teams_list()
return sm


class Personne:
def __init__(self, nom):
self.nom = nom


class Etudiant(Personne):
def __init__(self, nom):
super(Etudiant, self).__init__(nom)


if __name__ == '__main__':
print("Bienvenue sur notre projet commun !")

Main().run()



2 changes: 1 addition & 1 deletion public/tmp_conversations/basic.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"data": [{"timestamp": "2021-10-01 21:58:21.075475", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-01 21:58:32.330007", "msg": "Salut", "sender": "Moi"}, {"timestamp": "2021-10-03 12:55:32.306144", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 12:55:43.099751", "msg": "a\na\na\na\na\na\na\na\na\na\na\n\na", "sender": "Moi"}, {"timestamp": "2021-10-03 12:56:34.275552", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 12:57:49.856594", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 12:59:15.629024", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:01:03.803355", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:01:46.966697", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:05:15.440522", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:05:45.345969", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:05:53.198908", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-03 13:21:15.583061", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-04 09:27:18.978075", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-04 09:27:25.558585", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-07 10:02:06.651348", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-07 13:45:56.442165", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-11 09:43:20.736492", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-11 09:43:32.269041", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-11 11:40:05.051486", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-11 11:40:25.364092", "msg": "/help", "sender": "Moi"}]}
{"data": [{"timestamp": "2021-10-01 21:58:21.075475", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-01 21:58:32.330007", "msg": "Salut", "sender": "Moi"}, {"timestamp": "2021-10-03 12:55:32.306144", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 12:55:43.099751", "msg": "a\na\na\na\na\na\na\na\na\na\na\n\na", "sender": "Moi"}, {"timestamp": "2021-10-03 12:56:34.275552", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 12:57:49.856594", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 12:59:15.629024", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:01:03.803355", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:01:46.966697", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:05:15.440522", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:05:45.345969", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-03 13:05:53.198908", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-03 13:21:15.583061", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-04 09:27:18.978075", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-04 09:27:25.558585", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-07 10:02:06.651348", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-07 13:45:56.442165", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-11 09:43:20.736492", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-10-11 09:43:32.269041", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-11 11:40:05.051486", "msg": "/hello", "sender": "Moi"}, {"timestamp": "2021-10-11 11:40:25.364092", "msg": "/help", "sender": "Moi"}, {"timestamp": "2021-12-14 17:35:30.549367", "msg": "Hey", "sender": "Moi"}, {"timestamp": "2021-12-14 17:38:40.114880", "msg": "Hey", "sender": "Moi"}]}
14 changes: 13 additions & 1 deletion public/views/channel.kv
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,16 @@
id: channels_content
cols: 1
spacing: 2
size_hint_y: None
size_hint_y: None

<ParticipantContainer@ScrollView>
# Attention, ceci est du code brut, vous devez le dynamiser !

do_scroll_x: False
do_scroll_y: True

GridLayout:
id: member_content
cols: 1
spacing: 2
size_hint_y: None
91 changes: 74 additions & 17 deletions src/models/channel.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,94 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import uuid

from src.models.group import Group

"""
Ce fichier contient une classe représentant un channel.
----- CODE DE LA CLASSE A IMPLEMENTER -----
"""

from src.models.mongo_connector import MongoConnector


class ParamNotFoundException(Exception):
pass


class Channel:
def __init__(self, identifier, name, group, icon_path=None, participants=None):
self.identifier = identifier
self.name = name
self.group = group
self.icon_path = icon_path
self.participants = participants
"""class to create a new channel, it can add and remove members to this channel"""

def join(self):
def __init__(self, channel_id: str, channel_name: str, channel_admin: str, group: Group, channel_members: list, chat_history=None):
"""create a new channel based on a name, an administrator, some members and a chat history"""
"""
Méthode permettant à un utilisateur de rejoindre ce channel.
PRE : channel_name and channel_admin are strings, group is Group, channel_members and chat_history are lists of strings
POST : a new Channel object is created
"""
pass
if chat_history is None:
chat_history = []
# self.id = uuid.uuid4() # génère un id aléatoire (et unique)
self.channel_id = channel_id
self.channel_name = channel_name
self.channel_admin = channel_admin
self.group = group

self.channel_members = channel_members # pour moi channel_members serait une
# liste de string (comme ça on peut ajouter et supprimer des membres facilement
# ajout automatique de l'admin dans la liste des membres
self.channel_members.append({"pseudo": self.channel_admin})
self.chat_history = chat_history # même chose que pour channel_members
try:
with MongoConnector() as connector:
self.__collection = connector.db["chat"]

def leave(self):
except Exception as error:
print(error)

def send_to_db(self):
"""send the channel to the database"""
"""
Méthode permettant à un utilisateur de quitter ce channel.
PRE :
POST : the channel is sent to the database
"""
pass
query = {
"channel_name": self.channel_name,
"channel_admin": self.channel_admin,
"channel_members": self.channel_members,
"chat_history": self.chat_history
}
self.__collection.insert_one(query)

def get_participants_status(self):
pass
def add_member(self, member):
"""add a new member to the channel"""
"""
PRE : member is a string
POST : member is added to the list of members of the channel
"""
self.channel_members.append(member)
query = {"channel_id": self.channel_id}
new_member = {"$set": {
"channel_members": self.channel_members
}}
self.__collection.update_one(query, new_member)

def get_message_history(self):
pass
def remove_member(self, member):
"""remove a member from the channel, it remove all the members that have the pseudo member"""
"""
PRE : member is a string that is in the list channel_members
POST : all the element 'member' of the list channel_members are removed
RAISE : paramNotFoundException if member is not in channel_members
"""
if member not in self.channel_members:
raise ParamNotFoundException(Exception)
self.channel_members = [i for i in self.channel_members if i != member] # permet de supprimer chaque élément
# member de la liste (même si il revient plsrs fois), remove ne supprime que la premiere occurrence
query = {"channel_name": self.channel_name}
member_to_remove = {"$set": {
"channel_members": self.channel_members
}}
self.__collection.update_one(query, member_to_remove)

def send_message(self):
def mute_group(self):
pass
6 changes: 3 additions & 3 deletions src/models/group.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import uuid
"""
Ce fichier contient une classe représentant un groupe.
----- CODE DE LA CLASSE A IMPLEMENTER -----
"""


class Group:
def __init__(self, gid, name):
self.gid = gid
def __init__(self, name):
self.gid = uuid.uuid4()
self.name = name
45 changes: 35 additions & 10 deletions src/models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,52 @@
import json

from src.config import config
from src.models.mongo_connector import MongoConnector
import uuid


# pour l'auto increment

class Message:
def __init__(self, timestamp, msg, sender):

def __init__(self, timestamp, msg, sender, channel_id, is_edited=False):
self.timestamp = timestamp
self.msg = msg
self.sender = sender
self.is_edited = is_edited
self._id = uuid.uuid4()
self.channel_id = channel_id

try:
with MongoConnector() as connector:
self.__collection = connector.db["messages"]
except Exception as e:
print(e)

def db_formatting(self):
return {
"_id": self._id,
"timestamp": str(self.timestamp),
"msg": self.msg,
"sender": self.sender
"sender": self.sender,
"is_edited": self.is_edited,
"channel_id": self.channel_id
}

def send_to_db(self):
conv_file_path = config.PUBLIC_DIR + "/tmp_conversations/basic.json"
with open(conv_file_path) as json_file:
conv = json.load(json_file)

conv["data"].append(self.db_formatting())

with open(conv_file_path, 'w') as outfile:
json.dump(conv, outfile)
# conv_file_path = config.PUBLIC_DIR + "/tmp_conversations/basic.json"
# with open(conv_file_path) as json_file:
# conv = json.load(json_file)
#
# conv["data"].append(self.db_formatting())
#
# with open(conv_file_path, 'w') as outfile:
# json.dump(conv, outfile)
self.__collection.insert_one(self.db_formatting())

def update_msg(self, new_msg):

self.__collection.find_one_and_update(self.msg_id, {'msg': new_msg})

def delete_db(self):
self.__collection.delete_one(self.msg_id)
2 changes: 1 addition & 1 deletion src/models/mongo_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MongoConnector:
"""

def __init__(self):
certificat_path = config.ROOT_DIR + "/certif_mongo.pem"
certificat_path = config.ROOT_DIR + "/2TM1-G3.pem"
uri = "mongodb+srv://cluster0.5i6qo.gcp.mongodb.net/ephecom?authSource=%24external&authMechanism=MONGODB-X509&retryWrites=true&w=majority&ssl_cert_reqs=CERT_NONE"
client = MongoClient(uri,
tls=True,
Expand Down
Loading