<s> from __future__ import unicode_literals , print_function , absolute_import <EOL> from django . utils . decorators import method_decorator <EOL> from django . views . decorators . debug import sensitive_post_parameters <EOL> from corehq . apps . accounting . exceptions import AccountingError <EOL> from corehq . apps . accounting . models import Subscription <EOL> from django_prbac . models import Role <EOL> class CCHQPRBACMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_view ( self , request , view_func , view_args , view_kwargs ) : <EOL> self . apply_prbac ( request ) <EOL> return None <EOL> @ classmethod <EOL> def apply_prbac ( cls , request ) : <EOL> if hasattr ( request , '<STR_LIT>' ) : <EOL> try : <EOL> plan_version , subscription = Subscription . get_subscribed_plan_by_domain ( request . domain ) <EOL> request . role = plan_version . role <EOL> request . plan = plan_version <EOL> request . subscription = subscription <EOL> return None <EOL> except AccountingError : <EOL> pass <EOL> privilege = Role . get_privilege ( '<STR_LIT>' ) <EOL> if privilege is not None : <EOL> request . role = privilege . role <EOL> else : <EOL> request . role = Role ( ) <EOL> class DomainHistoryMiddleware ( object ) : <EOL> def process_response ( self , request , response ) : <EOL> if hasattr ( request , '<STR_LIT>' ) : <EOL> self . remember_domain_visit ( request , response ) <EOL> return response <EOL> def remember_domain_visit ( self , request , response ) : <EOL> last_visited_domain = request . session . get ( '<STR_LIT>' ) <EOL> if last_visited_domain != request . domain : <EOL> request . session [ '<STR_LIT>' ] = request . domain </s>
