<s> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . shortcuts import get_object_or_404 <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . datastructures import MultiValueDictKeyError <EOL> from authority . models import Permission <EOL> from authority . views import permission_denied <EOL> from transifex . projects . forms import ProjectAccessControlForm <EOL> from transifex . projects . models import Project <EOL> from transifex . projects . permissions import * <EOL> from transifex . projects . permissions . project import ProjectPermission <EOL> from transifex . txcommon import notifications as txnotification <EOL> from transifex . txcommon . decorators import one_perm_required_or_403 , access_off <EOL> from transifex . txcommon . log import logger <EOL> from transifex . txcommon . views import permission_denied <EOL> from transifex . txpermissions . views import ( add_permission_or_request , <EOL> approve_permission_request , <EOL> delete_permission_or_request ) <EOL> def _get_project_and_permission ( project_slug , permission_pk ) : <EOL> """<STR_LIT>""" <EOL> project = get_object_or_404 ( Project , slug = project_slug ) <EOL> ctype = ContentType . objects . get_for_model ( Project ) <EOL> permission = get_object_or_404 ( Permission , object_id = project . pk , <EOL> content_type = ctype , id = permission_pk ) <EOL> return project , permission <EOL> @ access_off ( permission_denied ) <EOL> @ login_required <EOL> @ one_perm_required_or_403 ( pr_project_add_perm , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def project_add_permission ( request , project_slug ) : <EOL> """<STR_LIT>""" <EOL> project = get_object_or_404 ( Project , slug = project_slug ) <EOL> try : <EOL> username = request . POST [ '<STR_LIT:user>' ] <EOL> sendto = User . objects . get ( username = username ) <EOL> except ( MultiValueDictKeyError , User . DoesNotExist ) : <EOL> sendto = None <EOL> notice = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:object>' : project , <EOL> '<STR_LIT>' : [ sendto ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : project , <EOL> '<STR_LIT>' : sendto , <EOL> '<STR_LIT>' : request . user , <EOL> } , <EOL> } <EOL> return add_permission_or_request ( request , project , <EOL> view_name = '<STR_LIT>' , <EOL> approved = True , <EOL> extra_context = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : project , <EOL> '<STR_LIT>' : ProjectAccessControlForm ( instance = project ) , <EOL> '<STR_LIT>' : notice , <EOL> } , <EOL> template_name = '<STR_LIT>' ) <EOL> @ access_off ( permission_denied ) <EOL> @ login_required <EOL> @ one_perm_required_or_403 ( pr_project_approve_perm , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def project_approve_permission_request ( request , project_slug , permission_pk ) : <EOL> project , permission = _get_project_and_permission ( project_slug , permission_pk ) <EOL> notice = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:object>' : project , <EOL> '<STR_LIT>' : [ permission . user ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : project , <EOL> '<STR_LIT>' : permission . user , <EOL> '<STR_LIT>' : request . user , <EOL> } , <EOL> } <EOL> return approve_permission_request ( request , permission , <EOL> extra_context = { '<STR_LIT>' : notice } ) <EOL> @ access_off ( permission_denied ) <EOL> @ login_required <EOL> @ one_perm_required_or_403 ( pr_project_delete_perm , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def project_delete_permission ( request , project_slug , permission_pk ) : <EOL> """<STR_LIT>""" <EOL> project , permission = _get_project_and_permission ( project_slug , permission_pk ) <EOL> notice = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:object>' : project , <EOL> '<STR_LIT>' : [ permission . user ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : project , <EOL> '<STR_LIT>' : permission . user , <EOL> '<STR_LIT>' : request . user , <EOL> } , <EOL> } <EOL> return delete_permission_or_request ( request , permission , True , <EOL> extra_context = { '<STR_LIT>' : notice } ) <EOL> @ access_off ( permission_denied ) <EOL> @ login_required <EOL> def project_delete_permission_request ( request , project_slug , permission_pk ) : <EOL> """<STR_LIT>""" <EOL> project , permission = _get_project_and_permission ( project_slug , permission_pk ) <EOL> if request . user . id == permission . user . id : <EOL> notice_type = '<STR_LIT>' <EOL> sendto = project . maintainers . all ( ) <EOL> else : <EOL> notice_type = '<STR_LIT>' <EOL> sendto = [ permission . user ] <EOL> notice = { <EOL> '<STR_LIT:type>' : notice_type , <EOL> '<STR_LIT:object>' : project , <EOL> '<STR_LIT>' : sendto , <EOL> '<STR_LIT>' : { '<STR_LIT>' : project , <EOL> '<STR_LIT>' : permission . user , <EOL> '<STR_LIT>' : request . user , <EOL> } , <EOL> } <EOL> check = ProjectPermission ( request . user ) <EOL> if check . maintain ( project ) or request . user . has_perm ( '<STR_LIT>' ) or request . user . pk == permission . creator . pk : <EOL> return delete_permission_or_request ( request , permission , False , <EOL> extra_context = { '<STR_LIT>' : notice } , ) <EOL> check = ProjectPermission ( request . user ) <EOL> if check . maintain ( project ) or request . user . has_perm ( '<STR_LIT>' ) or request . user . pk == permission . creator . pk : <EOL> return delete_permission_or_request ( request , permission , False ) <EOL> return permission_denied ( request ) </s>
