def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] if self.is_finalized( Incident, kwargs['pk'], 'most_recent_status_incident') and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized')) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del (bundle.data['assigned_user']) status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id) comment_uri = self.create_comment(bundle.data['comment'], status_update.id, user) try: bundle.data['incident_comments'].append(comment_uri) except KeyError: bundle.data['incident_comments'] = [ comment_uri, ] with reversion.create_revision(): bundle = super(IncidentResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta(VersionStatus, user=user, status='edited') reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def build_js_context(user): return { 'locale': select_language(), 'rtl': is_right_to_left(), 'role_status_set': select_roles(), 'relation_status_set': select_relations(), 'predefined_search_set': select_predefined_searches(user), 'sources_set': select_sources(), 'labels_set': select_labels(), 'age_set': select_ages(), 'sexes_set': select_sexes(), 'civilian': select_civilian(), 'crimes_set': select_crime_categories(), 'status_set': select_statuses(user), 'create_status': create_status(), 'all_status_set': select_all_statuses(), 'conditions': select_conditions(), 'users_set': select_users(), 'loc_set': select_locations, 'username': user.username, 'userid': user.id, 'api_key': select_apikey(user), 'solr_url': get_solr_url(), 'can_assign_users': can_assign_users(user), 'can_delete_entities': can_delete(user), 'can_update_to_finalized': can_finalize(user), 'can_edit_assigned_entities': can_edit_assigned_entities(user), 'can_edit_entities': can_edit_entities(user), 'is_analyst': is_in_group(user, 'data-analyst'), 'is_senior_analyst': is_in_group(user, 'senior-data-analyst'), 'is_chief_analyst': is_in_group(user, 'chief-data-analyst'), }
def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] bundle.data['id'] = kwargs['pk'] if self.can_edit(user, bundle, Actor) is False: raise ImmediateHttpResponse( HttpForbidden('You do not have permission to edit this entity') ) if self.is_finalized( Actor, kwargs['pk'], 'most_recent_status_actor' ) and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized') ) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del(bundle.data['assigned_user']) status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id ) comment_uri = self.create_comment( bundle.data['comment'], status_update.id, user ) if "condition" not in bundle.data: bundle.data['condition'] = None if "POB" not in bundle.data: bundle.data['POB'] = None if "current_location" not in bundle.data: bundle.data['current_location'] = None try: bundle.data['actor_comments'].append(comment_uri) except KeyError: bundle.data['actor_comments'] = [comment_uri, ] with reversion.create_revision(): bundle = super(ActorResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta( VersionStatus, status='edited', user=user ) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] if self.can_edit(user, bundle, Bulletin) is False: raise ImmediateHttpResponse( HttpForbidden('You do not have permission to edit this entity') ) # permission checks if self.is_finalized( Bulletin, kwargs['pk'], 'most_recent_status_bulletin' ) and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized') ) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del(bundle.data['assigned_user']) # decide on available status status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id ) # create the commnt from the status update and the bundled comment comment_uri = self.create_comment( bundle.data['comment'], status_update.id, user ) try: bundle.data['bulletin_comments'].append(comment_uri) except KeyError: bundle.data['bulletin_comments'] = [comment_uri, ] with reversion.create_revision(): bundle = super(BulletinResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta( VersionStatus, status='edited', user=user ) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] bundle.data['id'] = kwargs['pk'] if self.can_edit(user, bundle, Actor) is False: raise ImmediateHttpResponse( HttpForbidden( 'You do not have permission to edit this entity')) if self.is_finalized( Actor, kwargs['pk'], 'most_recent_status_actor') and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized')) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del (bundle.data['assigned_user']) status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id) comment_uri = self.create_comment(bundle.data['comment'], status_update.id, user) if "condition" not in bundle.data: bundle.data['condition'] = None if "POB" not in bundle.data: bundle.data['POB'] = None if "current_location" not in bundle.data: bundle.data['current_location'] = None try: bundle.data['actor_comments'].append(comment_uri) except KeyError: bundle.data['actor_comments'] = [ comment_uri, ] with reversion.create_revision(): bundle = super(ActorResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta(VersionStatus, status='edited', user=user) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] if self.is_finalized( Incident, kwargs['pk'], 'most_recent_status_incident' ) and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized') ) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del(bundle.data['assigned_user']) status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id ) comment_uri = self.create_comment( bundle.data['comment'], status_update.id, user ) try: bundle.data['incident_comments'].append(comment_uri) except KeyError: bundle.data['incident_comments'] = [comment_uri, ] with reversion.create_revision(): bundle = super(IncidentResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta( VersionStatus, user=user, status='edited' ) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle