~ubuntu-branches/ubuntu/utopic/horizon/utopic-updates

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/identity/users/tables.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chris Johnston, James Page
  • Date: 2014-10-03 17:54:18 UTC
  • mfrom: (0.4.1) (1.1.44) (70.1.2 utopic)
  • Revision ID: package-import@ubuntu.com-20141003175418-1jomx0azdvnl5fxz
Tags: 1:2014.2~rc1-0ubuntu1
[ Chris Johnston ]
* d/theme/css/ubuntu.css: Fix Ubuntu theme for Instances "more" dropdown
  (LP: #1308651).

[ James Page ]
* New upstream release candidate:
  - d/p/*: Refresh.
* d/watch: Use tarballs.openstack.org for upstream releases. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
from django.template import defaultfilters
14
14
from django.utils.translation import ugettext_lazy as _
 
15
from django.utils.translation import ungettext_lazy
15
16
 
16
17
from horizon import messages
17
18
from horizon import tables
18
19
 
19
20
from openstack_dashboard import api
 
21
from openstack_dashboard import policy
20
22
 
21
23
 
22
24
ENABLE = 0
38
40
        return api.keystone.keystone_can_edit_user()
39
41
 
40
42
 
41
 
class EditUserLink(tables.LinkAction):
 
43
class EditUserLink(policy.PolicyTargetMixin, tables.LinkAction):
42
44
    name = "edit"
43
45
    verbose_name = _("Edit")
44
46
    url = "horizon:identity:users:update"
46
48
    icon = "pencil"
47
49
    policy_rules = (("identity", "identity:update_user"),
48
50
                    ("identity", "identity:list_projects"),)
49
 
 
50
 
    def get_policy_target(self, request, user):
51
 
        return {"user_id": user.id}
 
51
    policy_target_attrs = (("user_id", "id"),)
52
52
 
53
53
    def allowed(self, request, user):
54
54
        return api.keystone.keystone_can_edit_user()
55
55
 
56
56
 
57
 
class ToggleEnabled(tables.BatchAction):
 
57
class ToggleEnabled(policy.PolicyTargetMixin, tables.BatchAction):
58
58
    name = "toggle"
59
 
    action_present = (_("Enable"), _("Disable"))
60
 
    action_past = (_("Enabled"), _("Disabled"))
61
 
    data_type_singular = _("User")
62
 
    data_type_plural = _("Users")
 
59
 
 
60
    @staticmethod
 
61
    def action_present(count):
 
62
        return (
 
63
            ungettext_lazy(
 
64
                u"Enable User",
 
65
                u"Enable Users",
 
66
                count
 
67
            ),
 
68
            ungettext_lazy(
 
69
                u"Disable User",
 
70
                u"Disable Users",
 
71
                count
 
72
            ),
 
73
        )
 
74
 
 
75
    @staticmethod
 
76
    def action_past(count):
 
77
        return (
 
78
            ungettext_lazy(
 
79
                u"Enabled User",
 
80
                u"Enabled Users",
 
81
                count
 
82
            ),
 
83
            ungettext_lazy(
 
84
                u"Disabled User",
 
85
                u"Disabled Users",
 
86
                count
 
87
            ),
 
88
        )
63
89
    classes = ("btn-toggle",)
64
90
    policy_rules = (("identity", "identity:update_user"),)
65
 
 
66
 
    def get_policy_target(self, request, user=None):
67
 
        if user:
68
 
            return {"user_id": user.id}
69
 
        return {}
 
91
    policy_target_attrs = (("user_id", "id"),)
70
92
 
71
93
    def allowed(self, request, user=None):
72
94
        if not api.keystone.keystone_can_edit_user():
101
123
 
102
124
 
103
125
class DeleteUsersAction(tables.DeleteAction):
104
 
    data_type_singular = _("User")
105
 
    data_type_plural = _("Users")
 
126
    @staticmethod
 
127
    def action_present(count):
 
128
        return ungettext_lazy(
 
129
            u"Delete User",
 
130
            u"Delete Users",
 
131
            count
 
132
        )
 
133
 
 
134
    @staticmethod
 
135
    def action_past(count):
 
136
        return ungettext_lazy(
 
137
            u"Deleted User",
 
138
            u"Deleted Users",
 
139
            count
 
140
        )
106
141
    policy_rules = (("identity", "identity:delete_user"),)
107
142
 
108
143
    def allowed(self, request, datum):