Projet

Général

Profil

0001-backoffice-also-lock-related-user-formdata-12895.patch

Frédéric Péters, 21 septembre 2016 15:43

Télécharger (9,49 ko)

Voir les différences:

Subject: [PATCH] backoffice: also lock related user formdata (#12895)

 tests/test_backoffice_pages.py | 79 ++++++++++++++++++++++++++++++++++++++----
 wcs/backoffice/management.py   |  1 +
 wcs/formdata.py                |  4 +++
 wcs/forms/common.py            | 14 +++++---
 4 files changed, 86 insertions(+), 12 deletions(-)
tests/test_backoffice_pages.py
78 78
    return user1
79 79

  
80 80
def create_superuser(pub):
81
    create_user(pub, is_admin=True)
81
    return create_user(pub, is_admin=True)
82 82

  
83 83
def create_environment(pub, set_receiver=True):
84 84
    Workflow.wipe()
......
958 958
    account.store()
959 959
    app2 = login(get_app(pub), username='foobar', password='foobar')
960 960
    resp = app2.get('/backoffice/management/form-title/%s/' % number31.id)
961
    assert 'Be warned this form is also being' in resp.body
961
    assert 'Be warned forms of this user are also being looked' in resp.body
962 962
    assert not 'backoffice-description' in resp.body
963 963
    assert not 'CLICK ME!' in resp.body
964 964
    assert not 'CLICK ME2!' in resp.body
......
2514 2514
        assert not 'advisory-lock' in resp.body
2515 2515

  
2516 2516
    resp = app.get('/backoffice/management/form-title/' + first_link)
2517
    assert not 'Be warned this form is also being' in resp.body
2517
    assert not 'Be warned forms of this user are also being looked' in resp.body
2518 2518
    assert 'button_commentable' in resp.body
2519 2519
    assert len(resp.forms) == 1
2520 2520
    resp = app2.get('/backoffice/management/form-title/' + first_link)
2521
    assert 'Be warned this form is also being' in resp.body
2521
    assert 'Be warned forms of this user are also being looked' in resp.body
2522 2522
    assert not 'button_commentable' in resp.body
2523 2523
    assert len(resp.forms) == 0
2524 2524
    # revisit with first user, no change
2525 2525
    resp = app.get('/backoffice/management/form-title/' + first_link)
2526
    assert not 'Be warned this form is also being' in resp.body
2526
    assert not 'Be warned forms of this user are also being looked' in resp.body
2527 2527
    assert 'button_commentable' in resp.body
2528 2528
    # back to second
2529 2529
    resp = app2.get('/backoffice/management/form-title/' + first_link)
2530
    assert 'Be warned this form is also being' in resp.body
2530
    assert 'Be warned forms of this user are also being looked' in resp.body
2531 2531
    assert not 'button_commentable' in resp.body
2532 2532
    resp = resp.click('(unlock actions)')
2533 2533
    resp = resp.follow()
2534
    assert 'Be warned this form is also being' in resp.body
2534
    assert 'Be warned forms of this user are also being looked' in resp.body
2535 2535
    assert 'button_commentable' in resp.body
2536 2536
    assert not '(unlock actions)' in resp.body
2537 2537
    assert len(resp.forms) == 1
......
2549 2549
    assert not 'advisory-lock' in app2.get('/backoffice/management/form-title/')
2550 2550
    assert 'advisory-lock' in app.get('/backoffice/management/form-title/')
2551 2551

  
2552
def test_backoffice_advisory_lock_related_formdatas(pub):
2553
    if not pub.is_using_postgresql():
2554
        pytest.skip('this requires SQL')
2555
        return
2556
    pub.session_manager.session_class.wipe()
2557
    user = create_superuser(pub)
2558
    create_environment(pub)
2559

  
2560
    formdef = FormDef.get_by_urlname('form-title')
2561
    formdatas = formdef.data_class().select(lambda x: x.status == 'wf-new')
2562

  
2563
    second_user = pub.user_class(name='foobar')
2564
    second_user.roles = Role.keys()
2565
    second_user.store()
2566
    account = PasswordAccount(id='foobar')
2567
    account.set_password('foobar')
2568
    account.user_id = second_user.id
2569
    account.store()
2570

  
2571
    third_user = pub.user_class(name='user')
2572
    third_user.store()
2573

  
2574
    for formdata in formdatas[:2]:
2575
        formdata.user_id = third_user.id
2576
        formdata.store()
2577

  
2578
    second_formdef = FormDef.get_by_urlname('other-form')
2579
    second_formdef.workflow_roles = {}
2580
    second_formdef.store()
2581
    other_formdatas = second_formdef.data_class().select(lambda x: x.status == 'wf-new')
2582
    other_formdatas[0].user_id = third_user.id
2583
    other_formdatas[0].store()
2584

  
2585
    app = login(get_app(pub))
2586
    resp = app.get('/backoffice/management/form-title/%s/' % formdatas[0].id)
2587
    assert not 'Be warned forms of this user are also being looked' in resp.body
2588

  
2589
    app2 = login(get_app(pub), username='foobar', password='foobar')
2590
    resp2 = app2.get('/backoffice/management/form-title/%s/' % formdatas[0].id)
2591
    assert 'Be warned forms of this user are also being looked' in resp2.body
2592

  
2593
    # another by the same user
2594
    resp2 = app2.get('/backoffice/management/form-title/%s/' % formdatas[1].id)
2595
    assert 'Be warned forms of this user are also being looked' in resp2.body
2596

  
2597
    # another by another user
2598
    resp2 = app2.get('/backoffice/management/form-title/%s/' % formdatas[3].id)
2599
    assert not 'Be warned forms of this user are also being looked' in resp2.body
2600

  
2601
    # check another formdef is only marked as visited if the user has potential
2602
    # actions on it.
2603
    session = pub.session_manager.session_class.select(lambda x: x.user == user.id)[0]
2604
    second_formdef.workflow_roles = {'_receiver': 1}
2605
    second_formdef.store()
2606
    other_formdata = second_formdef.data_class().get(other_formdatas[0].id)
2607
    other_formdata.store() # update concerned_roles
2608

  
2609
    assert not 'formdata-other-form-%d' % other_formdata.id in session.visiting_objects.keys()
2610
    session.visiting_objects = {}
2611
    session.store()
2612

  
2613
    resp = app.get('/backoffice/management/form-title/%s/' % formdatas[0].id)
2614
    session = pub.session_manager.session_class.select(lambda x: x.user == user.id)[0]
2615
    assert 'formdata-other-form-%d' % other_formdata.id in session.visiting_objects.keys()
2616

  
2552 2617
def test_backoffice_resubmit(pub):
2553 2618
    user = create_user(pub)
2554 2619
    create_environment(pub)
wcs/backoffice/management.py
1908 1908
                        ]
