Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Association-Cocktail/mantisbt int…
Browse files Browse the repository at this point in the history
…o maturbet-ldapfieldsevent-1
  • Loading branch information
maturbet committed Apr 30, 2020
2 parents 3732212 + c142c21 commit 191a3a2
Show file tree
Hide file tree
Showing 161 changed files with 5,554 additions and 1,416 deletions.
1 change: 1 addition & 0 deletions .imgbotconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"schedule": "daily",
"ignoredFiles": [
"css/images/*",
"fonts/*",
],
"aggressiveCompression": "false"
}
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ before_install:
- if php -r "exit( (int)! version_compare( '$TRAVIS_PHP_VERSION', '7.0', '>=' ) );"; then mkdir -p ~/bin && wget -O ~/bin/phpunit https://phar.phpunit.de/phpunit-5.7.phar && chmod +x ~/bin/phpunit; fi

before_script:
- ./scripts/travis_before_script.sh
- ./build-scripts/travis_before_script.sh

script:
- ./scripts/travis_script.sh
- ./build-scripts/travis_script.sh

# -----------------------------------------------------------------------------
# What to build, and on which platforms
Expand Down
4 changes: 2 additions & 2 deletions account_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
</td>
<td>
<?php
if( $t_ldap && ON == config_get( 'use_ldap_email' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_email' ) ) {
# With LDAP
echo string_display_line( $u_email );
} else {
Expand All @@ -220,7 +220,7 @@
</td>
</tr>
<tr><?php
if( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) {
if( $t_ldap && ON == config_get_global( 'use_ldap_realname' ) ) {
# With LDAP
echo '<td class="category">' . lang_get( 'realname' ) . '</td>';
echo '<td>';
Expand Down
2 changes: 1 addition & 1 deletion account_prof_edit_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
</tr>
<tr>
<th class="category">
<span class="required">*</span><?php echo lang_get( 'os_version' ) ?>
<span class="required">*</span><?php echo lang_get( 'os_build' ) ?>
</th>
<td>
<input type="text" name="os_build" class="input-sm" size="16" maxlength="16" value="<?php echo string_attribute( $v_os_build ) ?>" required />
Expand Down
4 changes: 2 additions & 2 deletions account_prof_menu_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@
</tr>
<tr>
<td class="category">
<span class="required">*</span> <?php echo lang_get( 'os_version' ) ?>
<span class="required">*</span> <?php echo lang_get( 'os_build' ) ?>
</td>
<td>
<input id="os-version" type="text" name="os_build" class="input-sm" size="16" maxlength="16" required />
<input id="os-build" type="text" name="os_build" class="input-sm" size="16" maxlength="16" required />
</td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions account_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@

# Update email (but only if LDAP isn't being used)
# Do not update email for a user verification
if( !( $t_ldap && config_get( 'use_ldap_email' ) )
if( !( $t_ldap && config_get_global( 'use_ldap_email' ) )
&& !$t_account_verification ) {
if( !is_blank( $f_email ) && $f_email != user_get_email( $t_user_id ) ) {
$t_update_email = true;
}
}

# Update real name (but only if LDAP isn't being used)
if( !( $t_ldap && config_get( 'use_ldap_realname' ) ) ) {
if( !( $t_ldap && config_get_global( 'use_ldap_realname' ) ) ) {
# strip extra spaces from real name
$t_realname = string_normalize( $f_realname );
if( $t_realname != user_get_field( $t_user_id, 'realname' ) ) {
Expand Down
16 changes: 16 additions & 0 deletions admin/check/check_config_inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@
array( false => 'Issues moved may end up with invalid category id.' )
);

$t_field_options = array(
'bug_report_page_fields',
'bug_view_page_fields',
'bug_update_page_fields'
);

foreach( $t_field_options as $t_field_option ) {
$t_fields = config_get( $t_field_option, null, ALL_USERS, ALL_PROJECTS );
check_print_test_warn_row(
$t_field_option . ' configuration option does not contain "os_version"',
!in_array ( 'os_version', $t_fields ),
array( false => 'You need to replace "os_version" by "os_build" for the ' . $t_field_option . ' configuration option '
. '(see issue <a href="https://mantisbt.org/bugs/view.php?id=26840">#26840</a>).')
);
}

# Deprecated Settings
check_print_test_warn_row( 'Deprecated "limit_reporters" setting should no longer be used',
$g_limit_reporters == OFF,
Expand Down
2 changes: 1 addition & 1 deletion admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function print_info_row( $p_description, $p_value ) {
</td>
</tr>
<?php
print_info_row( lang_get( 'schema_version' ), config_get( 'database_version' ) );
print_info_row( lang_get( 'schema_version' ), config_get( 'database_version', 0, ALL_USERS, ALL_PROJECTS ) );
print_info_row( lang_get( 'adodb_version' ), $g_db->Version() );
?>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions admin/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function print_test( $p_test_description, $p_result, $p_hard_fail = true, $p_mes
$g_db_connected = true;
}

$t_cur_version = config_get( 'database_version', -1 );
$t_cur_version = config_get( 'database_version', -1, ALL_USERS, ALL_PROJECTS);

if( $t_cur_version > 1 ) {
$g_database_upgrade = true;
Expand Down Expand Up @@ -1101,7 +1101,7 @@ function print_test( $p_test_description, $p_result, $p_hard_fail = true, $p_mes
echo '</td>';
if( $t_ret == 2 ) {
print_test_result( GOOD );
config_set( 'database_version', $i );
config_set( 'database_version', $i, ALL_USERS, ALL_PROJECTS );
} else {
$t_all_sql = '';
if( $t_sql ) {
Expand Down
4 changes: 2 additions & 2 deletions admin/upgrade_unattended.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function print_test_result( $p_result, $p_hard_fail = true, $p_message = '' ) {

# TODO: Enhance this check to support the mode where this script is called on an empty database.
# check to see if the new installer was used
if( -1 == config_get( 'database_version', -1 ) ) {
if( -1 == config_get( 'database_version', -1, ALL_USERS, ALL_PROJECTS ) ) {
echo 'Upgrade from the current installed MantisBT version is no longer supported. If you are using MantisBT version older than 1.0.0, then upgrade to v1.0.0 first.';
exit( 1 );
}
Expand Down Expand Up @@ -180,7 +180,7 @@ function print_test_result( $p_result, $p_hard_fail = true, $p_message = '' ) {

if( $t_ret == 2 ) {
print_test_result( GOOD );
config_set( 'database_version', $i );
config_set( 'database_version', $i, ALL_USERS, ALL_PROJECTS );
} else {
$t_msg = $t_sqlarray[0];
if( !is_blank( $g_db->ErrorMsg() ) ) {
Expand Down
112 changes: 9 additions & 103 deletions api/rest/restcore/config_rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,117 +30,23 @@
/**
* A method that does the work to handle getting a set of configs via REST API.
*
* The following query string parameters are supported:
* - option/option[]: can be a string or an array
* - project_id: an optional parameter for project id to get configs for. Default ALL_PROJECTS (0).
* - user_id: an optional parameter for user id to get configs for. Default current user.
* can be 0 for ALL_USERS.
*
* The response will include a config key that is an array of requested configs. Configs
* that are not public or are not defined will be filtered out, and request will still succeed.
* This is to make it easier to request configs that maybe defined in some versions of MantisBT
* but not others.
*
* Note that only users with ADMINISTRATOR access can fetch configuration for other users.
*
* @param \Slim\Http\Request $p_request The request.
* @param \Slim\Http\Response $p_response The response.
* @param array $p_args Arguments
* @return \Slim\Http\Response The augmented response.
*/
function rest_config_get( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_options = $p_request->getParam( 'option' );
if( !is_array( $t_options ) ) {
$t_options = array( $t_options );
}

$t_project_id = $p_request->getParam( 'project_id' );
if( is_null( $t_project_id ) ) {
$t_project_id = ALL_PROJECTS;
}

if( $t_project_id != ALL_PROJECTS && !project_exists( $t_project_id ) ) {
return $p_response->withStatus( HTTP_STATUS_NOT_FOUND, "Project with id '$t_project_id' not found" );
}

$t_user_id = $p_request->getParam( 'user_id' );
if( is_null( $t_user_id ) ) {
$t_user_id = auth_get_current_user_id();
} else {
if( $t_user_id != ALL_USERS &&
$t_user_id != auth_get_current_user_id() &&
!current_user_is_administrator() ) {
return $p_response->withStatus( HTTP_STATUS_FORBIDDEN, 'Admin access required to get configs for other users' );
}

if( $t_user_id != ALL_USERS && user_exists( $t_user_id ) ) {
return $p_response->withStatus( HTTP_STATUS_NOT_FOUND, "User with id '$t_user_id' not found" );
}
}
$t_data = array(
'query' => array(
'option' => $p_request->getParam( 'option' ),
'project_id' => $p_request->getParam( 'project_id' ),
'user_id' => $p_request->getParam( 'user_id' ),
)
);

$t_configs = array();
foreach( $t_options as $t_option ) {
# Filter out undefined configs rather than error, they may be valid in some MantisBT versions but not
# others.
if( !config_is_set( $t_option ) ) {
continue;
}

# Filter out private configs, since they can be private in some configs but public in others.
if( config_is_private( $t_option ) ) {
continue;
}

$t_value = config_get( $t_option, /* default */ null, $t_user_id, $t_project_id );
if( config_is_enum( $t_option ) ) {
$t_value = config_get_enum_as_array( $t_option, $t_value );
}

$t_config_pair = array(
"option" => $t_option,
"value" => $t_value
);

$t_configs[] = $t_config_pair;
}

# wrap all configs into a configs attribute to allow adding other information if needed in the future
# that belongs outside the configs response.
$t_result = array( 'configs' => $t_configs );
$t_command = new ConfigsGetCommand( $t_data );
$t_result = $t_command->execute( $t_data );

return $p_response->withStatus( HTTP_STATUS_SUCCESS )->withJson( $t_result );
}

/**
* Checks if the specific config option is an enum.
*
* @param string $p_option The option name.
* @return bool true enum, false otherwise.
*/
function config_is_enum( $p_option ) {
return stripos( $p_option, '_enum_string' ) !== false;
}

/**
* Gets the enum config option as an array with the id as the key and the value
* as an array with name and label (localized name) keys.
*
* @param string $p_enum_name The enum config option name.
* @param string $p_enum_string_value The enum config option value.
* @return array The enum array.
*/
function config_get_enum_as_array( $p_enum_name, $p_enum_string_value ) {
$t_enum_assoc_array = MantisEnum::getAssocArrayIndexedByValues( $p_enum_string_value );
$t_localized_enum_string = lang_get( $p_enum_name );

$t_enum_array = array();

foreach( $t_enum_assoc_array as $t_id => $t_name ) {
$t_label = MantisEnum::getLocalizedLabel( $p_enum_string_value, $t_localized_enum_string, $t_id );
$t_enum_entry = array( 'id' => $t_id, 'name' => $t_name, 'label' => $t_label );
$t_enum_array[] = $t_enum_entry;
}

return $t_enum_array;
}

37 changes: 9 additions & 28 deletions api/rest/restcore/lang_rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,22 @@
});

/**
* A method that does the work to handle getting a set of configs via REST API.
*
* The following query string parameters are supported:
* - string/string[]: can be a string or an array
*
* The response will include a config key that is an array of requested configs. Configs
* that are not public or are not defined will be filtered out, and request will still succeed.
* This is to make it easier to request configs that maybe defined in some versions of MantisBT
* but not others.
*
* Note that only users with ADMINISTRATOR access can fetch configuration for other users.
* A method that does the work to handle getting a set of localized strings via REST API.
*
* @param \Slim\Http\Request $p_request The request.
* @param \Slim\Http\Response $p_response The response.
* @param array $p_args Arguments
* @return \Slim\Http\Response The augmented response.
*/
function rest_lang_get( \Slim\Http\Request $p_request, \Slim\Http\Response $p_response, array $p_args ) {
$t_strings = $p_request->getParam( 'string' );
if( !is_array( $t_strings ) ) {
$t_strings = array( $t_strings );
}

$t_current_language = lang_get_current();
$t_localized_strings = array();
foreach( $t_strings as $t_string ) {
if( !lang_exists( $t_string, $t_current_language) ) {
continue;
}

$t_localized_strings[] = array( 'name' => $t_string, 'localized' => lang_get( $t_string ) );
}

$t_result = array( 'strings' => $t_localized_strings );
$t_result['language'] = $t_current_language;
$t_data = array(
'query' => array(
'string' => $p_request->getParam( 'string' )
)
);

$t_command = new LocalizedStringsGetCommand( $t_data );
$t_result = $t_command->execute();

return $p_response->withStatus( HTTP_STATUS_SUCCESS )->withJson( $t_result );
}
6 changes: 3 additions & 3 deletions bug_report_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
$t_show_profiles = config_get( 'enable_profiles' );
$t_show_platform = $t_show_profiles && in_array( 'platform', $t_fields );
$t_show_os = $t_show_profiles && in_array( 'os', $t_fields );
$t_show_os_version = $t_show_profiles && in_array( 'os_version', $t_fields );
$t_show_os_build = $t_show_profiles && in_array( 'os_build', $t_fields );
$t_show_resolution = in_array( 'resolution', $t_fields );
$t_show_status = in_array( 'status', $t_fields );
$t_show_tags =
Expand Down Expand Up @@ -370,7 +370,7 @@
</td>
</tr>
<?php } ?>
<?php if( $t_show_platform || $t_show_os || $t_show_os_version ) { ?>
<?php if( $t_show_platform || $t_show_os || $t_show_os_build ) { ?>
<tr>
<th class="category">
<label for="profile_id"><?php echo lang_get( 'select_profile' ) ?></label>
Expand Down Expand Up @@ -420,7 +420,7 @@
</tr>
<tr>
<th class="category">
<label for="os_build"><?php echo lang_get( 'os_version' ) ?></label>
<label for="os_build"><?php echo lang_get( 'os_build' ) ?></label>
</th>
<td>
<?php
Expand Down
8 changes: 4 additions & 4 deletions bug_update_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
$t_show_profiles = config_get( 'enable_profiles' ) == ON;
$t_show_platform = $t_show_profiles && in_array( 'platform', $t_fields );
$t_show_os = $t_show_profiles && in_array( 'os', $t_fields );
$t_show_os_version = $t_show_profiles && in_array( 'os_version', $t_fields );
$t_show_os_build = $t_show_profiles && in_array( 'os_build', $t_fields );
$t_show_versions = version_should_show_product_version( $t_bug->project_id );
$t_show_product_version = $t_show_versions && in_array( 'product_version', $t_fields );
$t_show_product_build = $t_show_versions && in_array( 'product_build', $t_fields ) && ( config_get( 'enable_product_build' ) == ON );
Expand Down Expand Up @@ -490,7 +490,7 @@
# Platform, OS, OS Version
#

if( $t_show_platform || $t_show_os || $t_show_os_version ) {
if( $t_show_platform || $t_show_os || $t_show_os_build ) {
echo '<tr>';

$t_spacer = 0;
Expand Down Expand Up @@ -531,9 +531,9 @@
$t_spacer += 2;
}

if( $t_show_os_version ) {
if( $t_show_os_build ) {
# OS Version
echo '<th class="category"><label for="os_build">' . lang_get( 'os_version' ) . '</label></th>';
echo '<th class="category"><label for="os_build">' . lang_get( 'os_build' ) . '</label></th>';
echo '<td>';

if( config_get( 'allow_freetext_in_profile_fields' ) == OFF ) {
Expand Down

0 comments on commit 191a3a2

Please sign in to comment.