Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
system_administration:infrastructure:module_manager [2022/09/18 14:50] – [fonctionnement du module] madjid | system_administration:infrastructure:module_manager [2022/09/18 15:24] (current) – removed madjid | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Module-Manager ====== | ||
- | ===== fonctionnement du module ===== | ||
- | Quand l’utilisateur clique sur le lien de téléchargement de l' | ||
- | La fonction download_attachement() sera lancé ,elle vérifie si le client à acheté le produit associé | ||
- | <code python> | ||
- | def download_attachment(self, | ||
- | # Check if this is a valid attachment id | ||
- | log.warning("########### | ||
- | attachment = request.env[' | ||
- | [(' | ||
- | [" | ||
- | ) | ||
- | if attachment: | ||
- | attachment = attachment[0] | ||
- | else: | ||
- | return redirect(self.orders_page) | ||
- | |||
- | # Check if the user has bought the associated product | ||
- | res_model = attachment[' | ||
- | res_id = attachment[' | ||
- | purchased_products = request.env[' | ||
- | |||
- | |||
- | if res_model == ' | ||
- | if res_id not in purchased_products: | ||
- | return redirect(self.orders_page) | ||
- | </ | ||
- | Aussi elle vérifie la pièce jointe (attachement) sur le module product.template | ||
- | <code python> | ||
- | # Also check for attachments in the product templates | ||
- | elif res_model == ' | ||
- | template_ids = request.env[' | ||
- | if res_id not in template_ids: | ||
- | return redirect(self.orders_page) | ||
- | |||
- | else: | ||
- | return redirect(self.orders_page) | ||
- | </ | ||
- | Si le type de l’attachement == ' | ||
- | <code python> | ||
- | data = [] | ||
- | # Get the list of product & append them in a list [name, version] | ||
- | for a in attachments: | ||
- | if a[' | ||
- | b = requests.get(f' | ||
- | log.warning(' | ||
- | data.append( | ||
- | { | ||
- | " | ||
- | " | ||
- | }) | ||
- | </ | ||
- | |||
- | Au niveau du serveur Module-manager: | ||
- | La fonction update_module_list() fait appel à la fonction module_populator(): | ||
- | <code python> def update_module_list(request, | ||
- | utils.modules_populator(Module, | ||
- | return JsonResponse({' | ||
- | </ | ||
- | La fonction **module_populator()** récupère la version du module et le nom du modele: | ||
- | * La fonction récupère la liste des modules depuis gitlab a traves la fonction **get_module_liste()** et vérifie si la version du module existe sur la liste | ||
- | * Si la version n' | ||
- | <code python> | ||
- | def modules_populator(model, | ||
- | """ | ||
- | Create Modules in The Local Database | ||
- | """ | ||
- | for module in get_module_list(version=version): | ||
- | # Check if module exists in the local database | ||
- | if not model.objects.filter( | ||
- | name=module, | ||
- | version=version | ||
- | ).exists(): | ||
- | model.objects.create( | ||
- | name=module, | ||
- | version=version | ||
- | ) | ||
- | </ | ||
- | la fonction **get_module_liste()** : | ||
- | <code python> | ||
- | def get_module_list(version): | ||
- | """ | ||
- | Fetch all the modules by Name & Version then return the it as a list | ||
- | """ | ||
- | | ||
- | repo_modules = f' | ||
- | get_modules_req = requests.get( | ||
- | repo_modules, | ||
- | headers=settings.HEADERS | ||
- | ).text | ||
- | |||
- | # GET ALL MODULES OF ELOAPPS REPOSITORY | ||
- | modules_list = [] | ||
- | for module in json.loads(get_modules_req): | ||
- | modules_list.append(module[' | ||
- | print(f" | ||
- | return modules_list | ||
- | </ | ||
- | |||
- | Après la mise à jour des modules sur le serveur module-manager et la vérification avec le dépôt Gitlab , on arrivera à l’étape de vérification du token de l' | ||
- | <code python> | ||
- | if user[' | ||
- | log.warning(' | ||
- | token_id = request.env[' | ||
- | token = token_id[0][' | ||
- | log.warning(' | ||
- | |||
- | # If the user doesn t have a token create a call to the url service to create | ||
- | # a access token () | ||
- | else : | ||
- | log.warning(' | ||
- | token = request.env[' | ||
- | log.warning(" | ||
- | </ | ||
- | La fonction **get_acces()** vérifie si l’utilisateur existe au niveau du serveur module-manager: | ||
- | * Sur le service module-manager la vérification de l' | ||
- | * Si l' | ||
- | * Si l' | ||
- | * Si l' | ||
- | * Si l' | ||
- | <code python> | ||
- | def get_access(self, | ||
- | url_user = " | ||
- | url = " | ||
- | url_token = " | ||
- | data = { | ||
- | ' | ||
- | ' | ||
- | } | ||
- | req_user =json.loads(requests.get(str(url_user)).text) | ||
- | #If the user exists in the server | ||
- | if req_user[' | ||
- | # | ||
- | if token : | ||
- | | ||
- | # | ||
- | else : | ||
- | | ||
- | token = self.env[' | ||
- | ' | ||
- | ' | ||
- | }) | ||
- | | ||
- | # | ||
- | else : | ||
- | req = json.loads(requests.post(url, | ||
- | token = self.env[' | ||
- | ' | ||
- | ' | ||
- | }) | ||
- | | ||
- | </ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- |