@@ -216,13 +216,7 @@ public void setUserTeams(String userId, String[] teamIds, String grantorId) thro
216216 } catch (SQLException e ) {
217217 throw new DBCException ("Error saving user teams in database" , e );
218218 }
219- var event = WSSubjectPermissionEvent .update (
220- getSmSessionId (),
221- getUserId (),
222- SMSubjectType .user ,
223- userId
224- );
225- application .getEventController ().addEvent (event );
219+ addSubjectPermissionsUpdateEvent (userId , SMSubjectType .user );
226220 }
227221
228222
@@ -599,13 +593,7 @@ public void setUserAuthRole(@NotNull String userId, @Nullable String authRole) t
599593 } catch (SQLException e ) {
600594 throw new DBCException ("Error while updating user authentication role" , e );
601595 }
602- var event = WSSubjectPermissionEvent .update (
603- getSmSessionId (),
604- getUserId (),
605- SMSubjectType .user ,
606- userId
607- );
608- application .getEventController ().addEvent (event );
596+ addSubjectPermissionsUpdateEvent (userId , SMSubjectType .user );
609597 }
610598
611599
@@ -1040,13 +1028,7 @@ public void deleteTeam(String teamId, boolean force) throws DBCException {
10401028 throw new DBCException ("Error deleting team from database" , e );
10411029 }
10421030 if (force ) {
1043- var event = WSSubjectPermissionEvent .update (
1044- getSmSessionId (),
1045- getUserId (),
1046- SMSubjectType .team ,
1047- teamId
1048- );
1049- application .getEventController ().addEvent (event );
1031+ addSubjectPermissionsUpdateEvent (teamId , SMSubjectType .team );
10501032 }
10511033 }
10521034
@@ -1082,6 +1064,7 @@ public void setSubjectPermissions(String subjectId, List<String> permissionIds,
10821064 } catch (SQLException e ) {
10831065 throw new DBCException ("Error saving subject permissions in database" , e );
10841066 }
1067+ addSubjectPermissionsUpdateEvent (subjectId , null );
10851068 }
10861069
10871070 private void insertPermissions (Connection dbCon , String subjectId , String [] permissionIds , String grantorId ) throws SQLException {
@@ -2231,6 +2214,7 @@ public void setObjectPermissions(
22312214 @ NotNull String grantor
22322215 ) throws DBException {
22332216 if (CommonUtils .isEmpty (objectIds )) {
2217+ subjectIds .forEach (id -> addSubjectPermissionsUpdateEvent (id , null ));
22342218 return ;
22352219 } else if (CommonUtils .isEmpty (subjectIds )) {
22362220 addObjectPermissionsUpdateEvent (objectIds , objectType );
@@ -2280,6 +2264,25 @@ public void setObjectPermissions(
22802264 }
22812265 }
22822266
2267+
2268+
2269+ private void addSubjectPermissionsUpdateEvent (@ NotNull String subjectId , @ Nullable SMSubjectType subjectType ) {
2270+ if (subjectType == null ) {
2271+ subjectType = getSubjectType (subjectId );
2272+ }
2273+ if (subjectType == null ) {
2274+ log .error ("Subject type is not found for subject '" + subjectId + "'" );
2275+ return ;
2276+ }
2277+ var event = WSSubjectPermissionEvent .update (
2278+ getSmSessionId (),
2279+ getUserId (),
2280+ subjectType ,
2281+ subjectId
2282+ );
2283+ application .getEventController ().addEvent (event );
2284+ }
2285+
22832286 private void addObjectPermissionsUpdateEvent (@ NotNull Set <String > objectIds , @ NotNull SMObjectType objectType ) {
22842287 for (var objectId : objectIds ) {
22852288 var event = WSObjectPermissionEvent .update (
@@ -2625,14 +2628,33 @@ public Set<String> getFilteredSubjects(Set<String> allSubjects) {
26252628 result .add (dbResult .getString (1 ));
26262629 }
26272630 }
2628- };
2631+ }
26292632 return result ;
26302633 } catch (SQLException e ) {
26312634 log .error ("Error getting all subject ids from database" , e );
26322635 return Set .of ();
26332636 }
26342637 }
26352638
2639+ private SMSubjectType getSubjectType (@ NotNull String subjectId ) {
2640+ try (Connection dbCon = database .openConnection ()) {
2641+ Set <String > result = new HashSet <>();
2642+ String sqlBuilder = "SELECT SUBJECT_TYPE FROM {table_prefix}CB_AUTH_SUBJECT U WHERE SUBJECT_ID = ?" ;
2643+ try (var dbStat = dbCon .prepareStatement (database .normalizeTableNames (sqlBuilder ))) {
2644+ dbStat .setString (1 , subjectId );
2645+ try (ResultSet dbResult = dbStat .executeQuery ()) {
2646+ if (dbResult .next ()) {
2647+ return SMSubjectType .fromCode (dbResult .getString (1 ));
2648+ }
2649+ }
2650+ }
2651+ return null ;
2652+ } catch (SQLException e ) {
2653+ log .error ("Error getting all subject ids from database" , e );
2654+ return null ;
2655+ }
2656+ }
2657+
26362658 @ Nullable
26372659 private String getSmSessionId () {
26382660 var credentials = credentialsProvider .getActiveUserCredentials ();
0 commit comments