Skip to content

Commit 20bf591

Browse files
committed
remove unexisting permissions
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 7240b2f commit 20bf591

17 files changed

+89
-229
lines changed

app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@
5050
import it.niedermann.owncloud.notes.shared.model.Capabilities;
5151

5252
@Database(
53-
entities = {
54-
Account.class,
55-
Note.class,
56-
CategoryOptions.class,
57-
SingleNoteWidgetData.class,
58-
NotesListWidgetData.class,
59-
ShareEntity.class,
60-
Capabilities.class
61-
}, version = 28,
62-
autoMigrations = {
63-
@AutoMigration(from = 25, to = 26),
64-
@AutoMigration(from = 26, to = 27),
65-
@AutoMigration(from = 27, to = 28),
66-
}
53+
entities = {
54+
Account.class,
55+
Note.class,
56+
CategoryOptions.class,
57+
SingleNoteWidgetData.class,
58+
NotesListWidgetData.class,
59+
ShareEntity.class,
60+
Capabilities.class
61+
}, version = 29,
62+
autoMigrations = {
63+
@AutoMigration(from = 25, to = 26),
64+
@AutoMigration(from = 26, to = 27),
65+
@AutoMigration(from = 27, to = 28),
66+
@AutoMigration(from = 28, to = 29),
67+
}
6768
)
6869
@TypeConverters({Converters.class})
6970
public abstract class NotesDatabase extends RoomDatabase {

app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,10 @@ public List<ShareEntity> getShareEntities(String path) {
10101010
return db.getShareDao().getShareEntities(path);
10111011
}
10121012

1013+
public void deleteShareById(int id) {
1014+
db.getShareDao().deleteById(id);
1015+
}
1016+
10131017
public void updateNote(Note note) {
10141018
db.getNoteDao().updateNote(note);
10151019
}

app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/ShareDao.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package it.niedermann.owncloud.notes.persistence.dao
88

99
import androidx.room.Dao
10+
import androidx.room.Delete
1011
import androidx.room.Insert
1112
import androidx.room.OnConflictStrategy
1213
import androidx.room.Query
@@ -19,4 +20,7 @@ interface ShareDao {
1920

2021
@Query("SELECT * FROM share_table WHERE path = :path")
2122
fun getShareEntities(path: String): List<ShareEntity>
23+
24+
@Query("DELETE FROM share_table WHERE id = :id")
25+
fun deleteById(id: Int)
2226
}

app/src/main/java/it/niedermann/owncloud/notes/persistence/entity/ShareEntity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ data class ShareEntity(
2525
val uid_owner: String? = null,
2626
val displayname_owner: String? = null,
2727
val url: String? = null,
28-
val expiration_date: Long? = null
28+
val expiration_date: Long? = null,
29+
val permissions: Double? = null
2930
)

app/src/main/java/it/niedermann/owncloud/notes/persistence/sync/ShareAPI.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import retrofit2.http.Query
2424

2525
interface ShareAPI {
2626
@GET("sharees")
27-
fun getSharees(
27+
fun fetchSharees(
2828
@Query("format") format: String = "json",
2929
@Query("itemType") itemType: String = "file",
3030
@Query("search") search: String,
@@ -33,14 +33,8 @@ interface ShareAPI {
3333
@Query("lookup") lookup: String = "false",
3434
): LinkedTreeMap<String, Any?>?
3535

36-
@GET("shares/{remoteId}?format=json")
37-
fun getShares(
38-
@Path("remoteId") remoteId: Long,
39-
@Query("include_tags") includeTags: Boolean = true,
40-
): Call<OcsResponse<List<CreateShareResponse>>>
41-
4236
@GET("shares/?format=json")
43-
fun getSharesForSpecificNote(
37+
fun fetchSharesForSpecificNote(
4438
@Query("path") path: String,
4539
@Query("reshares") reshares: Boolean = true,
4640
@Query("subfiles") subfiles: Boolean = true
@@ -65,8 +59,8 @@ interface ShareAPI {
6559
): Call<OcsResponse<CreateShareResponse>>
6660

6761
@GET("shares/?format=json")
68-
fun getShareFromNote(
62+
fun fetchSharesFromNote(
6963
@Query("path") path: String,
70-
@Query("shared_with_me") sharedWithMe: Boolean = true
64+
@Query("shared_with_me") sharedWithMe: Boolean = false
7165
): Call<OcsResponse<List<CreateShareResponse>>>
7266
}

app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareActivity.java

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private void initializeArguments() {
161161
final var ssoAcc = SingleAccountHelper.getCurrentSingleSignOnAccount(NoteShareActivity.this);
162162
repository = new ShareRepository(NoteShareActivity.this, ssoAcc);
163163
capabilities = repository.getCapabilities();
164-
repository.getSharesForNotesAndSaveShareEntities();
164+
repository.fetchSharesForNotesAndSaveShareEntities();
165165

166166
runOnUiThread(() -> {
167167
binding.fileName.setText(note.getTitle());
@@ -519,17 +519,16 @@ public void updateShareeListAdapter() {
519519
return;
520520
}
521521

522-
List<OCShare> tempShares = new ArrayList<>();
523-
524-
// to show share with users/groups info
522+
List<OCShare> remoteNotes;
525523
if (note != null) {
526-
// get shares from local DB
527-
populateSharesList(tempShares);
524+
remoteNotes = repository.fetchSharesFromNote(note);
525+
} else {
526+
remoteNotes = new ArrayList<>();
528527
}
529528

530529
runOnUiThread(() -> {
531530
shares.clear();
532-
shares.addAll(tempShares);
531+
shares.addAll(remoteNotes);
533532

534533
adapter.removeAll();
535534
adapter.addShares(shares);
@@ -544,35 +543,6 @@ public void updateShareeListAdapter() {
544543
});
545544
}
546545

547-
private void populateSharesList(List<OCShare> targetList) {
548-
// Get shares from local DB
549-
final var shareEntities = repository.getShareEntitiesForSpecificNote(note);
550-
for (var entity : shareEntities) {
551-
if (entity.getId() != null) {
552-
addSharesToList(entity.getId(), targetList);
553-
}
554-
}
555-
556-
// Get shares from remote
557-
final var remoteShares = repository.getShareFromNote(note);
558-
if (remoteShares != null) {
559-
for (var entity : remoteShares) {
560-
addSharesToList(entity.getId(), targetList);
561-
}
562-
}
563-
}
564-
565-
private void addSharesToList(long id, List<OCShare> targetList) {
566-
final var result = repository.getShares(id);
567-
if (result != null) {
568-
for (OCShare ocShare : result) {
569-
if (!targetList.contains(ocShare)) {
570-
targetList.add(ocShare);
571-
}
572-
}
573-
}
574-
}
575-
576546
private void addPublicShares(ShareeListAdapter adapter) {
577547
List<OCShare> publicShares = new ArrayList<>();
578548

@@ -759,12 +729,17 @@ public void onQuickPermissionChanged(OCShare share, int permission) {
759729
}
760730

761731
private void updateShare(OCShare share) {
732+
if (note == null) {
733+
Log_OC.e(TAG, "note is null, cannot update share");
734+
return;
735+
}
736+
762737
executorService.submit(() -> {
763738
try {
764-
final var updatedShares = repository.getShares(share.getId());
739+
final var updatedShares = repository.fetchSharesFromNote(note);
765740

766741
runOnUiThread(() -> {
767-
if (updatedShares != null && binding.sharesList.getAdapter() instanceof ShareeListAdapter adapter) {
742+
if (binding.sharesList.getAdapter() instanceof ShareeListAdapter adapter) {
768743
OCShare updatedShare = null;
769744
for (int i=0;i<updatedShares.size();i++) {
770745
if (updatedShares.get(i).getId() == share.getId()) {

app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareDetailActivity.kt

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class NoteShareDetailActivity :
124124
updateViewForNoteScreenType()
125125
}
126126
implementClickEvents()
127-
setVisibilitiesOfShareOption()
128127
}
129128
}
130129
}
@@ -133,24 +132,13 @@ class NoteShareDetailActivity :
133132
finish()
134133
}
135134

136-
private fun setVisibilitiesOfShareOption() {
137-
binding.run {
138-
if (canSetFileRequest()) {
139-
shareProcessPermissionFileDrop.visibility = View.VISIBLE
140-
} else {
141-
shareProcessPermissionFileDrop.visibility = View.GONE
142-
}
143-
}
144-
}
145-
146135
override fun applyBrand(color: Int) {
147136
val util = BrandingUtil.of(color, this)
148137

149138
binding.run {
150139
util.platform.run {
151140
themeRadioButton(canViewRadioButton)
152141
themeRadioButton(canEditRadioButton)
153-
themeRadioButton(shareProcessPermissionFileDrop)
154142

155143
colorTextView(shareProcessEditShareLink)
156144
colorTextView(shareProcessAdvancePermissionTitle)
@@ -229,7 +217,7 @@ class NoteShareDetailActivity :
229217
}
230218

231219
private fun updateViewForUpdate() {
232-
if (share?.isFolder == true) updateViewForFolder() else updateViewForFile()
220+
updateViewForFile()
233221

234222
selectRadioButtonAccordingToPermission()
235223

@@ -269,7 +257,7 @@ class NoteShareDetailActivity :
269257
}
270258

271259
private fun selectRadioButtonAccordingToPermission() {
272-
val selectedType = SharePermissionManager.getSelectedType(share, encrypted = false)
260+
val selectedType = SharePermissionManager.getSelectedType(share)
273261
binding.run {
274262
when (selectedType) {
275263
QuickPermissionType.VIEW_ONLY -> {
@@ -280,10 +268,6 @@ class NoteShareDetailActivity :
280268
canEditRadioButton.isChecked = true
281269
}
282270

283-
QuickPermissionType.FILE_REQUEST -> {
284-
shareProcessPermissionFileDrop.isChecked = true
285-
}
286-
287271
else -> Unit
288272
}
289273
}
@@ -292,7 +276,7 @@ class NoteShareDetailActivity :
292276
private fun setMaxPermissionsIfDefaultPermissionExists() {
293277
if (repository.getCapabilities().defaultPermission != OCShare.NO_PERMISSION) {
294278
binding.canEditRadioButton.isChecked = true
295-
permission = SharePermissionManager.getMaximumPermission(isFolder())
279+
permission = SharePermissionManager.getMaximumPermission()
296280
}
297281
}
298282

@@ -372,13 +356,8 @@ class NoteShareDetailActivity :
372356
shareProcessSetPasswordSwitch.visibility = View.VISIBLE
373357

374358
if (share != null) {
375-
if (SharePermissionManager.isFileRequest(share)) {
376-
shareProcessHideDownloadCheckbox.visibility = View.GONE
377-
} else {
378-
shareProcessHideDownloadCheckbox.visibility = View.VISIBLE
379-
shareProcessHideDownloadCheckbox.isChecked =
380-
share?.isHideFileDownload == true
381-
}
359+
shareProcessHideDownloadCheckbox.visibility = View.VISIBLE
360+
shareProcessHideDownloadCheckbox.isChecked = share?.isHideFileDownload == true
382361
}
383362
}
384363
}
@@ -401,20 +380,6 @@ class NoteShareDetailActivity :
401380

402381
private fun updateViewForFile() {
403382
binding.canEditRadioButton.text = getString(R.string.link_share_editing)
404-
binding.shareProcessPermissionFileDrop.visibility = View.GONE
405-
}
406-
407-
private fun updateViewForFolder() {
408-
binding.run {
409-
canEditRadioButton.text =
410-
getString(R.string.link_share_allow_upload_and_editing)
411-
shareProcessPermissionFileDrop.visibility = View.VISIBLE
412-
if (isSecureShare) {
413-
shareProcessPermissionFileDrop.visibility = View.GONE
414-
shareProcessAllowResharingCheckbox.visibility = View.GONE
415-
shareProcessSetExpDateSwitch.visibility = View.GONE
416-
}
417-
}
418383
}
419384

420385
/**
@@ -473,11 +438,7 @@ class NoteShareDetailActivity :
473438
}
474439

475440
R.id.can_edit_radio_button -> {
476-
permission = SharePermissionManager.getMaximumPermission(isFolder())
477-
}
478-
479-
R.id.share_process_permission_file_drop -> {
480-
permission = OCShare.CREATE_PERMISSION_FLAG
441+
permission = SharePermissionManager.getMaximumPermission()
481442
}
482443
}
483444
}
@@ -604,7 +565,6 @@ class NoteShareDetailActivity :
604565
binding.shareProcessAllowResharingCheckbox.isChecked -> getReSharePermission()
605566
binding.canViewRadioButton.isChecked -> OCShare.READ_PERMISSION_FLAG
606567
binding.canEditRadioButton.isChecked -> OCShare.MAXIMUM_PERMISSIONS_FOR_FILE
607-
binding.shareProcessPermissionFileDrop.isChecked -> OCShare.CREATE_PERMISSION_FLAG
608568
else -> permission
609569
}
610570

@@ -627,9 +587,10 @@ class NoteShareDetailActivity :
627587

628588
private suspend fun updateShare(noteText: String, label: String, password: String, sendEmail: Boolean) {
629589
val downloadPermission = !binding.shareProcessHideDownloadCheckbox.isChecked
590+
630591
val requestBody = repository.getUpdateShareRequest(
631592
downloadPermission = downloadPermission,
632-
share = share,
593+
share = share!!,
633594
noteText = noteText,
634595
label = label,
635596
password = password,
@@ -673,7 +634,7 @@ class NoteShareDetailActivity :
673634
)
674635

675636
if (result.isSuccess()) {
676-
repository.getSharesForNotesAndSaveShareEntities()
637+
repository.fetchSharesForNotesAndSaveShareEntities()
677638
}
678639

679640
handleResult(result.isSuccess())
@@ -707,9 +668,7 @@ class NoteShareDetailActivity :
707668
}
708669

709670
// region Helpers
710-
private fun isFolder(): Boolean = (share?.isFolder == true)
711-
712-
private fun canSetFileRequest(): Boolean = isFolder() && shareType.isPublicOrMail()
671+
private fun canSetFileRequest(): Boolean = shareType.isPublicOrMail()
713672

714673
private fun isPublicShare(): Boolean = (shareType == ShareType.PUBLIC_LINK)
715674
// endregion

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/ShareeListAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
137137
if (holder instanceof LinkShareViewHolder publicShareViewHolder) {
138138
publicShareViewHolder.bind(share, listener, position);
139139
} else if (holder instanceof InternalShareViewHolder internalShareViewHolder) {
140-
internalShareViewHolder.bind(share, listener);
140+
internalShareViewHolder.bind(listener);
141141
} else if (holder instanceof NewLinkShareViewHolder newLinkShareViewHolder) {
142142
newLinkShareViewHolder.bind(listener);
143143
} else {

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/holder/InternalShareViewHolder.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
package it.niedermann.owncloud.notes.share.adapter.holder;
88

99
import android.content.Context;
10-
import android.graphics.PorterDuff;
1110
import android.view.View;
1211

1312
import androidx.annotation.NonNull;
14-
import androidx.core.content.res.ResourcesCompat;
1513
import androidx.recyclerview.widget.RecyclerView;
1614

17-
import com.owncloud.android.lib.resources.shares.OCShare;
18-
1915
import it.niedermann.owncloud.notes.R;
2016
import it.niedermann.owncloud.notes.databinding.ItemInternalShareLinkBinding;
2117
import it.niedermann.owncloud.notes.share.listener.ShareeListAdapterListener;
@@ -34,13 +30,8 @@ public InternalShareViewHolder(ItemInternalShareLinkBinding binding, Context con
3430
this.context = context;
3531
}
3632

37-
public void bind(OCShare share, ShareeListAdapterListener listener) {
38-
if (share.isFolder()) {
39-
binding.shareInternalLinkText.setText(context.getString(R.string.share_internal_link_to_folder_text));
40-
} else {
41-
binding.shareInternalLinkText.setText(context.getString(R.string.share_internal_link_to_file_text));
42-
}
43-
33+
public void bind(ShareeListAdapterListener listener) {
34+
binding.shareInternalLinkText.setText(context.getString(R.string.share_internal_link_to_file_text));
4435
binding.copyInternalContainer.setOnClickListener(l -> listener.copyInternalLink());
4536
}
4637
}

0 commit comments

Comments
 (0)