source: peerreviewplugin/tags/0.12/3.1/codereview/util.py

Last change on this file was 15536, checked in by Cinc-th, 7 years ago

PeerReviewPlugin: changed ini file section name for custom settings from peer-review to peerreview for consistency.

File size: 2.4 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# Copyright (C) 2016 Cinc
4# All rights reserved.
5#
6# This software is licensed as described in the file COPYING.txt, which
7# you should have received as part of this distribution.
8#
9# Author: Cinc
10#
11
12from model import PeerReviewModel, PeerReviewerModel, ReviewFileModel
13
14__author__ = 'Cinc'
15__copyright__ = "Copyright 2016"
16__license__ = "BSD"
17
18
19def get_review_for_file(env, file_id):
20    rf = ReviewFileModel(env, file_id)
21    if not rf:
22        return None
23    rev = PeerReviewModel(env, rf['review_id'])
24    return rev
25
26
27def not_allowed_to_comment(env, review, perm, authname):
28    """Check if the current user may comment on a file.
29
30    For adding a comment you must either be:
31
32    * the owner of the review
33    * one of the reviewers
34    * a user with permission CODE_REVIEW_MGR
35
36    @return: True if commenting is not allowed, False otherwise
37    """
38    # Don't let users comment who are not part of this review
39    reviewers = PeerReviewerModel.select_by_review_id(env, review['review_id'])
40    all_names = [reviewer['reviewer'] for reviewer in reviewers]
41    # Include owner of review in allowed names
42    all_names.append(review['owner'])  # We don't care if the name is already in the list
43
44    if authname not in all_names and 'CODE_REVIEW_MGR' not in perm:
45        return True
46
47    return False
48
49
50def review_is_finished(config, review):
51    """A finished review may only be reopened by a manager or admisnistrator
52
53    :param config: Trac config object
54    :param review: review object
55
56    :return True if review is in one of the terminal states
57    """
58    finish_states = config.getlist("peerreview", "terminal_review_states")
59    return review['status'] in finish_states
60
61
62def review_is_locked(config, review, authname=""):
63    """For a locked review a user can't change his voting
64    :param config: Trac config object
65    :param review: review object
66    :authname: login name of user
67
68    :return True if review is in lock state, usually 'reviewed'.
69
70    authname may be an empty string to check if a review is in the lock state at all.
71    If not empty the review is not locked for the user with the given login name.
72    """
73    if review['owner'] == authname:
74        return False
75
76    lock_states = config.getlist("peerreview", "reviewer_locked_states")
77    return review['status'] in lock_states
Note: See TracBrowser for help on using the repository browser.