1909 1909
            from wcs import sql
1910 1910
            formdatas = sql.AnyFormData.select(criterias, order_by='receipt_time')
1911
            self.filled.related_user_forms = formdatas
1911 1912

  
1912 1913
            if formdatas:
1913 1914
                r += htmltext('<div class="user-pending-forms">')
wcs/formdata.py
788 788
                cls=qommon.misc.JSONEncoder,
789 789
                encoding=get_publisher().site_charset)
790 790

  
791
    def mark_as_being_visited(self):
792
        object_key = 'formdata-%s-%s' % (self.formdef.url_name, self.id)
793
        get_session().mark_visited_object(object_key)
794

  
791 795
    def feed_session(self):
792 796
        # this gives a chance to fields to initialize things that would rely on
793 797
        # current data ahead of times
wcs/forms/common.py
527 527
        if get_request().get_query() == 'unlock':
528 528
            # mark user as active visitor of the object, then redirect to self,
529 529
            # the unlocked form will appear.
530
            get_session().mark_visited_object(object_key)
530
            self.filled.mark_as_being_visited()
531 531
            return redirect('./#lock-notice')
532 532

  
533 533
        user = self.check_receiver()
......
594 594
                    visitor_users.append('%s (%s)' % (visitor_name, time_ago))
595 595
                if visitor_users:
596 596
                    r += htmltext('<div id="lock-notice" class="infonotice"><p>')
597
                    r += _('Be warned this form is also being looked at by: '
597
                    r += _('Be warned forms of this user are also being looked at by: '
598 598
                           '%s.') % ', '.join(visitor_users)
599 599
                    r += ' '
600 600
                    r += htmltext('</p>')
......
605 605
                    r += htmltext('</div>')
606 606
            if not visitors or me_in_visitors:
607 607
                r += form.render()
608
                get_session().mark_visited_object(object_key)
608
                self.filled.mark_as_being_visited()
609
                related_user_forms = getattr(self.filled, 'related_user_forms', None) or []
610
                for user_formdata in related_user_forms:
611
                    other_form = user_formdata.get_workflow_form(user)
612
                    if other_form:
613
                        user_formdata.mark_as_being_visited()
609 614

  
610 615
        if not locked:
611 616
            if (self.filled.get_status() and self.filled.get_status().backoffice_info_text) or (
......
740 745
            f.edited_data = self.filled
741 746
            f.edit_action_id = action_id
742 747
            f.action_url = 'wfedit-%s' % action_id
743
            get_session().mark_visited_object('formdata-%s-%s' % (
744
                self.formdef.url_name, self.filled.id))
748
            self.filled.mark_as_being_visited()
745 749
            get_response().breadcrumb = get_response().breadcrumb[:-1]
746 750
            get_response().breadcrumb.append((f.action_url, _('Edit')))
747 751
            return f._q_index()
748
-