42
42
import javax .faces .context .ExternalContext ;
43
43
import javax .faces .context .FacesContext ;
44
44
import javax .faces .event .ActionEvent ;
45
+ import org .apache .commons .lang .StringUtils ;
45
46
46
47
import org .apache .commons .logging .Log ;
47
48
import org .apache .commons .logging .LogFactory ;
49
+ import org .sakaiproject .authz .api .AuthzGroup ;
50
+ import org .sakaiproject .authz .api .AuthzGroupService ;
51
+ import org .sakaiproject .authz .api .AuthzPermissionException ;
52
+ import org .sakaiproject .authz .api .GroupNotDefinedException ;
48
53
import org .sakaiproject .authz .api .Role ;
49
54
import org .sakaiproject .component .api .ServerConfigurationService ;
50
55
import org .sakaiproject .component .cover .ComponentManager ;
59
64
import org .sakaiproject .tool .api .SessionManager ;
60
65
import org .sakaiproject .tool .api .ToolManager ;
61
66
import org .sakaiproject .umem .api .Authz ;
67
+ import org .sakaiproject .user .api .UserDirectoryService ;
62
68
import org .sakaiproject .user .api .UserNotDefinedException ;
63
- import org .sakaiproject .user .cover .UserDirectoryService ;
64
69
import org .sakaiproject .util .ResourceLoader ;
65
70
66
71
@@ -82,7 +87,7 @@ public class SiteListBean {
82
87
/** Resource bundle */
83
88
private transient ResourceLoader msgs = new ResourceLoader ("org.sakaiproject.umem.tool.bundle.Messages" );
84
89
/** Controller fields */
85
- private List userSitesRows ;
90
+ private List < UserSitesRow > userSitesRows ;
86
91
/** Getter vars */
87
92
private boolean refreshQuery = false ;
88
93
private boolean allowed = false ;
@@ -98,13 +103,21 @@ public class SiteListBean {
98
103
private SiteService M_site = (SiteService ) ComponentManager .get (SiteService .class .getName ());
99
104
private ToolManager M_tm = (ToolManager ) ComponentManager .get (ToolManager .class .getName ());
100
105
private Authz authz = (Authz ) ComponentManager .get (Authz .class .getName ());
106
+ private AuthzGroupService authzGroupService = (AuthzGroupService ) ComponentManager .get ( AuthzGroupService .class .getName () );
107
+ private UserDirectoryService userDirectoryService = (UserDirectoryService ) ComponentManager .get ( UserDirectoryService .class .getName () );
101
108
private ServerConfigurationService M_scf = (ServerConfigurationService ) ComponentManager .get (ServerConfigurationService .class .getName ());
102
109
/** Private vars */
103
110
private RuleBasedCollator collator ;
104
111
private long timeSpentInGroups = 0 ;
105
112
private String portalURL = M_scf .getPortalUrl ();
106
113
private String message = "" ;
107
114
115
+ private final static String frameID = "Main" + org .sakaiproject .tool .cover .ToolManager .getCurrentPlacement ().getId ().replaceAll ( "[-!~]" , "x" );
116
+ public static String getFrameID ()
117
+ {
118
+ return frameID ;
119
+ }
120
+
108
121
// ######################################################################################
109
122
// UserSitesRow CLASS
110
123
// ######################################################################################
@@ -121,6 +134,7 @@ public class UserSitesRow implements Serializable {
121
134
private String pubView ;
122
135
private String userStatus ;
123
136
private String siteTerm ;
137
+ private boolean selected ;
124
138
125
139
{
126
140
try {
@@ -130,6 +144,7 @@ public class UserSitesRow implements Serializable {
130
144
}
131
145
}
132
146
public UserSitesRow () {
147
+ this .selected = false ;
133
148
}
134
149
135
150
public UserSitesRow (String siteId , String siteTitle , String siteType , String groups , String roleName , String pubView , String userStatus , String term ) {
@@ -141,6 +156,7 @@ public UserSitesRow(String siteId, String siteTitle, String siteType, String gro
141
156
this .pubView = pubView ;
142
157
this .userStatus = userStatus ;
143
158
this .siteTerm = term ;
159
+ this .selected = false ;
144
160
}
145
161
146
162
public UserSitesRow (Site site , String groups , String roleName ) {
@@ -152,6 +168,7 @@ public UserSitesRow(Site site, String groups, String roleName) {
152
168
this .pubView = site .isPublished () ? msgs .getString ("status_published" ) : msgs .getString ("status_unpublished" );
153
169
this .userStatus = site .getMember (userId ).isActive () ? msgs .getString ("site_user_status_active" ) : msgs .getString ("site_user_status_inactive" );
154
170
this .siteTerm = site .getProperties ().getProperty (PROP_SITE_TERM );
171
+ this .selected = false ;
155
172
}
156
173
157
174
public String getSiteId () {
@@ -193,7 +210,14 @@ public String getUserStatus(){
193
210
public String getSiteTerm () {
194
211
return siteTerm ;
195
212
}
196
-
213
+
214
+ public boolean isSelected () {
215
+ return selected ;
216
+ }
217
+
218
+ public void setSelected ( boolean selected ) {
219
+ this .selected = selected ;
220
+ }
197
221
}
198
222
199
223
public static final Comparator getUserSitesRowComparator (final String fieldName , final boolean sortAscending , final Collator collator ) {
@@ -283,7 +307,7 @@ public String getInitValues() {
283
307
* @throws SQLException
284
308
*/
285
309
private void doSearch () throws SQLException {
286
- userSitesRows = new ArrayList ();
310
+ userSitesRows = new ArrayList <> ();
287
311
Connection c = null ;
288
312
PreparedStatement pst = null ;
289
313
ResultSet rs = null ;
@@ -346,7 +370,7 @@ private void doSearch() throws SQLException {
346
370
*/
347
371
private void doSearch2 () throws SQLException {
348
372
long start = (new Date ()).getTime ();
349
- userSitesRows = new ArrayList ();
373
+ userSitesRows = new ArrayList <> ();
350
374
thisUserId = M_session .getCurrentSessionUserId ();
351
375
setSakaiSessionUser (userId );
352
376
LOG .debug ("Switched CurrentSessionUserId: " + M_session .getCurrentSessionUserId ());
@@ -371,7 +395,7 @@ private void doSearch2() throws SQLException {
371
395
* @deprecated
372
396
*/
373
397
private void doSearch3 () throws SQLException {
374
- userSitesRows = new ArrayList ();
398
+ userSitesRows = new ArrayList <> ();
375
399
timeSpentInGroups = 0 ;
376
400
Connection c = null ;
377
401
PreparedStatement pst = null ;
@@ -538,7 +562,7 @@ public List getUserSitesRows() {
538
562
return userSitesRows ;
539
563
}
540
564
541
- public void setUserSitesRows (List userRows ) {
565
+ public void setUserSitesRows (List < UserSitesRow > userRows ) {
542
566
this .userSitesRows = userRows ;
543
567
}
544
568
@@ -551,9 +575,9 @@ public boolean isRenderTable() {
551
575
}
552
576
553
577
public String getUserDisplayId () {
554
- String displayId = null ;
578
+ String displayId ;
555
579
try {
556
- displayId = UserDirectoryService .getUser (userId ).getDisplayId ();
580
+ displayId = userDirectoryService .getUser (userId ).getDisplayId ();
557
581
}catch (UserNotDefinedException e ){
558
582
displayId = userId ;
559
583
}
@@ -580,6 +604,80 @@ public void setSitesSortColumn(String sitesSortColumn) {
580
604
this .sitesSortColumn = sitesSortColumn ;
581
605
}
582
606
607
+ /**
608
+ * SAK-29637 - Action listener for the 'Set to Active' button.
609
+ *
610
+ * @param event
611
+ */
612
+ public void setToInactive ( ActionEvent event )
613
+ {
614
+ toggleUserStatusInSites ( false );
615
+ }
616
+
617
+ /**
618
+ * SAK-29637 - Action listener for the 'Set to Inactive' button.
619
+ *
620
+ * @param event
621
+ */
622
+ public void setToActive ( ActionEvent event )
623
+ {
624
+ toggleUserStatusInSites ( true );
625
+ }
626
+
627
+ /**
628
+ * SAK-29637 - Utility method to toggle the user's status in the selected sites.
629
+ *
630
+ * @param active true = toggle to active, false = toggle to inactive
631
+ */
632
+ private void toggleUserStatusInSites ( boolean active )
633
+ {
634
+ // Loop through all user rows (user's sites)
635
+ for ( UserSitesRow row : userSitesRows )
636
+ {
637
+ if ( row .isSelected () )
638
+ {
639
+ // Get the site
640
+ Site site = row .site ;
641
+ if ( site == null )
642
+ {
643
+ try
644
+ {
645
+ site = M_site .getSite ( row .getSiteId () );
646
+ }
647
+ catch ( IdUnusedException ex )
648
+ {
649
+ LOG .warn ( "site not found, id=" + row .getSiteId (), ex );
650
+ }
651
+ }
652
+
653
+ if ( site != null )
654
+ {
655
+ String realmID = site .getReference ();
656
+ try
657
+ {
658
+ String roleID = site .getMember ( userId ).getRole ().getId ();
659
+ AuthzGroup realm = authzGroupService .getAuthzGroup ( realmID );
660
+ boolean isProvided = StringUtils .isNotBlank ( realm .getProviderGroupId () );
661
+ realm .addMember ( userId , roleID , active , isProvided );
662
+ authzGroupService .save ( realm );
663
+ }
664
+ catch ( GroupNotDefinedException ex )
665
+ {
666
+ LOG .warn ( "realm not found, id=" + realmID , ex );
667
+ }
668
+ catch ( AuthzPermissionException ex )
669
+ {
670
+ LOG .warn ( "permission exception updating realm, id=" + realmID , ex );
671
+ }
672
+ }
673
+ }
674
+ }
675
+
676
+ // Refresh the list
677
+ this .refreshQuery = true ;
678
+ getInitValues ();
679
+ }
680
+
583
681
// ######################################################################################
584
682
// CSV export
585
683
// ######################################################################################
@@ -597,15 +695,16 @@ private String getFileNamePrefix() {
597
695
598
696
/**
599
697
* Build a generic tabular representation of the user site membership data export.
698
+ * SAK-29637 - modified to obey user's selection
600
699
*
601
700
* @param userSites The content of the table
602
701
* @return
603
702
* A table of data suitable to be exported
604
703
*/
605
704
private List <List <Object >> buildDataTable (List <UserSitesRow > userSites ) {
606
- List <List <Object >> table = new LinkedList <List < Object > >();
705
+ List <List <Object >> table = new LinkedList <>();
607
706
608
- List <Object > header = new ArrayList <Object >();
707
+ List <Object > header = new ArrayList <>();
609
708
header .add (msgs .getString ("site_name" ));
610
709
header .add (msgs .getString ("site_id" ));
611
710
header .add (msgs .getString ("groups" ));
@@ -615,20 +714,23 @@ private List<List<Object>> buildDataTable(List<UserSitesRow> userSites) {
615
714
header .add (msgs .getString ("status" ));
616
715
header .add (msgs .getString ("site_user_status" ));
617
716
table .add (header );
618
-
717
+
619
718
for (UserSitesRow userSiteRow : userSites ) {
620
- List <Object > currentRow = new ArrayList <Object >();
621
- currentRow .add (userSiteRow .getSiteTitle ());
622
- currentRow .add (userSiteRow .getSiteId ());
623
- currentRow .add (userSiteRow .getGroups ());
624
- currentRow .add (userSiteRow .getSiteType ());
625
- currentRow .add (userSiteRow .getSiteTerm ());
626
- currentRow .add (userSiteRow .getRoleName ());
627
- currentRow .add (userSiteRow .getPubView ());
628
- currentRow .add (userSiteRow .getUserStatus ());
629
- table .add (currentRow );
719
+ if ( userSiteRow .isSelected () )
720
+ {
721
+ List <Object > currentRow = new ArrayList <>();
722
+ currentRow .add (userSiteRow .getSiteTitle ());
723
+ currentRow .add (userSiteRow .getSiteId ());
724
+ currentRow .add (userSiteRow .getGroups ());
725
+ currentRow .add (userSiteRow .getSiteType ());
726
+ currentRow .add (userSiteRow .getSiteTerm ());
727
+ currentRow .add (userSiteRow .getRoleName ());
728
+ currentRow .add (userSiteRow .getPubView ());
729
+ currentRow .add (userSiteRow .getUserStatus ());
730
+ table .add (currentRow );
731
+ }
630
732
}
631
-
733
+
632
734
return table ;
633
- }
735
+ }
634
736
}
0 commit comments