Constants.pm 4.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Bug Tracking System.
#
# Contributor(s): Marc Schumann <wurblzap@gmail.com>
16
#                 Max Kanat-Alexander <mkanat@bugzilla.org>
17 18 19 20 21 22

package Bugzilla::WebService::Constants;

use strict;
use base qw(Exporter);

23
our @EXPORT = qw(
24 25 26
    WS_ERROR_CODE
    ERROR_UNKNOWN_FATAL
    ERROR_UNKNOWN_TRANSIENT
27
    ERROR_AUTH_NODATA
28 29

    WS_DISPATCH
30 31
);

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
# This maps the error names in global/*-error.html.tmpl to numbers.
# Generally, transient errors should have a number above 0, and
# fatal errors should have a number below 0.
#
# This hash should generally contain any error that could be thrown
# by the WebService interface. If it's extremely unlikely that the
# error could be thrown (like some CodeErrors), it doesn't have to
# be listed here.
#
# "Transient" means "If you resubmit that request with different data,
# it may work."
#
# "Fatal" means, "There's something wrong with Bugzilla, probably
# something an administrator would have to fix."
#
# NOTE: Numbers must never be recycled. If you remove a number, leave a
# comment that it was retired. Also, if an error changes its name, you'll
# have to fix it here.
use constant WS_ERROR_CODE => {
51
    # Generic errors (Bugzilla::Object and others) are 50-99.    
52
    object_not_specified        => 50,
53
    param_required              => 50,
54
    params_required             => 50,
55
    object_does_not_exist       => 51,
56
    xmlrpc_invalid_value        => 52,
57
    # Bug errors usually occupy the 100-200 range.
58 59
    improper_bug_id_field_value => 100,
    bug_id_does_not_exist       => 101,
60
    bug_access_denied           => 102,
61
    bug_access_query            => 102,
62 63 64 65 66 67 68
    # These all mean "invalid alias"
    alias_too_long           => 103,
    alias_in_use             => 103,
    alias_is_numeric         => 103,
    alias_has_comma_or_space => 103,
    # Misc. bug field errors
    illegal_field => 104,
69
    freetext_too_long => 104,
70 71 72 73 74 75
    # Component errors
    require_component       => 105,
    component_name_too_long => 105,
    # Invalid Product
    no_products         => 106,
    entry_access_denied => 106,
76
    product_access_denied => 106,
77 78 79
    product_disabled    => 106,
    # Invalid Summary
    require_summary => 107,
80 81
    # Invalid field name
    invalid_field_name => 108,
82
    # Not authorized to edit the bug
83
    product_edit_denied => 109,
84 85 86
    # Comment-related errors
    comment_is_private => 110,
    comment_id_invalid => 111,
87 88 89
    # See Also errors
    bug_url_invalid => 112,
    bug_url_too_long => 112,
90 91 92 93 94 95

    # Authentication errors are usually 300-400.
    invalid_username_or_password => 300,
    account_disabled             => 301,
    auth_invalid_email           => 302,
    extern_id_conflict           => -303,
96
    auth_failure                 => 304,
97 98 99 100

    # User errors are 500-600.
    account_exists        => 500,
    illegal_email_address => 501,
101 102
    account_creation_disabled   => 501,
    account_creation_restricted => 501,
103 104
    password_too_short    => 502,
    password_too_long     => 503,
105 106 107 108
    invalid_username      => 504,
    # This is from strict_isolation, but it also basically means 
    # "invalid user."
    invalid_user_group    => 504,
109
    user_access_by_id_denied    => 505,
110
    user_access_by_match_denied => 505,
111 112 113 114 115 116
};

# These are the fallback defaults for errors not in ERROR_CODE.
use constant ERROR_UNKNOWN_FATAL     => -32000;
use constant ERROR_UNKNOWN_TRANSIENT => 32000;

117 118 119
use constant ERROR_AUTH_NODATA   => 410;
use constant ERROR_GENERAL       => 999;

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
sub WS_DISPATCH {
    # We "require" here instead of "use" above to avoid a dependency loop.
    require Bugzilla::Hook;
    my %hook_dispatch;
    Bugzilla::Hook::process('webservice', { dispatch => \%hook_dispatch });

    my $dispatch = {
        'Bugzilla' => 'Bugzilla::WebService::Bugzilla',
        'Bug'      => 'Bugzilla::WebService::Bug',
        'User'     => 'Bugzilla::WebService::User',
        'Product'  => 'Bugzilla::WebService::Product',
        %hook_dispatch
    };
    return $dispatch;
};


137
1;