Skip to content

Commit

Permalink
#1503 dupicates on upsync: assignment/unassignment of groups
Browse files Browse the repository at this point in the history
  • Loading branch information
desperateCoder committed Nov 22, 2024
1 parent 929da8b commit 6d97f09
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import it.niedermann.nextcloud.deck.model.ocs.projects.JoinCardWithProject;
import it.niedermann.nextcloud.deck.model.ocs.projects.OcsProject;
import it.niedermann.nextcloud.deck.model.ocs.projects.OcsProjectResource;
import it.niedermann.nextcloud.deck.model.ocs.user.UserForAssignment;
import it.niedermann.nextcloud.deck.model.relations.UserInBoard;
import it.niedermann.nextcloud.deck.model.relations.UserInGroup;
import it.niedermann.nextcloud.deck.model.widget.filter.EWidgetType;
Expand Down Expand Up @@ -422,6 +423,17 @@ public void updateUser(long accountId, User user, boolean setStatus) {
notifyFilterWidgetsAboutChangedEntity(FilterWidget.EChangedEntityType.USER, user.getLocalId());
}

@WorkerThread
public UserForAssignment getUserForAssignmentDirectly(long localUserId) {
SimpleSQLiteQuery query = new SimpleSQLiteQuery(
"SELECT case when uig.memberId is null then 0 else 1 end as type, u.uid as userId " +
"FROM User u " +
"left join UserInGroup uig on uig.groupId = u.localId " +
" WHERE u.localId = ? LIMIT 1",
new Object[]{localUserId});
return db.getUserInGroupDao().getUserForAssignment(query);
}

