remove the middleware as not valid and fix permissions check in templates