Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to delete passwords on public links when password is enforced but permission is set #9857

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
:is-folder-share="resource.isFolder"
:is-modifiable="canEditLink(quicklink)"
:is-password-enforced="isPasswordEnforcedFor(quicklink)"
:is-password-removable="canDeletePublicLinkPassword(quicklink)"
:link="quicklink"
@update-link="checkLinkToUpdate"
@remove-public-link="deleteLinkConfirmation"
Expand Down Expand Up @@ -57,6 +58,7 @@
:is-folder-share="resource.isFolder"
:is-modifiable="canEditLink(link)"
:is-password-enforced="isPasswordEnforcedFor(link)"
:is-password-removable="canDeletePublicLinkPassword(link)"
:link="link"
@update-link="checkLinkToUpdate"
@remove-public-link="deleteLinkConfirmation"
Expand Down Expand Up @@ -185,6 +187,11 @@ export default defineComponent({
})
)
const canCreatePublicLinks = computed(() => can('create-all', 'PublicLink'))

const canDeleteReadOnlyPublicLinkPassword = computed(() =>
can('delete-all', 'ReadOnlyPublicLinkPassword')
)

const canCreateLinks = computed(() => {
if (unref(resource).isReceivedShare() && !unref(hasResharing)) {
return false
Expand Down Expand Up @@ -225,6 +232,7 @@ export default defineComponent({
directLinks,
indirectLinks,
canCreatePublicLinks,
canDeleteReadOnlyPublicLinkPassword,
configurationManager,
passwordPolicyService,
canCreateLinks,
Expand Down Expand Up @@ -389,6 +397,21 @@ export default defineComponent({
)
},

canDeletePublicLinkPassword(link) {
const isFolder = link.indirect || this.resource.isFolder
const isPasswordEnforced = this.isPasswordEnforcedFor(link)

if (!isPasswordEnforced) {
return true
}

const currentRole = LinkShareRoles.getByBitmask(parseInt(link.permissions), isFolder)

return (
currentRole.name === linkRoleViewerFolder.name && this.canDeleteReadOnlyPublicLinkPassword
)
},

addNewLink() {
this.checkLinkToCreate({
link: {
Expand Down Expand Up @@ -422,7 +445,7 @@ export default defineComponent({
checkLinkToUpdate({ link }) {
const params = this.getParamsForLink(link)

if (!link.password && this.isPasswordEnforcedFor(link)) {
AlexAndBear marked this conversation as resolved.
Show resolved Hide resolved
if (!link.password && !this.canDeletePublicLinkPassword(link)) {
showQuickLinkPasswordModal(
{
...this.$language,
Expand Down Expand Up @@ -626,6 +649,7 @@ export default defineComponent({
#oc-files-sharing-sidebar {
border-radius: 5px;
}

.link-name-container {
background-color: var(--oc-color-input-bg);
border: 1px solid var(--oc-color-input-border);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ export default defineComponent({
type: Boolean,
default: false
},
isPasswordRemovable: {
type: Boolean,
default: false
},
link: {
type: Object,
required: true
Expand Down Expand Up @@ -323,7 +327,7 @@ export default defineComponent({
method: this.showPasswordModal
})

if (!this.isPasswordEnforced) {
if (this.isPasswordRemovable) {
result.push({
id: 'remove-password',
title: this.$gettext('Remove password'),
Expand All @@ -338,7 +342,7 @@ export default defineComponent({
})
}
}
if (!this.isPasswordEnforced && !this.link.password && !this.isAliasLink) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh I don't get this check in the first place? If password is not enforced we don't allow the user to add a password ?

if (!this.link.password && !this.isAliasLink) {
result.push({
id: 'add-password',
title: this.$gettext('Add password'),
Expand Down
1 change: 1 addition & 0 deletions packages/web-client/src/helpers/resource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type AbilitySubjects =
| 'Language'
| 'Logo'
| 'PublicLink'
| 'ReadOnlyPublicLinkPassword'
| 'Role'
| 'Setting'

Expand Down
23 changes: 14 additions & 9 deletions packages/web-pkg/src/quickActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ export default {
if (passwordEnforced) {
return showQuickLinkPasswordModal(
{ store, $gettext: language.$gettext, passwordPolicyService },
async (password) => {
await copyQuicklink({
ability,
clientService,
language,
password,
resource: item,
store
})
async (password: string) => {
try {
await copyQuicklink({
ability,
clientService,
language,
password,
resource: item,
store
})
store.dispatch('hideModal')
} catch (e) {
console.error(e)
}
}
)
}
Expand Down
3 changes: 3 additions & 0 deletions packages/web-runtime/src/services/auth/abilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const getAbilities = (
],
'Logo.Write.all': [{ action: 'update-all', subject: 'Logo' }],
'PublicLink.Write.all': [{ action: 'create-all', subject: 'PublicLink' }],
'ReadOnlyPublicLinkPassword.Delete.all': [
{ action: 'delete-all', subject: 'ReadOnlyPublicLinkPassword' }
],
'Roles.ReadWrite.all': [
{ action: 'create-all', subject: 'Role' },
{ action: 'delete-all', subject: 'Role' },
Expand Down