@UiThread
public LiveData<Label> getLabelByRemoteId(long accountId, long remoteId) {
return new ReactiveLiveData<>(db.getLabelDao().getLabelByRemoteId(accountId, remoteId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import androidx.room.Dao;
import androidx.room.Query;
import androidx.room.RawQuery;
import androidx.sqlite.db.SupportSQLiteQuery;

import it.niedermann.nextcloud.deck.model.ocs.user.UserForAssignment;
import it.niedermann.nextcloud.deck.model.relations.UserInGroup;

@Dao
public interface UserInGroupDao extends GenericDao<UserInGroup> {
@Query("DELETE FROM useringroup WHERE groupId = :localId")
void deleteByGroupId(long localId);

@RawQuery
UserForAssignment getUserForAssignment(SupportSQLiteQuery query);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package it.niedermann.nextcloud.deck.model.ocs.user;

public class UserForAssignment {
// 0 for user, 1 for group
private int type;
// UUID from user-Table
private String userId;

public UserForAssignment(int type, String userId) {
this.type = type;
this.userId = userId;
}

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import it.niedermann.nextcloud.deck.model.ocs.user.GroupMemberUIDs;
import it.niedermann.nextcloud.deck.model.ocs.user.OcsUser;
import it.niedermann.nextcloud.deck.model.ocs.user.OcsUserList;
import it.niedermann.nextcloud.deck.model.ocs.user.UserForAssignment;
import it.niedermann.nextcloud.deck.model.propagation.CardUpdate;
import it.niedermann.nextcloud.deck.model.propagation.Reorder;
import it.niedermann.nextcloud.deck.remote.api.ApiProvider;
Expand Down Expand Up @@ -197,12 +198,12 @@ public void updateCard(long boardId, long stackId, CardUpdate card, @NonNull Res
this.requestHelper.request(() -> provider.getDeckAPI().updateCard(boardId, stackId, card.getId(), card), responseCallback);
}

public void assignUserToCard(long boardId, long stackId, long cardId, String userUID, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().assignUserToCard(boardId, stackId, cardId, userUID), responseCallback);
public void assignUserToCard(long boardId, long stackId, long cardId, UserForAssignment userAssignment, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().assignUserToCard(boardId, stackId, cardId, userAssignment), responseCallback);
}

public void unassignUserFromCard(long boardId, long stackId, long cardId, String userUID, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().unassignUserFromCard(boardId, stackId, cardId, userUID), responseCallback);
public void unassignUserFromCard(long boardId, long stackId, long cardId, UserForAssignment userAssignment, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
this.requestHelper.request(() -> provider.getDeckAPI().unassignUserFromCard(boardId, stackId, cardId, userAssignment), responseCallback);
}

public void assignLabelToCard(long boardId, long stackId, long cardId, long labelId, @NonNull ResponseCallback<EmptyResponse> responseCallback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import it.niedermann.nextcloud.deck.model.full.FullBoard;
import it.niedermann.nextcloud.deck.model.full.FullCard;
import it.niedermann.nextcloud.deck.model.full.FullStack;
import it.niedermann.nextcloud.deck.model.ocs.user.UserForAssignment;
import it.niedermann.nextcloud.deck.model.propagation.CardUpdate;
import it.niedermann.nextcloud.deck.model.propagation.Reorder;
import okhttp3.MultipartBody;
Expand Down Expand Up @@ -105,11 +106,11 @@ public interface DeckAPI {

@FormUrlEncoded
@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/assignUser")
Call<EmptyResponse> assignUserToCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("userId") String userUID);
Call<EmptyResponse> assignUserToCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Body() UserForAssignment assignment);

@FormUrlEncoded
@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/unassignUser")
Call<EmptyResponse> unassignUserFromCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Field("userId") String userUID);
Call<EmptyResponse> unassignUserFromCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Body() UserForAssignment assignment);

@PUT("v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/reorder")
Call<List<FullCard>> moveCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Body Reorder reorder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import it.niedermann.nextcloud.deck.model.enums.DBStatus;
import it.niedermann.nextcloud.deck.model.full.FullCard;
import it.niedermann.nextcloud.deck.model.full.FullStack;
import it.niedermann.nextcloud.deck.model.ocs.user.UserForAssignment;
import it.niedermann.nextcloud.deck.model.propagation.CardUpdate;
import it.niedermann.nextcloud.deck.remote.adapters.ServerAdapter;
import it.niedermann.nextcloud.deck.remote.api.IResponseCallback;
Expand Down Expand Up @@ -339,7 +340,9 @@ public void onError(Throwable throwable) {
}
User user = dataBaseAdapter.getUserByLocalIdDirectly(changedUser.getUserId());
if (changedUser.getStatusEnum() == DBStatus.LOCAL_DELETED) {
serverAdapter.unassignUserFromCard(board.getId(), stack.getId(), changedUser.getCardId(), user.getUid(), new ResponseCallback<>(account) {
UserForAssignment userForAssignment = dataBaseAdapter.getUserForAssignmentDirectly(changedUser.getUserId());

serverAdapter.unassignUserFromCard(board.getId(), stack.getId(), changedUser.getCardId(), userForAssignment, new ResponseCallback<>(account) {
@Override
public void onResponse(EmptyResponse response, Headers headers) {
dataBaseAdapter.deleteJoinedUserForCardPhysicallyByRemoteIDs(account.getId(), changedUser.getCardId(), user.getUid());
Expand All @@ -348,7 +351,9 @@ public void onResponse(EmptyResponse response, Headers headers) {
} else if (changedUser.getStatusEnum() == DBStatus.LOCAL_EDITED) {
if (!USER_JOINS_IN_SYNC.contains(changedUser)) {
USER_JOINS_IN_SYNC.add(changedUser);
serverAdapter.assignUserToCard(board.getId(), stack.getId(), changedUser.getCardId(), user.getUid(), new ResponseCallback<>(account) {
UserForAssignment userForAssignment = dataBaseAdapter.getUserForAssignmentDirectly(changedUser.getUserId());

serverAdapter.assignUserToCard(board.getId(), stack.getId(), changedUser.getCardId(), userForAssignment, new ResponseCallback<>(account) {
@Override
public void onResponse(EmptyResponse response, Headers headers) {
dataBaseAdapter.setStatusForJoinCardWithUser(card.getLocalId(), user.getLocalId(), DBStatus.UP_TO_DATE.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment;
import it.niedermann.nextcloud.deck.model.ocs.comment.OcsComment;
import it.niedermann.nextcloud.deck.model.ocs.user.OcsUserList;
import it.niedermann.nextcloud.deck.model.ocs.user.UserForAssignment;
import it.niedermann.nextcloud.deck.remote.adapters.ServerAdapter;
import it.niedermann.nextcloud.deck.remote.api.GsonConfig;
import it.niedermann.nextcloud.deck.remote.api.IResponseCallback;
Expand Down Expand Up @@ -1240,7 +1241,9 @@ public void assignUserToCard(@NonNull User user, @NonNull Card card) {
Board board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getBoardId());
Account account = dataBaseAdapter.getAccountByIdDirectly(card.getAccountId());
if (connectivityUtil.hasInternetConnection()) {
serverAdapter.assignUserToCard(board.getId(), stack.getId(), card.getId(), user.getUid(), new ResponseCallback<>(account) {
UserForAssignment userForAssignment = dataBaseAdapter.getUserForAssignmentDirectly(user.getLocalId());

serverAdapter.assignUserToCard(board.getId(), stack.getId(), card.getId(), userForAssignment, new ResponseCallback<>(account) {

@Override
public void onResponse(EmptyResponse response, Headers headers) {
Expand Down Expand Up @@ -1306,7 +1309,9 @@ public void unassignUserFromCard(@NonNull User user, @NonNull Card card) {
Stack stack = dataBaseAdapter.getStackByLocalIdDirectly(card.getStackId());
Board board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getBoardId());
Account account = dataBaseAdapter.getAccountByIdDirectly(card.getAccountId());
serverAdapter.unassignUserFromCard(board.getId(), stack.getId(), card.getId(), user.getUid(), new ResponseCallback<>(account) {
UserForAssignment userForAssignment = dataBaseAdapter.getUserForAssignmentDirectly(user.getLocalId());

serverAdapter.assignUserToCard(board.getId(), stack.getId(), card.getId(), userForAssignment, new ResponseCallback<>(account) {
@Override
public void onResponse(EmptyResponse response, Headers headers) {
dataBaseAdapter.deleteJoinedUserForCardPhysically(card.getLocalId(), user.getLocalId());
Expand Down

0 comments on commit 6d97f09

Please sign in to comment.