[dw-free] Lacks function to return a list of sorted trust groups
[commit: http://hg.dwscoalition.org/dw-free/rev/0fab2892cfcc]
http://bugs.dwscoalition.org/show_bug.cgi?id=1616
Sort trust groups on all pages that use them. This sorts by the sortorder
(user defined), and falls back to sorting alphabetically if no sort is
defined.
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1616
Sort trust groups on all pages that use them. This sorts by the sortorder
(user defined), and falls back to sorting alphabetically if no sort is
defined.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/DW/User/Edges/WatchTrust/Loader.pm
- cgi-bin/LJ/User.pm
- cgi-bin/weblib.pl
- htdocs/manage/circle/add.bml
- htdocs/manage/circle/editfilters.bml
- htdocs/manage/emailpost.bml
- htdocs/manage/tags.bml
-------------------------------------------------------------------------------- diff -r 1bfddd15a0c0 -r 0fab2892cfcc cgi-bin/DW/User/Edges/WatchTrust/Loader.pm --- a/cgi-bin/DW/User/Edges/WatchTrust/Loader.pm Thu Aug 27 05:17:36 2009 +0000 +++ b/cgi-bin/DW/User/Edges/WatchTrust/Loader.pm Thu Aug 27 05:22:30 2009 +0000 @@ -332,7 +332,12 @@ sub _trust_groups { } # no arg, return entire object - return { map { $_->[1] => LJ::MemCache::array_to_hash( 'trust_group', [$memver, @$_] ) } @$fg }; + if ( wantarray ) { # group list sorted by sortorder || name order + return map { LJ::MemCache::array_to_hash( 'trust_group', [$memver, @$_] ) } + sort { $a->[3] <=> $b->[3] || $a->[2] cmp $b->[2] } @$fg; + } else { # ref to hash keyed by bitnum + return { map { $_->[1] => LJ::MemCache::array_to_hash( 'trust_group', [$memver, @$_] ) } @$fg }; + } }; # check memcache diff -r 1bfddd15a0c0 -r 0fab2892cfcc cgi-bin/LJ/User.pm --- a/cgi-bin/LJ/User.pm Thu Aug 27 05:17:36 2009 +0000 +++ b/cgi-bin/LJ/User.pm Thu Aug 27 05:22:30 2009 +0000 @@ -3606,11 +3606,11 @@ sub security_group_display { my @ret; - my $groups = $u->trust_groups || {}; - foreach my $groupid ( keys %$groups ) { - next unless $group_ids{$groupid}; # not in mask - - my $name = LJ::ehtml( $groups->{$groupid}->{groupname} ); + my @groups = $u->trust_groups; + foreach my $group ( @groups ) { + next unless $group_ids{$group->{groupnum}}; # not in mask + + my $name = LJ::ehtml( $group->{groupname} ); if ( $use_urls ) { my $url = LJ::eurl( $u->journal_base . "/security/group:$name" ); push @ret, "<a href='$url'>$name</a>"; diff -r 1bfddd15a0c0 -r 0fab2892cfcc cgi-bin/weblib.pl --- a/cgi-bin/weblib.pl Thu Aug 27 05:17:36 2009 +0000 +++ b/cgi-bin/weblib.pl Thu Aug 27 05:22:30 2009 +0000 @@ -1783,9 +1783,9 @@ PREVIEW my @secs = ("public", $string_public, "friends", $is_comm ? $string_friends_comm : $string_friends); push @secs, ("private", $string_private) unless $is_comm; - my @secopts; - my $trust_groups = $remote && $remote->trust_groups; - if ( ref $trust_groups eq 'HASH' && scalar keys %$trust_groups && !$is_comm ) { + my ( @secopts, @trust_groups ); + @trust_groups = $remote->trust_groups if $remote; + if ( scalar @trust_groups && !$is_comm ) { push @secs, ("custom", $string_custom); push @secopts, ("onchange" => "customboxes()"); } @@ -1795,17 +1795,18 @@ PREVIEW 'tabindex' => $tabindex->(), @secopts }, @secs) . "\n"; # if custom security groups available, show them in a hideable div - if ( ref $trust_groups eq 'HASH' && scalar keys %$trust_groups ) { + if ( scalar @trust_groups ) { my $display = $opts->{'security'} eq "custom" ? "block" : "none"; $out .= LJ::help_icon("security", "<span id='security-help'>\n", "\n</span>\n"); $out .= "<div id='custom_boxes' class='pkg' style='display: $display;'>\n"; $out .= "<ul id='custom_boxes_list'>"; - foreach my $fg ( sort { $trust_groups->{$a}->{sortorder} <=> $trust_groups->{$b}->{sortorder} } keys %$trust_groups ) { + foreach my $group ( @trust_groups ) { + my $fg = $group->{groupnum}; $out .= "<li>"; $out .= LJ::html_check({ 'name' => "custom_bit_$fg", 'id' => "custom_bit_$fg", 'selected' => $opts->{"custom_bit_$fg"} || $opts->{'security_mask'}+0 & 1 << $fg }) . " "; - $out .= "<label for='custom_bit_$fg'>" . LJ::ehtml($trust_groups->{$fg}->{groupname}) . "</label>\n"; + $out .= "<label for='custom_bit_$fg'>" . LJ::ehtml( $group->{groupname} ) . "</label>\n"; $out .= "</li>"; } $out .= "</ul>"; diff -r 1bfddd15a0c0 -r 0fab2892cfcc htdocs/manage/circle/add.bml --- a/htdocs/manage/circle/add.bml Thu Aug 27 05:17:36 2009 +0000 +++ b/htdocs/manage/circle/add.bml Thu Aug 27 05:22:30 2009 +0000 @@ -181,13 +181,13 @@ }); } - my $trust_groups = $remote->trust_groups; + my @trust_groups = $remote->trust_groups; ## let them pick friend groups # FIXME: Add support for reading groups once those exist my $err; - if ( $remote->can_trust( $u ) && keys %$trust_groups ) { + if ( $remote->can_trust( $u ) && @trust_groups ) { ## extra add and cancel buttons $body .= "<br /><br />"; @@ -208,16 +208,16 @@ $body .= "<?p <br />"; $body .= "$ML{'.groups.text1'} " . LJ::help_icon('customgroups', ' ') . "p?>\n"; $body .= "<blockquote>\n"; - foreach my $g ( sort { lc $trust_groups->{$a}->{groupname} cmp - lc $trust_groups->{$b}->{groupname} } keys %$trust_groups ) { - my $ck = ( $remote->trustmask( $u ) & (1 << $g) ); + foreach my $group ( @trust_groups ) { + my $g = $group->{groupnum}; + my $ck = ( $remote->trustmask( $u ) & (1 << $g) ); - $body .= LJ::html_check({ 'name' => "bit_$g", - 'id' => "fg:bit_$g", - 'selected' => $ck, - 'label' => $trust_groups->{$g}->{groupname} }); - $body .= "<br />\n"; - } + $body .= LJ::html_check( { name => "bit_$g", + id => "fg:bit_$g", + selected => $ck, + label => $group->{groupname} } ); + $body .= "<br />\n"; + } $body .= "</blockquote>"; } diff -r 1bfddd15a0c0 -r 0fab2892cfcc htdocs/manage/circle/editfilters.bml --- a/htdocs/manage/circle/editfilters.bml Thu Aug 27 05:17:36 2009 +0000 +++ b/htdocs/manage/circle/editfilters.bml Thu Aug 27 05:22:30 2009 +0000 @@ -414,10 +414,10 @@ END_JS $body .= "<tr style='vertical-align: top;'>"; $body .= "<td><select name='list_groups' style='width: 150px;' size='15' onchange='groupClicked();'>"; - foreach my $trustgroupid ( sort { $trust_groups->{$a}->{sortorder} <=> $trust_groups->{$b}->{sortorder} } keys %$trust_groups ) { - my $listname = $trust_groups->{$trustgroupid}->{groupname}; - $listname .= " $ML{'.group.public'}" if $trust_groups->{$trustgroupid}->{is_public}; - $body .= "<option value='$trustgroupid'>" . LJ::ehtml($listname); + foreach my $trustgroup ( $u->trust_groups ) { + my $listname = $trustgroup->{groupname}; + $listname .= " $ML{'.group.public'}" if $trustgroup->{is_public}; + $body .= "<option value='$trustgroup->{groupnum}'>" . LJ::ehtml($listname); } $body .= "</select></td>"; diff -r 1bfddd15a0c0 -r 0fab2892cfcc htdocs/manage/emailpost.bml --- a/htdocs/manage/emailpost.bml Thu Aug 27 05:17:36 2009 +0000 +++ b/htdocs/manage/emailpost.bml Thu Aug 27 05:22:30 2009 +0000 @@ -358,9 +358,8 @@ body<= { "noauth" => 1, } ); - my $trusted = $u->trust_groups; - my @groups = map { $trusted->{$_}->{'groupname'} } - sort { $trusted->{$a}->{'sortorder'} <=> $trusted->{$b}->{'sortorder'} } keys %$trusted; + my @trusted = $u->trust_groups; + my @groups = map { $_->{'groupname'} } @trusted; my @userpics = @{ $res->{'pickws'} }; $ret .= "<?p " . BML::ml('.intro', {'aopts' => "href='$LJ::SITEROOT/manage/emailpost?mode=help'"}) . " p?><br />"; diff -r 1bfddd15a0c0 -r 0fab2892cfcc htdocs/manage/tags.bml --- a/htdocs/manage/tags.bml Thu Aug 27 05:17:36 2009 +0000 +++ b/htdocs/manage/tags.bml Thu Aug 27 05:22:30 2009 +0000 @@ -301,10 +301,8 @@ HEAD push @groups, ("private", $ML{'.setting.maintainers'}); } - my $grouplist = $u->trust_groups; - push @groups, map { "group:" . $_, $grouplist->{$_}->{groupname} } - sort { $grouplist->{$a}->{groupname} cmp $grouplist->{$b}->{groupname} } - keys %$grouplist; + my @grouplist = $u->trust_groups; + push @groups, map { "group:" . $_->{groupnum}, $_->{groupname} } @grouplist; my $security = LJ::Tags::get_permission_levels($u); --------------------------------------------------------------------------------