public UserAuthorityGroupCanIssueFilter( User user, boolean canGrantOwnUserAuthorityGroups ) { if ( user != null && user.getUserCredentials() != null ) { this.userCredentials = user.getUserCredentials(); this.canGrantOwnUserAuthorityGroups = canGrantOwnUserAuthorityGroups; } }
@Override public UserInfo getCurrentUserInfo() { return new UserInfo( currentUser.getId(), currentUser.getUsername(), currentUser.getUserCredentials().getAllAuthorities() ); }
@Override public Set<OrganisationUnit> getCurrentUserOrganisationUnits() { return currentUser != null ? currentUser.getOrganisationUnits() : new HashSet<>(); }
/** * Returns the first of the data view organisation units associated with the * user. If none, returns the first of the data capture organisation units. * If none, return nulls. */ public OrganisationUnit getDataViewOrganisationUnitWithFallback() { return hasDataViewOrganisationUnit() ? getDataViewOrganisationUnit() : getOrganisationUnit(); }
/** * Returns the first of the tei search organisation units associated with the * user. If none, returns the first of the data capture organisation units. * If none, return nulls. */ public OrganisationUnit getTeiSearchOrganisationUnitWithFallback() { return hasTeiSearchOrganisationUnit() ? getTeiSearchOrganisationUnit() : getOrganisationUnit(); }
@Override public UserCredentials getUserCredentialsByUsername( String username ) { for ( User user : users ) { if ( user.getUsername().equals( username ) ) { return user.getUserCredentials(); } } return null; }
@Override public String toString() { return "{" + "\"user\":\"" + user.getUsername() + "\", " + "\"name:\":\"" + name + "\", " + "\"value\":\"" + value + "\" " + "}"; }
String storedBy = getValidUsername( event.getStoredBy(), null, importOptions.getUser() != null ? importOptions.getUser().getUsername() : "[Unknown]" ); programStageInstance.setStoredBy( storedBy ); String completedBy = getValidUsername( event.getCompletedBy(), null, importOptions.getUser() != null ? importOptions.getUser().getUsername() : "[Unknown]" ); UserCredentials userCredentials = importOptions.getUser().getUserCredentials(); if ( importOptions.getUser() == null || !importOptions.getUser().isAuthorized( Authorities.F_EDIT_EXPIRED.getAuthority() ) )
@Override public boolean setAsFavorite( User user ) { if ( this.favorites == null ) { this.favorites = new HashSet<>(); } return this.favorites.add( user.getUid() ); }
@Override public void decideAccessEventQuery( EventQueryParams params ) { User user = currentUserService.getCurrentUser(); decideAccess( params ); boolean notAuthorized = user != null && !user.isAuthorized( AUTH_VIEW_EVENT_ANALYTICS ); throwExWhenTrue( notAuthorized, String.format( "User: %s is not allowed to view event analytics", user.getUsername() ) ); }
@Override public void preCreate( IdentifiableObject object, ObjectBundle bundle ) { if ( !User.class.isInstance( object ) || ((User) object).getUserCredentials() == null ) return; User user = (User) object; bundle.putExtras( user, "uc", user.getUserCredentials() ); user.setUserCredentials( null ); }
public static Map<String, Set<OrganisationUnit>> getOrganisationUnitsByPhoneNumber( String sender, Collection<User> users ) { Map<String, Set<OrganisationUnit>> userOrgUnitMap = new HashMap<>(); for ( User u : users ) { if ( u.getOrganisationUnits() != null ) { userOrgUnitMap.put( u.getUid(), u.getOrganisationUnits() ); } } return userOrgUnitMap; }
/** * 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() + ") )"; } }
private boolean haveOverrideAuthority( User user ) { return user == null || user.isSuper(); }
public boolean remove( User user ) { Iterator<UserMessage> iterator = userMessages.iterator(); while ( iterator.hasNext() ) { UserMessage userMessage = iterator.next(); if ( userMessage.getUser() != null && userMessage.getUser().equals( user ) ) { iterator.remove(); return true; } } return false; }
/** * Builds a HTML table representing the ReportTable input * * @param reportTable reportTable to generate HTML for * @param user user to generate reportTable data for * @return a HTML representation of the reportTable * @throws Exception */ private String generateReportTableHtml( ReportTable reportTable, User user ) { StringWriter stringWriter = new StringWriter(); GridUtils.toHtmlInlineCss( reportTableService .getReportTableGridByUser( reportTable.getUid(), new Date(), user.getOrganisationUnit().getUid(), user ), stringWriter ); return stringWriter.toString().replaceAll( "\\R", "" ); }
private boolean doValidationOfMandatoryAttributes( User user ) { return user == null || !user.isAuthorized( Authorities.F_IGNORE_TRACKER_REQUIRED_VALUE_VALIDATION.getAuthority() ); }
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; }
public void markReplied( User sender, Message message ) { for ( UserMessage userMessage : userMessages ) { User user = userMessage.getUser(); if ( user != null && !user.equals( sender ) && (!message.isInternal() || (message.isInternal() && (user.isAuthorized( "F_MANAGE_TICKETS" ) || user.isAuthorized( "ALL" )))) ) { userMessage.setRead( false ); } } addMessage( message ); this.lastSender = sender; this.setLastMessage( new Date() ); }
if ( user != null && user.hasOrganisationUnit() ) OrganisationUnit organisationUnit = user.getOrganisationUnit();