Improve error messages.
parent
c9fab40e1a
commit
f6d1fdad06
|
@ -84,10 +84,10 @@ class UsersViewSet(ModelCrudViewSet):
|
|||
password = request.DATA.get("password")
|
||||
|
||||
if not password:
|
||||
raise exc.WrongArguments(_("incomplete argiments"))
|
||||
raise exc.WrongArguments(_("Incomplete arguments"))
|
||||
|
||||
if len(password) < 6:
|
||||
raise exc.WrongArguments(_("invalid password length"))
|
||||
raise exc.WrongArguments(_("Invalid password length"))
|
||||
|
||||
request.user.set_password(password)
|
||||
request.user.save(update_fields=["password"])
|
||||
|
|
|
@ -86,7 +86,7 @@ class MembershipViewSet(ModelCrudViewSet):
|
|||
Q(project_id=serializer.data["project"],
|
||||
email=serializer.data["email"]))
|
||||
if qs.count() > 0:
|
||||
raise exc.WrongArguments(_("Already exist user with specified email address."))
|
||||
raise exc.WrongArguments(_("Email address is already taken."))
|
||||
|
||||
self.pre_save(serializer.object)
|
||||
self.object = serializer.save(force_insert=True)
|
||||
|
|
|
@ -79,22 +79,22 @@ class IssueViewSet(NotificationSenderMixin, ModelCrudViewSet):
|
|||
|
||||
if (obj.project.owner != self.request.user and
|
||||
obj.project.memberships.filter(user=self.request.user).count() == 0):
|
||||
raise exc.PreconditionError(_("You must not add a new issue to this project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this issue."))
|
||||
|
||||
if obj.milestone and obj.milestone.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not add a new issue to this milestone."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this issue."))
|
||||
|
||||
if obj.status and obj.status.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not use a status from other project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this issue."))
|
||||
|
||||
if obj.severity and obj.severity.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not use a severity from other project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this issue."))
|
||||
|
||||
if obj.priority and obj.priority.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not use a priority from other project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this issue."))
|
||||
|
||||
if obj.type and obj.type.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not use a type from other project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this issue."))
|
||||
|
||||
def post_save(self, obj, created=False):
|
||||
with reversion.create_revision():
|
||||
|
@ -128,4 +128,5 @@ class IssueAttachmentViewSet(ModelCrudViewSet):
|
|||
|
||||
if (obj.project.owner != self.request.user and
|
||||
obj.project.memberships.filter(user=self.request.user).count() == 0):
|
||||
raise exc.PreconditionError(_("You must not add a new issue attachment to this project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add attachments "
|
||||
"to this issue"))
|
||||
|
|
|
@ -44,8 +44,8 @@ class TaskAttachmentViewSet(ModelCrudViewSet):
|
|||
|
||||
if (obj.project.owner != self.request.user and
|
||||
obj.project.memberships.filter(user=self.request.user).count() == 0):
|
||||
raise exc.PreconditionError(_("You must not add a new task attachment to this project."))
|
||||
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add "
|
||||
"attachments to this task."))
|
||||
|
||||
|
||||
class TaskViewSet(NotificationSenderMixin, ModelCrudViewSet):
|
||||
|
@ -71,16 +71,16 @@ class TaskViewSet(NotificationSenderMixin, ModelCrudViewSet):
|
|||
|
||||
if (obj.project.owner != self.request.user and
|
||||
obj.project.memberships.filter(user=self.request.user).count() == 0):
|
||||
raise exc.PreconditionError(_("You must not add a new task to this project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this task."))
|
||||
|
||||
if obj.milestone and obj.milestone.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not add a task to this milestone."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this task."))
|
||||
|
||||
if obj.user_story and obj.user_story.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not add a task to this user story."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this task."))
|
||||
|
||||
if obj.status and obj.status.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not use a status from other project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this task."))
|
||||
|
||||
def post_save(self, obj, created=False):
|
||||
with reversion.create_revision():
|
||||
|
|
|
@ -52,7 +52,8 @@ class UserStoryAttachmentViewSet(ModelCrudViewSet):
|
|||
|
||||
if (obj.project.owner != self.request.user and
|
||||
obj.project.memberships.filter(user=self.request.user).count() == 0):
|
||||
raise exc.PreconditionError(_("You must not add a new user story attachment to this project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for "
|
||||
"add attachments to this user story"))
|
||||
|
||||
|
||||
class UserStoryViewSet(NotificationSenderMixin, ModelCrudViewSet):
|
||||
|
@ -71,16 +72,16 @@ class UserStoryViewSet(NotificationSenderMixin, ModelCrudViewSet):
|
|||
def bulk_create(self, request, **kwargs):
|
||||
bulk_stories = request.DATA.get('bulkStories', None)
|
||||
if bulk_stories is None:
|
||||
raise exc.BadRequest(detail=_('You need bulkStories data'))
|
||||
raise exc.BadRequest(_('bulkStories parameter is mandatory'))
|
||||
|
||||
project_id = request.DATA.get('projectId', None)
|
||||
if project_id is None:
|
||||
raise exc.BadRequest(detail=_('You need projectId data'))
|
||||
raise exc.BadRequest(_('projectId parameter is mandatory'))
|
||||
|
||||
project = get_object_or_404(Project, id=project_id)
|
||||
|
||||
if not has_project_perm(request.user, project, 'add_userstory'):
|
||||
raise exc.PermissionDenied(_("You don't have permision to create user stories"))
|
||||
raise exc.PermissionDenied(_("You don't have permisions to create user stories."))
|
||||
|
||||
service = services.UserStoriesService()
|
||||
service.bulk_insert(project, request.user, bulk_stories)
|
||||
|
@ -95,16 +96,16 @@ class UserStoryViewSet(NotificationSenderMixin, ModelCrudViewSet):
|
|||
bulk_stories = request.DATA.get("bulkStories", None)
|
||||
|
||||
if bulk_stories is None:
|
||||
raise exc.BadRequest("bulkStories is missing")
|
||||
raise exc.BadRequest(_("bulkStories parameter is mandatory"))
|
||||
|
||||
project_id = request.DATA.get('projectId', None)
|
||||
if project_id is None:
|
||||
raise exc.BadRequest(detail='You need projectId data')
|
||||
raise exc.BadRequest(_("projectId parameter ir mandatory"))
|
||||
|
||||
project = get_object_or_404(Project, id=project_id)
|
||||
|
||||
if not has_project_perm(request.user, project, 'add_userstory'):
|
||||
raise exc.PermissionDenied("You don't have permision to create user stories")
|
||||
raise exc.PermissionDenied(_("You don't have permisions to create user stories."))
|
||||
|
||||
service = services.UserStoriesService()
|
||||
service.bulk_update_order(project, request.user, bulk_stories)
|
||||
|
@ -122,13 +123,13 @@ class UserStoryViewSet(NotificationSenderMixin, ModelCrudViewSet):
|
|||
|
||||
if (obj.project.owner != self.request.user and
|
||||
obj.project.memberships.filter(user=self.request.user).count() == 0):
|
||||
raise exc.PreconditionError(_("You must not add a new user story to this project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this user story"))
|
||||
|
||||
if obj.milestone and obj.milestone.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not add a new user story to this milestone."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this user story"))
|
||||
|
||||
if obj.status and obj.status.project != obj.project:
|
||||
raise exc.PreconditionError(_("You must not use a status from other project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add/modify this user story"))
|
||||
|
||||
def post_save(self, obj, created=False):
|
||||
with reversion.create_revision():
|
||||
|
|
|
@ -36,7 +36,8 @@ class WikiAttachmentViewSet(ModelCrudViewSet):
|
|||
|
||||
if (obj.project.owner != self.request.user and
|
||||
obj.project.memberships.filter(user=self.request.user).count() == 0):
|
||||
raise exc.PreconditionError(_("You must not add a new wiki page to this project."))
|
||||
raise exc.PermissionDenied(_("You don't have permissions for add "
|
||||
"attachments to this wiki page."))
|
||||
|
||||
def pre_save(self, obj):
|
||||
if not obj.id:
|
||||
|
@ -61,8 +62,8 @@ class WikiViewSet(ModelCrudViewSet):
|
|||
|
||||
if (obj.project.owner != self.request.user and
|
||||
obj.project.memberships.filter(user=self.request.user).count() == 0):
|
||||
raise exc.PreconditionError(_("You must not add a new wiki page to this project."))
|
||||
|
||||
raise exc.PermissionDenied(_("You don't haver permissions for add/modify "
|
||||
"this wiki page."))
|
||||
def pre_save(self, obj):
|
||||
if not obj.owner:
|
||||
obj.owner = self.request.user
|
||||
|
|
Loading…
Reference in New Issue