Skip to content

Commit

Permalink
User with access to single project defaults to it, not all projects
Browse files Browse the repository at this point in the history
Since 1.2, if a user has access to only one project, the project
selection box at top right isn't shown. This was causing issues as new
users accounts have 'All projects' as their default:

 - user can't report issues (no link for all projects)
 - categories displayed are prefixed with [project]

Until this commit, users had to define their (single) project as default
using preferences to work around the problem; this is no longer needed.

Function html_login_info() now sets the current project as appropriate
if user has only access to a single one, and also defines that as the
default.

The account preferences page has also been modified to only include 'All
projects' in the selection list when user has more than one project
available.

Fixes #9826, #14268
  • Loading branch information
dregad committed Sep 10, 2012
1 parent 87c7423 commit cfa022b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 10 additions & 1 deletion account_prefs_inc.php
Expand Up @@ -92,7 +92,16 @@ function edit_account_prefs($p_user_id = null, $p_error_if_protected = true, $p_
<label for="default-project-id"><span><?php echo lang_get( 'default_project' ) ?></span></label>
<span class="select">
<select id="default-project-id" name="default_project">
<?php print_project_option_list( (int)$t_pref->default_project ) ?>
<?php
# Count number of available projects
$t_projects = current_user_get_accessible_projects();
$t_num_proj = count( $t_projects );
if( $t_num_proj == 1 ) {
$t_num_proj += count( current_user_get_accessible_subprojects( $t_projects[0] ) );
}
# Only display "All projects" in selection list if there is more than 1
print_project_option_list( (int)$t_pref->default_project, $t_num_proj > 1 );
?>
</select>
</span>
<span class="label-style"></span>
Expand Down
16 changes: 11 additions & 5 deletions core/html_api.php
Expand Up @@ -544,12 +544,10 @@ function html_login_info() {
}
echo '</div>';


# Project Selector hidden if only one project visisble to user
$t_show_project_selector = true;
if( count( current_user_get_accessible_projects() ) == 1 ) {

// >1
$t_project_ids = current_user_get_accessible_projects();
$t_project_ids = current_user_get_accessible_projects();
if( count( $t_project_ids ) == 1 ) {
$t_project_id = (int) $t_project_ids[0];
if( count( current_user_get_accessible_subprojects( $t_project_id ) ) == 0 ) {
$t_show_project_selector = false;
Expand Down Expand Up @@ -579,6 +577,14 @@ function html_login_info() {
echo '</form>';
echo '<div id="current-time">' . $t_now . '</div>';
} else {
# User has only one project, set it as both current and default
if( ALL_PROJECTS == helper_get_current_project() ) {
helper_set_current_project( $t_project_id );
current_user_set_default_project( $t_project_id );
# Force reload of current page
$t_redirect_url = str_replace( config_get( 'short_path' ), '', $_SERVER['REQUEST_URI'] );
html_meta_redirect( $t_redirect_url, 0, false );
}
echo '<div id="current-time-centered">' . $t_now . '</div>';
}
}
Expand Down

0 comments on commit cfa022b

Please sign in to comment.