def role_action_save(request): from policyengine.models import CommunityRole, PolicykitAddRole, PolicykitEditRole data = json.loads(request.body) user = get_user(request) action = None if data['operation'] == 'Add': action = PolicykitAddRole() elif data['operation'] == 'Change': action = PolicykitEditRole() action.role = CommunityRole.objects.filter(name=html.unescape(data['name']))[0] else: return HttpResponseBadRequest() action.community = user.community action.initiator = user action.name = data['role_name'] action.description = data['description'] action.save() action.permissions.set(Permission.objects.filter(name__in=data['permissions'])) action.ready = True action.save() return HttpResponse()
def policy_action_save(request): from policyengine.models import PlatformPolicy, ConstitutionPolicy, PolicykitAddConstitutionPolicy, PolicykitAddPlatformPolicy, PolicykitChangeConstitutionPolicy, PolicykitChangePlatformPolicy data = json.loads(request.body) user = get_user(request) action = None if data['type'] == 'Constitution' and data['operation'] == 'Add': action = PolicykitAddConstitutionPolicy() action.is_bundled = data['is_bundled'] elif data['type'] == 'Platform' and data['operation'] == 'Add': action = PolicykitAddPlatformPolicy() action.is_bundled = data['is_bundled'] elif data['type'] == 'Constitution' and data['operation'] == 'Change': action = PolicykitChangeConstitutionPolicy() action.constitution_policy = ConstitutionPolicy.objects.get(id=data['policy']) elif data['type'] == 'Platform' and data['operation'] == 'Change': action = PolicykitChangePlatformPolicy() action.platform_policy = PlatformPolicy.objects.get(id=data['policy']) else: return HttpResponseBadRequest() action.community = user.community action.initiator = user action.name = data['name'] action.description = data['description'] action.filter = data['filter'] action.initialize = data['initialize'] action.check = data['check'] action.notify = data['notify'] action.success = data['success'] action.fail = data['fail'] action.save() return HttpResponse()
def document_action_remove(request): from policyengine.models import CommunityDoc, PolicykitDeleteCommunityDoc data = json.loads(request.body) user = get_user(request) action = PolicykitDeleteCommunityDoc() action.community = user.community action.initiator = user action.doc = CommunityDoc.objects.get(id=data['doc']) action.save() return HttpResponse()
def role_action_remove(request): from policyengine.models import CommunityRole, PolicykitDeleteRole data = json.loads(request.body) user = get_user(request) action = PolicykitDeleteRole() action.community = user.community action.initiator = user action.role = CommunityRole.objects.get(name=data['role']) action.save() return HttpResponse()
def get_queryset(self): if self.request.query_params.get("search", None): params = self.request.query_params.get("search", None) return WechatUser.objects.filter(Q(username__icontains=params) | Q(phone__icontains=params) | Q(name__icontains=params) ) if self.kwargs.get('pk') is None: return WechatUser.objects.all() user_id = int(self.kwargs['pk']) if self.request.user.id != user_id: target_user = WechatUser.objects.get(id=user_id) action = ViewedProfileTracking(actor=self.request.user, visited_profile=target_user) action.save() return WechatUser.objects.all()
def policy_action_remove(request): from policyengine.models import PlatformPolicy, ConstitutionPolicy, PolicykitRemoveConstitutionPolicy, PolicykitRemovePlatformPolicy data = json.loads(request.body) user = get_user(request) action = None if data['type'] == 'Constitution': action = PolicykitRemoveConstitutionPolicy() action.constitution_policy = ConstitutionPolicy.objects.get(id=data['policy']) elif data['type'] == 'Platform': action = PolicykitRemovePlatformPolicy() action.platform_policy = PlatformPolicy.objects.get(id=data['policy']) else: return HttpResponseBadRequest() action.community = user.community action.initiator = user action.save() return HttpResponse()
def regenerate_actions(apps, schema_editor): DivesiteComment = apps.get_model('comments', 'DivesiteComment') SlipwayComment = apps.get_model('comments', 'SlipwayComment') CompressorComment = apps.get_model('comments', 'CompressorComment') for comment in DivesiteComment.objects.all(): if not Action.objects.filter(action_object_object_id=comment.id).exists(): Action.objects.create(actor=comment.owner, verb='commented', action_object=comment, target=comment.divesite) for action in Action.objects.filter(action_object_object_id=str(comment.id)): if action.target is None: action.target = comment.divesite action.save() for comment in SlipwayComment.objects.all(): if not Action.objects.filter(action_object_object_id=comment.id).exists(): Action.objects.create(actor=comment.owner, verb='commented', action_object=comment, target=comment.slipway) for action in Action.objects.filter(action_object_object_id=str(comment.id)): if action.target is None: action.target = comment.slipway action.save() for comment in CompressorComment.objects.all(): if not Action.objects.filter(action_object_object_id=comment.id).exists(): Action.objects.create(actor=comment.owner, verb='commented', action_object=comment, target=comment.compressor) for action in Action.objects.filter(action_object_object_id=str(comment.id)): if action.target is None: action.target = comment.compressor action.save()
def document_action_save(request): from policyengine.models import CommunityDoc, PolicykitAddCommunityDoc, PolicykitChangeCommunityDoc data = json.loads(request.body) user = get_user(request) action = None if data['operation'] == 'Add': action = PolicykitAddCommunityDoc() elif data['operation'] == 'Change': action = PolicykitChangeCommunityDoc() action.doc = CommunityDoc.objects.filter(id=data['doc'])[0] else: return HttpResponseBadRequest() action.community = user.community action.initiator = user action.name = data['name'] action.text = data['text'] action.save() return HttpResponse()
def role_action_users(request): from policyengine.models import CommunityRole, CommunityUser, PolicykitAddUserRole, PolicykitRemoveUserRole data = json.loads(request.body) user = get_user(request) action = None if data['operation'] == 'Add': action = PolicykitAddUserRole() elif data['operation'] == 'Remove': action = PolicykitRemoveUserRole() else: return HttpResponseBadRequest() action.community = user.community action.initiator = user action.role = CommunityRole.objects.filter(name=data['role'])[0] action.save() action.users.set(CommunityUser.objects.filter(username=data['user'])) action.ready = True action.save() return HttpResponse()