diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-08-02 18:20:52 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-08-09 17:34:18 +0300 |
commit | e99ac780be5b328bd7ff232b4c4a9abd263394f7 (patch) | |
tree | f21ec08997a669216760da4e200ea09f836d7933 | |
parent | 635d58dddbfaefad150be529a39fdcb79717d38c (diff) |
#492 #631 new table for group-user-relation
3 files changed, 91 insertions, 3 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInGroup.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInGroup.java new file mode 100644 index 000000000..48e16cce5 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInGroup.java @@ -0,0 +1,70 @@ +package it.niedermann.nextcloud.deck.model.relations; + +import androidx.annotation.NonNull; +import androidx.room.Entity; +import androidx.room.ForeignKey; +import androidx.room.Index; + +import it.niedermann.nextcloud.deck.model.User; + +@Entity( + primaryKeys = {"groupId", "memberId"}, + indices = {@Index("groupId"), @Index("memberId"), @Index(name = "unique_idx_group_member", value = {"groupId","memberId"}, unique = true)}, + foreignKeys = { + @ForeignKey(entity = User.class, + parentColumns = "localId", + childColumns = "groupId", onDelete = ForeignKey.CASCADE), + @ForeignKey(entity = User.class, + parentColumns = "localId", + childColumns = "memberId", onDelete = ForeignKey.CASCADE) + }) +public class UserInGroup { + @NonNull + private Long groupId; + @NonNull + private Long memberId; + + @NonNull + public Long getGroupId() { + return groupId; + } + + public void setGroupId(@NonNull Long groupId) { + this.groupId = groupId; + } + + @NonNull + public Long getMemberId() { + return memberId; + } + + public void setMemberId(@NonNull Long memberId) { + this.memberId = memberId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + UserInGroup that = (UserInGroup) o; + + if (!groupId.equals(that.groupId)) return false; + return memberId.equals(that.memberId); + } + + @Override + public int hashCode() { + int result = groupId.hashCode(); + result = 31 * result + memberId.hashCode(); + return result; + } + + @Override + public String toString() { + return "UserInGroup{" + + "groupId=" + groupId + + ", memberId=" + memberId + + '}'; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java index df2d9a604..2ce983fe4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java @@ -36,6 +36,7 @@ import it.niedermann.nextcloud.deck.model.ocs.comment.Mention; 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.relations.UserInGroup; import it.niedermann.nextcloud.deck.model.widget.singlecard.SingleCardWidgetModel; import it.niedermann.nextcloud.deck.persistence.sync.SyncWorker; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.AccessControlDao; @@ -85,9 +86,10 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.Sta OcsProject.class, OcsProjectResource.class, JoinCardWithProject.class, + UserInGroup.class, }, exportSchema = false, - version = 19 + version = 20 ) @TypeConverters({DateTypeConverter.class}) public abstract class DeckDatabase extends RoomDatabase { @@ -236,6 +238,20 @@ public abstract class DeckDatabase extends RoomDatabase { database.execSQL("CREATE UNIQUE INDEX `index_OcsProjectResource_accountId_id` ON `OcsProjectResource` (`accountId`, `id`, `idString`, `projectId`)"); } }; + private static final Migration MIGRATION_19_20 = new Migration(19, 20) { + @Override + public void migrate(SupportSQLiteDatabase database) { + // https://github.com/stefan-niedermann/nextcloud-deck/issues/492 + // https://github.com/stefan-niedermann/nextcloud-deck/issues/631 + database.execSQL("CREATE TABLE `UserInGroup` (`groupId` INTEGER NOT NULL, `memberId` INTEGER NOT NULL, " + + "primary KEY(`groupId`, `memberId`), " + + "FOREIGN KEY(`groupId`) REFERENCES `User`(`localId`) ON UPDATE NO ACTION ON DELETE CASCADE, " + + "FOREIGN KEY(`memberId`) REFERENCES `User`(`localId`) ON UPDATE NO ACTION ON DELETE CASCADE)"); + database.execSQL("CREATE UNIQUE INDEX `unique_idx_group_member` ON `UserInGroup` (`groupId`, `memberId`)"); + database.execSQL("CREATE INDEX `index_UserInGroup_groupId` ON `UserInGroup` (`groupId`)"); + database.execSQL("CREATE INDEX `index_UserInGroup_memberId` ON `UserInGroup` (`memberId`)"); + } + }; public static final RoomDatabase.Callback ON_CREATE_CALLBACK = new RoomDatabase.Callback() { @Override @@ -281,6 +297,7 @@ public abstract class DeckDatabase extends RoomDatabase { .addMigrations(MIGRATION_16_17) .addMigrations(MIGRATION_17_18) .addMigrations(MIGRATION_18_19) + .addMigrations(MIGRATION_19_20) .fallbackToDestructiveMigration() .addCallback(ON_CREATE_CALLBACK) .build(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AccessControlDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AccessControlDataProvider.java index a5ca723f2..de859d281 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AccessControlDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AccessControlDataProvider.java @@ -54,7 +54,7 @@ public class AccessControlDataProvider extends AbstractSyncDataProvider<AccessCo try { latch.await(); } catch (InterruptedException e) { - e.printStackTrace(); + DeckLog.logError(e); } responder.onResponse(acl); } @@ -88,7 +88,7 @@ public class AccessControlDataProvider extends AbstractSyncDataProvider<AccessCo try { memberLatch.await(); } catch (InterruptedException e) { - e.printStackTrace(); + DeckLog.logError(e); } } @@ -149,6 +149,7 @@ public class AccessControlDataProvider extends AbstractSyncDataProvider<AccessCo @Override public void deletePhysicallyInDB(DataBaseAdapter dataBaseAdapter, long accountId, AccessControl accessControl) { + //TODO delete members from relation table dataBaseAdapter.deleteAccessControl(accessControl, false); } |