old_contents: import xmlrpclib
  
  from simplejson import JSONDecodeError
  
  from linaro_django_xmlrpc.models import ExposedAPI
  
  from lava_scheduler_app.models import (
      Device,
      DeviceType,
      JSONDataError,
      TestJob,
      )
  
  
  class SchedulerAPI(ExposedAPI):
  
      def submit_job(self, job_data):
          if not self.user:
              raise xmlrpclib.Fault(401, "Authentication required.")
          if not self.user.has_perm('lava_scheduler_app.add_testjob'):
              raise xmlrpclib.Fault(403, "Permission denied.")
          try:
              job = TestJob.from_json_and_user(job_data, self.user)
          except JSONDecodeError as e:
              raise xmlrpclib.Fault(400, "Decoding JSON failed: %s." % e)
          except JSONDataError as e:
              raise xmlrpclib.Fault(400, str(e))
          except Device.DoesNotExist:
              raise xmlrpclib.Fault(404, "Specified device not found.")
          except DeviceType.DoesNotExist:
              raise xmlrpclib.Fault(404, "Specified device type not found.")
          return job.id
  
      def cancel_job(self, job_id):
          if not self.user:
              raise xmlrpclib.Fault(401, "Authentication required.")
          job = TestJob.objects.get(pk=job_id)
          if not job.can_cancel(self.user):
              raise xmlrpclib.Fault(403, "Permission denied.")
          job.cancel()
          return True
  
new_contents: import xmlrpclib
  
  from simplejson import JSONDecodeError
  
  from linaro_django_xmlrpc.models import ExposedAPI
  
  from lava_scheduler_app.models import (
      Device,
      DeviceType,
      JSONDataError,
      TestJob,
      )
  
  
  class SchedulerAPI(ExposedAPI):
  
      def submit_job(self, job_data):
          if not self.user:
              raise xmlrpclib.Fault(
                  401, "Authentication with user and token required for this "
                  "API.")
          if not self.user.has_perm('lava_scheduler_app.add_testjob'):
              raise xmlrpclib.Fault(
                  403, "Permission denied.  User %r does not have the "
                  "'lava_scheduler_app.add_testjob' permission.  Contact "
                  "the administrators." % self.user.username)
          try:
              job = TestJob.from_json_and_user(job_data, self.user)
          except JSONDecodeError as e:
              raise xmlrpclib.Fault(400, "Decoding JSON failed: %s." % e)
          except JSONDataError as e:
              raise xmlrpclib.Fault(400, str(e))
          except Device.DoesNotExist:
              raise xmlrpclib.Fault(404, "Specified device not found.")
          except DeviceType.DoesNotExist:
              raise xmlrpclib.Fault(404, "Specified device type not found.")
          return job.id
  
      def cancel_job(self, job_id):
          if not self.user:
              raise xmlrpclib.Fault(401, "Authentication required.")
          job = TestJob.objects.get(pk=job_id)
          if not job.can_cancel(self.user):
              raise xmlrpclib.Fault(403, "Permission denied.")
          job.cancel()
          return True
  
subject: make submit_job give slightly more useful permission errors