Projet

Général

Profil

0001-studio-show-only-recent-changes-of-current-user-6295.patch

Lauréline Guérin, 28 juin 2022 16:37

Télécharger (5,02 ko)

Voir les différences:

Subject: [PATCH] studio: show only recent changes of current user (#62953)

 tests/admin_pages/test_studio.py         | 18 +++++++++++++++++-
 wcs/backoffice/studio.py                 |  5 +++--
 wcs/snapshots.py                         |  4 ++--
 wcs/sql.py                               |  5 +++--
 wcs/templates/wcs/backoffice/studio.html |  2 +-
 5 files changed, 26 insertions(+), 8 deletions(-)
tests/admin_pages/test_studio.py
137 137

  
138 138
def test_studio_home_recent_changes(sql_pub):
139 139
    pub = sql_pub
140
    create_superuser(pub)
140
    user = create_superuser(pub)
141
    other_user = pub.user_class(name='other')
142
    other_user.store()
141 143

  
142 144
    BlockDef.wipe()
143 145
    CardDef.wipe()
......
163 165

  
164 166
    app = login(get_app(pub))
165 167
    resp = app.get('/backoffice/studio/')
168
    assert len(resp.pyquery.find('ul.recent-changes li')) == 0
169

  
170
    for snapshot in pub.snapshot_class.select():
171
        snapshot.user_id = other_user.id
172
        snapshot.store()
173
    resp = app.get('/backoffice/studio/')
174
    assert len(resp.pyquery.find('ul.recent-changes li')) == 0
175

  
176
    for snapshot in pub.snapshot_class.select():
177
        snapshot.user_id = user.id
178
        snapshot.store()
179
    resp = app.get('/backoffice/studio/')
180
    assert len(resp.pyquery.find('ul.recent-changes li')) == 5
181

  
166 182
    # too old
167 183
    for i in range(5):
168 184
        assert 'backoffice/forms/blocks/%s/' % objects[BlockDef.xml_root_node][i].id not in resp
wcs/backoffice/studio.py
14 14
# You should have received a copy of the GNU General Public License
15 15
# along with this program; if not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from quixote import get_publisher
17
from quixote import get_publisher, get_request
18 18
from quixote.directory import Directory
19 19

  
20 20
from wcs.admin.logged_errors import LoggedErrorsDirectory
......
78 78
        }
79 79
        if get_publisher().snapshot_class:
80 80
            context['recent_objects'] = get_publisher().snapshot_class.get_recent_changes(
81
                object_types=[ot.xml_root_node for ot in object_types]
81
                object_types=[ot.xml_root_node for ot in object_types],
82
                user=get_request().user,
82 83
            )
83 84
        return template.QommonTemplateResponse(
84 85
            templates=['wcs/backoffice/studio.html'], context=context, is_django_native=True
wcs/snapshots.py
184 184
            obj.store()
185 185

  
186 186
    @classmethod
187
    def get_recent_changes(cls, object_types):
188
        elements = cls._get_recent_changes(object_types)
187
    def get_recent_changes(cls, object_types, user):
188
        elements = cls._get_recent_changes(object_types, user)
189 189
        instances = []
190 190
        for object_type, object_id, snapshot_timestamp in elements:
191 191
            klass = cls.get_class(object_type)
wcs/sql.py
3625 3625
        return cls.get(row[0])
3626 3626

  
3627 3627
    @classmethod
3628
    def _get_recent_changes(cls, object_types):
3628
    def _get_recent_changes(cls, object_types, user):
3629 3629
        conn, cur = get_connection_and_cursor()
3630 3630
        sql_statement = '''SELECT object_type, object_id, MAX(timestamp) AS m
3631 3631
                           FROM snapshots
3632 3632
                           WHERE object_type IN %(object_types)s
3633
                           AND user_id = %(user_id)s
3633 3634
                           GROUP BY object_type, object_id
3634 3635
                           ORDER BY m DESC
3635 3636
                           LIMIT 5'''
3636
        parameters = {'object_types': tuple(object_types)}
3637
        parameters = {'object_types': tuple(object_types), 'user_id': str(user.id)}
3637 3638
        cur.execute(sql_statement, parameters)
3638 3639
        result = cur.fetchall()
3639 3640
        conn.commit()
wcs/templates/wcs/backoffice/studio.html
34 34

  
35 35
    <div class="paragraph">
36 36
      <h3>{% trans "Recent changes" context "studio" %}</h3>
37
      <ul>
37
      <ul class="recent-changes">
38 38
        {% for obj in recent_objects %}
39 39
        <li><a href="{{ obj.get_admin_url }}">{{ obj.name }} ({{ obj.verbose_name }})</a>
40 40
                <span class="timestamp">{{ obj.snapshot_timestamp }}</span></li>
41
-