def test_edit_forecast_all_cost_centres_permission(self): assert not can_edit_cost_centre( self.test_user, self.cost_centre_code, ) self.assign_permission("edit_forecast_all_cost_centres") assert can_edit_cost_centre( self.test_user, self.cost_centre_code, )
def test_super_user(self): assert not can_edit_cost_centre( self.test_user, self.cost_centre_code, ) self.test_user.is_superuser = True self.test_user.save() assert can_edit_cost_centre( self.test_user, self.cost_centre, )
def test_basic_user_edit_permission(self): assert not can_edit_cost_centre( self.test_user, self.cost_centre_code, ) assign_perm( "change_costcentre", self.test_user, self.cost_centre, ) assert can_edit_cost_centre( self.test_user, self.cost_centre_code, )
def test_func(self): if "cost_centre_code" not in self.kwargs: raise NoCostCentreCodeInURLError( "No cost centre code provided in URL") self.cost_centre_code = self.kwargs["cost_centre_code"] has_permission = can_edit_cost_centre( self.request.user, self.cost_centre_code, ) user_can_edit = can_forecast_be_edited(self.request.user) if not user_can_edit: self.edit_not_available = True return False return has_permission
def export_edit_forecast_data(request, cost_centre): fields = ForecastQueryFields() if can_edit_cost_centre(request.user, cost_centre): filter = {fields.cost_centre_code_field: cost_centre} q = ForecastingDataView.view_data.raw_data_annotated( { **fields.EDIT_KEYS_DOWNLOAD, **fields.EDIT_FORECAST_DOWNLOAD_COLUMNS }, filter, order_list=fields.EDIT_FORECAST_DOWNLOAD_ORDER, include_zeros=True, ) title = f"Edit forecast {cost_centre}" return export_edit_to_excel(q, fields.EDIT_KEYS_DOWNLOAD, fields.EDIT_FORECAST_DOWNLOAD_COLUMNS, title) else: return redirect(reverse( "forecast_dit", kwargs={ "period": 0, }, ))