U
    ؎j3                  =   @   s  d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZ G dd dZd	hd
dddddddddddddddddhddddhd d!d"d#d$d%d&d'd(d)d*d+d,hd-d.d/d0hd1d2d3d4d5d6d7d8d9d:d;d<d=d>d?hd@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXhdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddddddddh6dddddddddh	ddddddddddddhdddddddhddddddddddddddddddddddddhddddhddddddddhdddddddddddddddddddddddddddddddddddddddddddddh-dddhdd ddhddddddd	d
hddddhdZddddddhZddddddhZdd e D Zed!dd:h dd e D Zdd e D Zed ed: ed? d d! e D Zd"Zd#d$ Zd%d& Zd.d)d*Zd+d, Zd-S (/      wraps)authenticatelogin)redirect_to_login)HttpResponseForbidden)redirect)RolePermissionUserProfilec                   @   s    e Zd ZdZdd Zdd ZdS )AdminLoginMiddlewarezFLegacy login middleware retained for compatibility with group_urls.py.c                 C   s
   || _ d S )N)get_response)selfr    r   4/var/www/html/crackeverytest/admin_app/middleware.py__init__   s    zAdminLoginMiddleware.__init__c                 C   s|   |j jsr|jdrr|jd}|jd}|rr|rrt|||d}|rr|jrrt|| t	|}|rjt
|S tdS | |S )Nz/adminusernamepassword)r   r   z/No admin module has been assigned to this user.)useris_authenticatedpath
startswithPOSTgetr   is_staffr   get_admin_landing_urlr   r   r   )r   requestr   r   r   landing_urlr   r   r   __call__   s    

zAdminLoginMiddleware.__call__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   r   	dashboardexam_categoryadd_exam_categoryedit_exam_categorydelete_exam_categoryexam_category_detaildelete_examitem
examMasteraddExameditExamdeleteExamById
AddSubjectsection_selct1exam_syllabusget_sub_sections
get_topicsadd_exam_syllabusupdate_strength_bulkexam_topicsfoundation_videos_listadd_foundation_videoedit_foundation_videodelete_foundation_videocoursescourse_createcourse_editzcreate-courseselect_exam_categorychange_category_statusdelete_coursechange_course_statusCourse_Students_listupdate_student_accessadd_on_course_listcreate_add_on_coursedelete_add_on_coursecourse_discountadd_course_discountedit_course_discountdelete_course_discountbatch_managementbatch_students	add_batch
edit_batchdelete_batch_by_Idchange_batch_statusremove_batchassign_batchgenerate_lecturessave_previewed_lecturesadd_batch_time_slotdelete_batch_slotsave_monthly_lecturesget_course_students_for_batchbulk_assign_batch_studentslive_LecturesaddLiveLecturedeleteLiveLecturebyIdeditLiveLectureuploadVideobyLectureIduploadZoomRecordingzoomRecordingJobStatusrecord_zoom_attendanceLecture_Detailslectures_timetable_htmlstudent_endTestverify_studentcounseling_groupsadd_counseling_groupedit_counseling_groupdelete_counseling_group_by_idcounseling_groups_detailadd_counseling_studentsdelete_counseling_student_by_idcounseling_schedule_listadd_counseling_scheduleedit_counseling_schedulecounseling_group_students delete_counseling_schedule_by_idcounseling_schedule_detailzquestion-bankzquestion-bank-listzadd-questionupload_excelupload_question_excelupload_question_wordupdate_question_tags_viewdownload_questions_wordadd_question_storeadd_mock_questionsfilter_questionssave_mock_questionseditquestionzdelete-questionzmock-test-listupdate_mock_statiscticcalculate_fullmock_statisctic calculate_advancemock_statiscticzmock-test-resultzview-solutionzmock-analysiszabc-analysisexam_section_analysisexam_filter_analysisstudent_analysisreset_student_examzadd-mockedit_mock_test	edit_mockdelete_mocksearch_mockadd_mocktestMockTestSeriesaddTestSerieseditTestSeriesdeleteMockTestSeriesvocabulary_questionsadd_vocab_questionedit_vocab_questiondelete_vocab_questionupload_vocab_excelupdate_question_ordercategory_selctquestion_tag_listadd_question_tagedit_question_tagdelete_question_tagget_mocktests_by_type"upload_question_explaination_videoregrade_edited_questions sync_question_explanation_videos'bulk_upload_question_explanation_videosquestion_video_upload_statusauto_tag_question_paragraphsStudents_listedit_studentdelete_studentblock_studentDevice_login_historyedit_login_is_lectureStudent_ProfileaddFollowUpaddCommentsfaculty_moduleadd_facultyedit_facultydelete_faculty_by_Idfaculty_detailsadd_faculty_leavedelete_faculty_leaveedit_faculty_leaveadd_faculty_detailsadd_time_slotupdate_slot_prioritydelete_slotuser_role_managementdelete_user_roleadd_user_roleedit_user_roleuser_profile_listadd_user	edit_userdelete_leadLead_Student_ProfileLead_Managementupload_lead_excel	app_leads	Lead_ViewLead_followupaddLeadz	save-lead	edit_leadfailed_ordersCourse_enquiriesdelete_course_enquiriesContact_us_enquiriesdelete_Contact_us_enquirieslead_statusadd_lead_statusedit_lead_statusdelete_lead_statuslead_sourceadd_lead_sourceedit_lead_sourcedelete_lead_sourcesend_whatsapp_templateStudyMaterialAddStudyMaterialdeleteMaterialsEditStudyMaterial	resourcesaddResourcesdeleteResourceseditResourcesresourcesRcaddResourcesRcdeleteResourcesRceditResourcesRcsectionadd_sectionedit_sectiondelete_section_by_Idzsub-sectionadd_sub_sectionedit_sub_sectiondelete_sub_section_by_Idz
topic-list	add_topic
edit_topicSelect_section_topicdelete_topicsection_selctsubsection_selectblog_categoryadd_blog_categoryedit_blog_categorydelete_blog_categoryz
blogs-list	add_blogs
edit_blogsdelete_blogbanners
add_banneredit_bannerdelete_bannermediaaddMedia	editMediadeleteMediabyIdnotificationadd_notificationedit_notificationdelete_notificationtestimonialadd_testimonialedit_testimonialdelete_testimonialResults
add_resultedit_resultdelete_resultapp_notificationadd_app_notificationSelesChange_Statusseles_Detailscoupon_codeadd_couponsedit_coupondelete_couponreportsales_reportslead_conversion_reportget_courses_by_exampotential_sales_reportnot_enrolled_students_reportenrolled_reportselfprep_students_reportzoomkeysadd_zoomkeyedit_zoomkeydelete_zoomkey_by_Id)r"   r#   foundation_videosr9   rE   batcheslive_lecturestest_seriesstudentsr   
user_rolesleadsstudy_materialsr   contentsorderscouponsreports	zoom_keysadmin_loginlogin_processadmin_logoutcron_notify_lecturescron_motivationcron_mock_eventsacademicYearMasteraddAcademicYeareditAcademicYeardeleteAcademicYearexamValiditiessaveExamValiditiesc                 C   s(   h | ] }|D ]}|  d r|qqS ))addcreateuploadgeneratelowerr   .0namesnamer   r   r   	<setcomp>   s
     r<  c                 C   s(   h | ] }|D ]}|  d r|qqS ))deleteremover6  r8  r   r   r   r<     s
     c                 C   s(   h | ] }|D ]}|  d r|qqS ))editchangeupdateblockresetZregradeassignverifyrecordsaveZstudent_endZ	calculatesendr6  r8  r   r   r   r<     s
     c                 C   s    i | ]\}}|D ]
}||qqS r   r   )r9  feature_keyZ	url_namesurl_namer   r   r   
<dictcomp>   s
     rK  ))r#   z/admin/exam_category)r  z/admin/foundation-videos-list)r9   z/admin/courses)rE   z/admin/course-discount/)r  z/admin/batch_management)r  z/admin/live_lecture)r  z/admin/mock-test-list?type=1)r  z/admin/students)r   z/admin/faculty_module)r  z/admin/users-list/)r  z/admin/app_leads)r   z/admin/study-material)r   z/admin/resources)r!  z/admin/section)r"  z/admin/sales)r#  z/admin/coupons)r$  z/admin/reports/not-enrolled/)r%  z/admin/zoom-keys/c                 C   s|   | r
