src/org/ohmage/service/UserImageServices.java
public void verifyUserCanReadImage(final String requesterUsername, 
			final UUID imageId) throws ServiceException {
		
		try {
			// If it is their own image, they can read it.
			if(requesterUsername.equals(userImageQueries.getImageOwner(imageId))) {
				return;
			}
			
			// Retrieve all of the campaigns associated with an image.
			List<String> campaignIds = campaignImageQueries.getCampaignIdsForImageId(imageId);
			
			// For each of the campaigns, see if the requesting user has 
			// sufficient permissions.
			for(String campaignId : campaignIds) {
				List<Campaign.Role> roles = userCampaignQueries.getUserCampaignRoles(requesterUsername, campaignId);

				// If they are a supervisor.
				if(roles.contains(Campaign.Role.SUPERVISOR)) {
					return;
				}
				
				// Retrieves the privacy state of the image in this campaign. 
				// If null is returned, something has changed since the list of
				// campaign IDs was retrieved, so we need to just error out.
				SurveyResponse.PrivacyState imagePrivacyState = campaignImageQueries.getImagePrivacyStateInCampaign(campaignId, imageId);
				
				// They are an author and the image is shared
				if(roles.contains(Campaign.Role.AUTHOR) && 
						SurveyResponse.PrivacyState.SHARED.equals(imagePrivacyState)) {
					return;
				}
				
				// Retrieve the campaign's privacy state.
				Campaign.PrivacyState campaignPrivacyState = campaignQueries.getCampaignPrivacyState(campaignId);
				
				// They are an analyst, the image is shared, and the campaign is shared.
				if(roles.contains(Campaign.Role.ANALYST) && 
						SurveyResponse.PrivacyState.SHARED.equals(imagePrivacyState) &&
						Campaign.PrivacyState.SHARED.equals(campaignPrivacyState)) {
					return;
				}
			}
			
			// If we made it to this point, the requesting user doesn't have
			// sufficient permissions to read the image.
			throw new ServiceException(
					ErrorCode.IMAGE_INSUFFICIENT_PERMISSIONS, 
					"The user doesn't have sufficient permissions to read the image.");
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
	}
/**
	 * Verifies that an user has sufficient permissions to read an image.
	 * 
	 * @param requesterUsername The username of the user making this request.
	 * 
	 * @param imageId The unique identifier for the image.
	 * 
	 * @throws ServiceException Thrown if the user doesn't have sufficient
	 * 							permissions to read the image.
	 */
Verifies that an user has sufficient permissions to read an image.

@param requesterUsername The username of the user making this request.

@param imageId The unique identifier for the image.

@throws ServiceException Thrown if the user doesn't have sufficient
permissions to read the image.
Verifies that an user has sufficient permissions to read an image . @param requesterUsername The username of the user making this request . @param imageId The unique identifier for the image . @throws ServiceException Thrown if the user doesn ' t have sufficient permissions to read the image .
public void verifyUserCanReadImage(final String requesterUsername, 
			final UUID imageId) throws ServiceException {
		try {
			if(requesterUsername.equals(userImageQueries.getImageOwner(imageId))) {
				return;
			}
			List<String> campaignIds = campaignImageQueries.getCampaignIdsForImageId(imageId);
			for(String campaignId : campaignIds) {
				List<Campaign.Role> roles = userCampaignQueries.getUserCampaignRoles(requesterUsername, campaignId);
				if(roles.contains(Campaign.Role.SUPERVISOR)) {
					return;
				}
				SurveyResponse.PrivacyState imagePrivacyState = campaignImageQueries.getImagePrivacyStateInCampaign(campaignId, imageId);
				if(roles.contains(Campaign.Role.AUTHOR) && 
						SurveyResponse.PrivacyState.SHARED.equals(imagePrivacyState)) {
					return;
				}
				Campaign.PrivacyState campaignPrivacyState = campaignQueries.getCampaignPrivacyState(campaignId);
				if(roles.contains(Campaign.Role.ANALYST) && 
						SurveyResponse.PrivacyState.SHARED.equals(imagePrivacyState) &&
						Campaign.PrivacyState.SHARED.equals(campaignPrivacyState)) {
					return;
				}
			}
			throw new ServiceException(
					ErrorCode.IMAGE_INSUFFICIENT_PERMISSIONS, 
					"The user doesn't have sufficient permissions to read the image.");
		}
		catch(DataAccessException e) {
			throw new ServiceException(e);
		}
	}
public void verifyUserCanReadImage ( final String requesterUsername , final UUID imageId ) throws ServiceException { try { if ( requesterUsername . equals ( userImageQueries . getImageOwner ( imageId ) ) ) { return ; } List < String > campaignIds = campaignImageQueries . getCampaignIdsForImageId ( imageId ) ; for ( String campaignId : campaignIds ) { List < Campaign . Role > roles = userCampaignQueries . getUserCampaignRoles ( requesterUsername , campaignId ) ; if ( roles . contains ( Campaign . Role . SUPERVISOR ) ) { return ; } SurveyResponse . PrivacyState imagePrivacyState = campaignImageQueries . getImagePrivacyStateInCampaign ( campaignId , imageId ) ; if ( roles . contains ( Campaign . Role . AUTHOR ) && SurveyResponse . PrivacyState . SHARED . equals ( imagePrivacyState ) ) { return ; } Campaign . PrivacyState campaignPrivacyState = campaignQueries . getCampaignPrivacyState ( campaignId ) ; if ( roles . contains ( Campaign . Role . ANALYST ) && SurveyResponse . PrivacyState . SHARED . equals ( imagePrivacyState ) && Campaign . PrivacyState . SHARED . equals ( campaignPrivacyState ) ) { return ; } } throw new ServiceException ( ErrorCode . IMAGE_INSUFFICIENT_PERMISSIONS , "The user doesn't have sufficient permissions to read the image." ) ; } catch ( DataAccessException e ) { throw new ServiceException ( e ) ; } }
Verifies that an user has sufficient permissions to read an image.
Verifies that an user has sufficient permissions to read an image .
// If it is their own image, they can read it. // Retrieve all of the campaigns associated with an image. // For each of the campaigns, see if the requesting user has  // sufficient permissions. // If they are a supervisor. // Retrieves the privacy state of the image in this campaign.  // If null is returned, something has changed since the list of // campaign IDs was retrieved, so we need to just error out. // They are an author and the image is shared // Retrieve the campaign's privacy state. // They are an analyst, the image is shared, and the campaign is shared. // If we made it to this point, the requesting user doesn't have // sufficient permissions to read the image.