Code Duplication    Length = 30-33 lines in 2 locations

bika/lims/workflow/analysis/guards.py 2 locations

@@ 178-210 (lines=33) @@
175
    return dependencies_guard(analysis, ["verify", "multi_verify"])
176
177
178
def guard_verify(analysis):
179
    """Return whether the transition "verify" can be performed or not
180
    """
181
    # Check if multi-verification
182
    remaining_verifications = analysis.getNumberOfRemainingVerifications()
183
    if remaining_verifications > 1:
184
        return False
185
186
    # Check if the current user is the same that submitted the result
187
    user_id = api.get_current_user().getId()
188
    if (analysis.getSubmittedBy() == user_id):
189
        if not analysis.isSelfVerificationEnabled():
190
            return False
191
192
    if analysis.getNumberOfRequiredVerifications() <= 1:
193
        # Check dependencies (analyses this analysis depends on)
194
        return dependencies_guard(analysis, "verify")
195
196
    # This analysis requires more than one verification
197
    # Check if user is the last verifier and consecutive multi-verification is
198
    # disabled
199
    verifiers = analysis.getVerificators()
200
    mv_type = analysis.bika_setup.getTypeOfmultiVerification()
201
    if verifiers and verifiers[:-1] == user_id \
202
            and mv_type == "self_multi_not_cons":
203
        return False
204
205
    # Check if user verified before and self multi-verification is disabled
206
    if user_id in verifiers and mv_type == "self_multi_disabled":
207
        return False
208
209
    # Check dependencies (analyses this analysis depends on)
210
    return dependencies_guard(analysis, ["verify", "multi_verify"])
211
212
213
def guard_retract(analysis):
@@ 146-175 (lines=30) @@
143
    return dependencies_guard(analysis, "submit")
144
145
146
def guard_multi_verify(analysis):
147
    """Return whether the transition "multi_verify" can be performed or not
148
    The transition multi_verify will only take place if multi-verification of
149
    results is enabled.
150
    """
151
    # If there is only one remaining verification, return False
152
    remaining_verifications = analysis.getNumberOfRemainingVerifications()
153
    if remaining_verifications <= 1:
154
        return False
155
156
    # Check if the current user is the same who submitted the result
157
    user_id = api.get_current_user().getId()
158
    if (analysis.getSubmittedBy() == user_id):
159
        if not analysis.isSelfVerificationEnabled():
160
            return False
161
162
    # Check if user is the last verifier and consecutive multi-verification is
163
    # disabled
164
    verifiers = analysis.getVerificators()
165
    mv_type = analysis.bika_setup.getTypeOfmultiVerification()
166
    if verifiers and verifiers[:-1] == user_id \
167
            and mv_type == "self_multi_not_cons":
168
        return False
169
170
    # Check if user verified before and self multi-verification is disabled
171
    if user_id in verifiers and mv_type == "self_multi_disabled":
172
        return False
173
174
    # Check dependencies (analyses this analysis depends on)
175
    return dependencies_guard(analysis, ["verify", "multi_verify"])
176
177
178
def guard_verify(analysis):