| j sd S | jrdS tjj| dddd }|s8d S ttjj|jdddj	ddd}t
D ]\}}||kr^|  S q^d S )	Nz/admin/dashboardActiveFr   statusZrole__statusZrole__is_deletedT)rolecan_viewfeature__is_deletedfeature__feature_key)flat)r   is_superuserr
   objectsfilterfirstsetr	   rO  values_listFEATURE_LANDING_URLS)r   profileZviewable_featuresrI  r   r   r   r   r      s4    

 
r   c                 C   s(   | t krdS | tkrdS | tkr$dS dS )Nr=  r?  r2  view)DELETE_URL_NAMESEDIT_URL_NAMESADD_URL_NAMES)rJ  r   r   r   _permission_action  s    r`  r\  Fc                    s   d|  fdd}|S )NZcan_c                    s   t   fdd}|S )Nc                    s   | j jst|  ddS | j jr0| f||S r<tdS tjj| j dddd	 }|r^ sftdS t
jjf |j dddi }|stdS | f||S )	Nz/admin/login)	login_urlz/You do not have permission to access this page.rL  FrM  )rO  rR  rQ  T)r   r   r   get_full_pathrT  r   r
   rU  rV  rW  r	   rO  exists)r   argskwargsr[  allowed)rI  permission_fieldsuperuser_only	view_funcr   r   wrapped  s0    

z=admin_permission_required.<locals>.decorator.<locals>.wrappedr   )ri  rj  rI  rg  rh  )ri  r   	decorator  s     z,admin_permission_required.<locals>.decoratorr   )rI  actionrh  rl  r   rk  r   admin_permission_required  s    
#rn  c                 C   s^   | D ]T}|j }|tkrq|tkr6tddd|j|_qt|}t|t|d|j|_q| S )z;Apply role permissions directly to each admin URL callback.NT)rI  rh  )rI  rm  )r;  EXEMPT_ADMIN_URL_NAMESSUPERUSER_ONLY_URL_NAMESrn  callbackURL_FEATURE_MAPr   r`  )urlpatternspatternrJ  rI  r   r   r   protect_admin_urlpatterns5  s(    
ru  N)r\  F) 	functoolsr   django.contrib.authr   r   django.contrib.auth.viewsr   django.httpr   django.shortcutsr   learn.modelsr	   r
   r   ZADMIN_FEATURE_URLSro  rp  valuesr_  rA  r]  r^  discardr2  itemsrr  rZ  r   r`  rn  ru  r   r   r   r   <module>   sn                                                                                                                                                                      }        






	 
)