/** * Returns a HQL string that determines whether an object is readable * by a user. * * @param x the object to test for readability. * @param u the user who might be able to read the object. * @return HQL that evaluates to true or false depending on readability. */ private String isReadable( String x, User u ) { return "( " + x + ".publicAccess is null" + " or substring(" + x + ".publicAccess, 0, 1) = 'r'" + " or " + x + ".user is not null and " + x + ".user.id = " + u.getId() + " or exists (select 'x' from UserGroupAccess a join a.userGroup.members u" + " where a in elements(" + x + ".userGroupAccesses) and u.id = " + u.getId() + ") )"; } }
@Override public int addUser( User user ) { this.users.add( user ); return user.getId(); }
@Override public void deleteUser( User user ) { jdbcTemplate.execute( "DELETE FROM userkeyjsonvalue WHERE userid = " + user.getId()); } }
@Override public int addUser( User user ) { AuditLogUtil.infoWrapper( log, currentUserService.getCurrentUsername(), user, AuditLogUtil.ACTION_CREATE ); userStore.save( user ); return user.getId(); }
@Override public List<UserMessage> getLastRecipients( User user, Integer first, Integer max ) { Assert.notNull( user, "User must be specified" ); String sql = " select distinct userinfoid, surname, firstname from userinfo uf " + "join usermessage um on (uf.userinfoid = um.userid) " + "join messageconversation_usermessages mu on (um.usermessageid = mu.usermessageid) " + "join messageconversation mc on (mu.messageconversationid = mc.messageconversationid) " + "where mc.lastsenderid = " + user.getId(); sql += " order by userinfoid desc"; if ( first != null && max != null ) { sql += " " + statementBuilder.limitRecord( first, max ); } return jdbcTemplate.query( sql, ( resultSet, count ) -> { UserMessage recipient = new UserMessage(); recipient.setId( resultSet.getInt( 1 ) ); recipient.setLastRecipientSurname( resultSet.getString( 2 ) ); recipient.setLastRecipientFirstname( resultSet.getString( 3 ) ); return recipient; } ); }
private String getCategoryOptionSharingForUser( User user ) { List<Integer> userGroupIds = getIdentifiers( user.getGroups() ); String sql = " left join ( "; sql += "select categoryoptioncomboid, count(categoryoptioncomboid) as option_size from categoryoptioncombos_categoryoptions group by categoryoptioncomboid) " + "as cocount on coc.categoryoptioncomboid = cocount.categoryoptioncomboid " + "left join (" + "select deco.categoryoptionid as deco_id, deco.uid as deco_uid, deco.publicaccess AS deco_publicaccess, " + "couga.usergroupaccessid as uga_id, coua.useraccessid as ua_id, uga.access as uga_access, uga.usergroupid AS usrgrp_id, " + "ua.access as ua_access, ua.userid as usr_id from dataelementcategoryoption deco " + "left join dataelementcategoryoptionusergroupaccesses couga on deco.categoryoptionid = couga.categoryoptionid " + "left join dataelementcategoryoptionuseraccesses coua on deco.categoryoptionid = coua.categoryoptionid " + "left join usergroupaccess uga on couga.usergroupaccessid = uga.usergroupaccessid " + "left join useraccess ua on coua.useraccessid = ua.useraccessid " + " where ua.userid=" + user.getId(); if ( userGroupIds != null && !userGroupIds.isEmpty() ) { sql += " or uga.usergroupid in (" + getCommaDelimitedString( userGroupIds ) + ") "; } sql += " ) as decoa on cocco.categoryoptionid = decoa.deco_id "; return sql; }
@Override public int deleteUserMessages( User user ) { Assert.notNull( user, "User must be specified" ); String sql = "delete from messageconversation_usermessages where usermessageid in (" + "select usermessageid from usermessage where userid = " + user.getId() + ")"; getSqlQuery( sql ).executeUpdate(); String hql = "delete UserMessage u where u.user = :user"; Query query = getQuery( hql ); query.setParameter( "user", user ); return query.executeUpdate(); }
@Override public int deleteMessages( User sender ) { Assert.notNull( sender, "User must be specified" ); String sql = "delete from messageconversation_messages where messageid in (" + "select messageid from message where userid = " + sender.getId() + ")"; getSqlQuery( sql ).executeUpdate(); String hql = "delete Message m where m.sender = :sender"; Query query = getQuery( hql ); query.setParameter( "sender", sender ); return query.executeUpdate(); }
private DataApprovalLevel getUserApprovalLevelWithCache( String orgUnitUid, DataApprovalWorkflow workflow ) { DataApprovalLevel userApprovalLevel = null; final String organisationUnitUid = orgUnitUid; final DataApprovalWorkflow dataApprovalWorkflow = workflow; userApprovalLevel = USER_APPROVAL_LEVEL_CACHE.get( user.getId() + "-" + organisationUnitUid, c -> dataApprovalLevelService.getUserApprovalLevel( user, organisationUnitService.getOrganisationUnit( organisationUnitUid ), dataApprovalWorkflow.getSortedLevels() ) ); return userApprovalLevel; }
protected void reloadUser( ImportOptions importOptions ) { if ( importOptions == null || importOptions.getUser() == null ) { return; } importOptions.setUser( userService.getUser( importOptions.getUser().getId() ) ); } }
@Override public UserInfo getCurrentUserInfo() { return new UserInfo( currentUser.getId(), currentUser.getUsername(), currentUser.getUserCredentials().getAllAuthorities() ); }
protected void reloadUser( ImportOptions importOptions ) { if ( importOptions == null || importOptions.getUser() == null ) { return; } importOptions.setUser( userService.getUser( importOptions.getUser().getId() ) ); }
@Override public Collection<org.hisp.dhis.api.mobile.model.User> findUser( String keyword ) throws NotAllowedException { Collection<User> users = new HashSet<>(); Collection<org.hisp.dhis.api.mobile.model.User> userList = new HashSet<>(); if ( keyword != null ) { int index = keyword.indexOf( ' ' ); if ( index != -1 && index == keyword.lastIndexOf( ' ' ) ) { String[] keys = keyword.split( " " ); keyword = keys[0] + " " + keys[1]; } } UserQueryParams params = new UserQueryParams(); params.setQuery( keyword ); users = userService.getUsers( params ); for ( User userCore : users ) { org.hisp.dhis.api.mobile.model.User user = new org.hisp.dhis.api.mobile.model.User(); user.setId( userCore.getId() ); user.setSurname( userCore.getSurname() ); user.setFirstName( userCore.getFirstName() ); userList.add( user ); } return userList; }
getSession().enableFilter( "userMessageUser" ).setParameter( "userid", user.getId() );
StringUtils.join( IdentifiableObjectUtils.getIdentifiers( attributeOptionCombos ), "," ) + ") " ) + ( isSuperUser ? "" : " and ( co.publicaccess is null or left(co.publicaccess, 1) = 'r' or co.userid is null or co.userid = " + user.getId() + " or exists ( " + "select 1 from dataelementcategoryoptionusergroupaccesses couga " + "left join usergroupaccess uga on uga.usergroupaccessid = couga.usergroupaccessid " + "left join usergroupmembers ugm on ugm.usergroupid = uga.usergroupid " + "where couga.categoryoptionid = cocco.categoryoptionid and ugm.userid = " + user.getId() + ") ) " ) + " and exists (select 1 from organisationunit od where od.path like o.path || '%' and od.organisationunitid in " + "(select distinct sourceid from datasetsource dss join dataset ds on ds.datasetid = dss.datasetid where ds.workflowid = " + workflow.getId() + "))";