Search in sources :

Example 1 with AccessToken

use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.

the class DataAccessorGaeImpl method getFcmTokenList.

@Override
public List<String> getFcmTokenList(Long userId) {
    if (userId == null || userId == 0L)
        return null;
    List<AccessTokenEntity> accessTokenList = ObjectifyService.ofy().load().type(AccessTokenEntity.class).filter("USER_ID", userId).filter("EXPIRY >", new Date()).list();
    List<String> fcmTokenList = new ArrayList<>(accessTokenList.size());
    for (AccessToken accessToken : accessTokenList) if (accessToken.getFcmToken() != null && !fcmTokenList.contains(accessToken.getFcmToken()))
        fcmTokenList.add(accessToken.getFcmToken());
    return fcmTokenList;
}
Also used : AccessToken(com.pratilipi.data.type.AccessToken) ArrayList(java.util.ArrayList) AccessTokenEntity(com.pratilipi.data.type.gae.AccessTokenEntity) Date(java.util.Date)

Example 2 with AccessToken

use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.

the class PratilipiDataUtil method hasAccessToListPratilipiData.

public static boolean hasAccessToListPratilipiData(PratilipiFilter pratilipiFilter) {
    if (pratilipiFilter.getState() == PratilipiState.PUBLISHED)
        return true;
    // Case 2: User with PRATILIPI_LIST access can list Pratilipis in any State.
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    if (UserAccessUtil.hasUserAccess(accessToken.getUserId(), pratilipiFilter.getLanguage(), AccessType.PRATILIPI_LIST))
        return true;
    if (pratilipiFilter.getState() == PratilipiState.DELETED)
        return false;
    if (pratilipiFilter.getAuthorId() == null)
        return false;
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Author author = dataAccessor.getAuthor(pratilipiFilter.getAuthorId());
    if (author == null)
        return false;
    return accessToken.getUserId().equals(author.getUserId());
}
Also used : AccessToken(com.pratilipi.data.type.AccessToken) DataAccessor(com.pratilipi.data.DataAccessor) Author(com.pratilipi.data.type.Author)

Example 3 with AccessToken

use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.

the class AccessTokenDataUtil method setOrUpdateFcmToken.

public static void setOrUpdateFcmToken(String fcmToken) {
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    if (fcmToken.equals(accessToken.getFcmToken()))
        return;
    accessToken.setFcmToken(fcmToken);
    accessToken = DataAccessorFactory.getDataAccessor().createOrUpdateAccessToken(accessToken);
}
Also used : AccessToken(com.pratilipi.data.type.AccessToken)

Example 4 with AccessToken

use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.

the class PratilipiDataUtil method hasAccessToUpdatePratilipiData.

public static boolean hasAccessToUpdatePratilipiData(Pratilipi pratilipi, PratilipiData pratilipiData) {
    // Case 1: Only DRAFTED/SUBMITTED/PUBLISHED content pieces can be updated.
    if (pratilipi.getState() != PratilipiState.DRAFTED && pratilipi.getState() != PratilipiState.SUBMITTED && pratilipi.getState() != PratilipiState.PUBLISHED)
        return false;
    Author author = pratilipi.getAuthorId() == null ? null : DataAccessorFactory.getDataAccessor().getAuthor(pratilipi.getAuthorId());
    // Case 2: Content pieces can be updated only if Author profile is ACTIVE.
    if (author != null && author.getState() != AuthorState.ACTIVE)
        return false;
    // Case 3: User with PRATILIPI_UPDATE access can update any content piece.
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    if (UserAccessUtil.hasUserAccess(accessToken.getUserId(), pratilipi.getLanguage(), AccessType.PRATILIPI_UPDATE)) {
        if (pratilipiData == null || !pratilipiData.hasLanguage() || pratilipiData.getLanguage() == pratilipi.getLanguage())
            return true;
        else if (UserAccessUtil.hasUserAccess(accessToken.getUserId(), pratilipiData.getLanguage(), AccessType.PRATILIPI_UPDATE))
            return true;
    }
    // Case 4: User can update content piece linked with his/her own Author profile.
    if (author != null && accessToken.getUserId().equals(author.getUserId()))
        return true;
    return false;
}
Also used : AccessToken(com.pratilipi.data.type.AccessToken) Author(com.pratilipi.data.type.Author)

Example 5 with AccessToken

use of com.pratilipi.data.type.AccessToken in project pratilipi by Pratilipi.

the class UserAuthorDataUtil method hasAccessToUpdateUserAuthorData.

public static boolean hasAccessToUpdateUserAuthorData(UserAuthor userAuthor, AccessType accessType) {
    AccessToken accessToken = AccessTokenFilter.getAccessToken();
    if (!userAuthor.getUserId().equals(accessToken.getUserId()))
        return false;
    if (!UserAccessUtil.hasUserAccess(accessToken.getUserId(), null, accessType))
        return false;
    // User can not follow his/her own Author profile.
    if (accessType == AccessType.USER_AUTHOR_FOLLOWING) {
        DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
        Author author = dataAccessor.getAuthor(userAuthor.getAuthorId());
        if (userAuthor.getUserId().equals(author.getUserId()))
            return false;
    }
    return true;
}
Also used : AccessToken(com.pratilipi.data.type.AccessToken) DataAccessor(com.pratilipi.data.DataAccessor) UserAuthor(com.pratilipi.data.type.UserAuthor) Author(com.pratilipi.data.type.Author)

Aggregations

AccessToken (com.pratilipi.data.type.AccessToken)17 DataAccessor (com.pratilipi.data.DataAccessor)8 Author (com.pratilipi.data.type.Author)8 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)5 Date (java.util.Date)5 UserAuthor (com.pratilipi.data.type.UserAuthor)3 UserPratilipi (com.pratilipi.data.type.UserPratilipi)3 Post (com.pratilipi.api.annotation.Post)2 GenericResponse (com.pratilipi.api.shared.GenericResponse)2 AuditLog (com.pratilipi.data.type.AuditLog)2 Pratilipi (com.pratilipi.data.type.Pratilipi)2 AccessTokenEntity (com.pratilipi.data.type.gae.AccessTokenEntity)2 Gson (com.google.gson.Gson)1 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)1 AuthorData (com.pratilipi.data.client.AuthorData)1 PratilipiData (com.pratilipi.data.client.PratilipiData)1 TagData (com.pratilipi.data.client.TagData)1 UserData (com.pratilipi.data.client.UserData)1 Comment (com.pratilipi.data.type.Comment)1 Vote (com.pratilipi.data.type.Vote)1