Prevent user from disabling her current project

Disabling user's current project is like shooting yourself in the foot
- once it's done, it's irreversible in the current tenant because it's
no longer possible to edit any Project/User/etc. Thus it is forbidden
both when using Edit Project modal or when inline-editing the
corresponding cell at Projects table.

Closes-Bug: #1398331
Change-Id: Iacca383f1d982a9b16c41c9f945fdcdde9f803a1
This commit is contained in:
Timur Sufiev 2014-12-02 16:35:57 +03:00
parent 569228ae99
commit 257cf49047
2 changed files with 14 additions and 3 deletions

View File

@ -181,9 +181,12 @@ class UpdateRow(tables.Row):
class UpdateCell(tables.UpdateAction):
def allowed(self, request, project, cell):
return api.keystone.keystone_can_edit_project() and \
policy.check((("identity", "identity:update_project"),),
request)
policy_rule = (("identity", "identity:update_project"),)
return (
(cell.column.name != 'enabled' or
request.user.token.project['id'] != cell.datum.id) and
api.keystone.keystone_can_edit_project() and
policy.check(policy_rule, request))
def update_cell(self, request, datum, project_id,
cell_name, new_cell_value):

View File

@ -506,6 +506,14 @@ class CreateProject(workflows.Workflow):
class UpdateProjectInfoAction(CreateProjectInfoAction):
enabled = forms.BooleanField(required=False, label=_("Enabled"))
def __init__(self, request, initial, *args, **kwargs):
super(UpdateProjectInfoAction, self).__init__(
request, initial, *args, **kwargs)
if initial['project_id'] == request.user.token.project['id']:
self.fields['enabled'].widget.attrs['disabled'] = True
self.fields['enabled'].help_text = _(
'You cannot disable your current project')
class Meta:
name = _("Project Information")
slug = 'update_info'