
    Ah                     X    d dl Z d dlmZ d dl d dlmZ  G d dej                        Zy)    N)Response)*)cmf_webhookc                   D    e Zd Zed        Zedd       Zed        Zd Zy)
CmfWebhookc                     t         j                  dd      5  t        j                  j	                  d      }|s&t        j                  ddd      j                         }d d d        |S # 1 sw Y   S xY w)	Nz&CmfLock:CmfWebhook:create_person_group   )timeoutwebhook)codeTu   Webhook группа)r   systemname)cmfutilCmfLockmodelsCmfPersonGroupgetsave)clsgroups     *./modules/automation/models/cmf_webhook.pywebhook_person_groupzCmfWebhook.webhook_person_group
   sr    __EPR_S 	o))--9-=E--9TPf-glln	o 		o s   A	A++A5Nc                    t         j                  j                  d      }|r^t        j                  j                  |      }t        j                  j                  ||      }t        j                  d| d| d       |S y )Ntoken)webhook_token_hashfieldsz CmfWebhook.token_person: person(z) by token_hash())requestargsr   r   	CmfPerson
hash_tokengdebug)r   r   r   
token_hashtoken_persons        r   get_token_personzCmfWebhook.get_token_person   sv      )))44U;J!++//:V\/]LGG6|nDTU_T``abc	     c                    t         j                  dt         j                   dt        j                          t        j                  j                  d      }|s#t         j                  d       t        ddd      S g d	}| j                  ||
      }|s| j                  ||      }|s*t         j                  d|        t        d| ddd      S |j                  t         j                  k7  rAt         j                  d|j                   dt         j                          t        ddd      S |j                         }|S )NzCmfWebhook.cls_call: person z, args: r   z(CmfWebhook.cls_call: webhook name absentzwebhook name absent  
text/plaincontent_type)	hook_type
token_user	eval_code	eval_fileeval_file_pathr   r   )r   r   z/CmfWebhook.cls_call: webhook not found by name webhook 
 not found  z(CmfWebhook.cls_call: webhook token_user z mismatch current_person znot authorized. Show error logi  )	r"   r#   current_personr   r   r   r   r.   call)r   webhook_namer   r   responses        r   cls_callzCmfWebhook.cls_call   s!   	.q/?/?.@WX||''/GG>@13\RRX''|F';gg<g?GGGEl^TUh|nJ?S_``!1!11GG''.'9'9&::STUTdTdSegh <sQ]^^<<>r'   c                    | j                   dv rt        j                  j                  d      }|s't        j                  d|  d       t        ddd      S t        j                  j                  |d	d
g      }|s-t        j                  d|  d|        t        d| ddd      S |j                  | k7  rFt        j                  d|  d|  d|j                          t        d|  d|j                   dd      S |j                         }|S | j                   dk(  r| j                         }d|i}|S | j                   dk(  rt        j                  j                  d      t        j                  j                  d      }}|dvr-t        j                  d|  d|        t        d| ddd      S t        j                  j                  t        j                   j#                  |            }|s.t        j                  d|  d| d       t        d| ddd      S 	 t%        t        j                  j&                  |j(                  g        dd| d!i}|S t        j                  d|  d&| j                           t        d'd$d      S # t*        $ r6}t        j-                  d|  d"|        t        d#| d$d      cY d%}~S d%}~ww xY w)(ug   Без полиморфного наследования мало смысла в этом методе)githubgitlabpluginzCmfWebhook.call(z): plugin code absentzplugin arg absentr)   r*   r+   typer   r2   z): plugin notfound by code zplugin code=r4   r5   z): webhook z mismatch plugin.webhook r3   bzPythonresultevagit_synceventrepo)pushz): unsupported event zUnsupported event: .i  )urlz): repo zRepo )r   z synced successfullyz): zRepo sync error: i  Nz): unsupported hook_type z&Unsupported hook_type. Show error log.)r-   r   r   r   r"   r#   r   r   CmfPluginGitr   webhook_calleval_bzpythonloggingwarningCmfEvagitRepourllibparseunquoteschedule_deferred_job	sync_repoid	Exception	exception)selfplugin_coder>   rA   rC   repo_urlrD   es           r   r7   zCmfWebhook.call1   s   >>11!,,**84K*4&0EFG 3S|TT((,,+vyFY,ZF*4&0KK=YZ,{m: FZfgg~~%&tf -  $v%>v~~>NPQ  tf$=fnn=MNPSbnp p((*F2 1 ^^z)'')F'F, + ^^},%ll..w79I9I&9Q8EJ&"24&8MeW UV"5eWA >R^__''++0D0DX0N+OD"24&
* UV%z <cP\]]Y%f&:&:&D&DDGG;W"eH:5I$JK  GG&tf,EdnnEUVWDsYeff  Y!!$4TF#aS"AB"3A3 7<XXYs   #8J 	K+K
K
K)N)__name__
__module____qualname__classmethodr   r&   r:   r7    r'   r   r   r   	   sA           **r'   r   )rN   flaskr   cmf.includemodules.automation.fieldsr   r   r^   r'   r   <module>rb      s%       1R'' Rr'   