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

Add label for public shares #3034

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
All notable changes to this project will be documented in this file.
##
## [5.3.0] - tbd
### New
- Add label to public shares
### Fixes
- Fix API calls
### Changes
Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
['name' => 'share#resolveGroup', 'url' => '/share/{token}/resolve', 'verb' => 'GET'],
['name' => 'share#user_to_admin', 'url' => '/share/{token}/admin', 'verb' => 'PUT'],
['name' => 'share#admin_to_user', 'url' => '/share/{token}/user', 'verb' => 'PUT'],
['name' => 'share#set_label', 'url' => '/share/{token}/setlabel', 'verb' => 'PUT'],
['name' => 'share#set_public_poll_email', 'url' => '/share/{token}/publicpollemail/{value}', 'verb' => 'PUT'],

['name' => 'settings#getAppSettings', 'url' => '/settings/app', 'verb' => 'GET'],
Expand Down
12 changes: 11 additions & 1 deletion lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,23 @@ public function userToAdmin(string $token): JSONResponse {
}

/**
* Convert user to poll admin
* Change the contraints for email addresses in public polls
* @NoAdminRequired
*/
public function setPublicPollEmail(string $token, string $value): JSONResponse {
return $this->response(fn () => ['share' => $this->shareService->setPublicPollEmail($token, $value)]);
}

/**
* Change the contraints for email addresses in public polls
* @NoAdminRequired
*/
public function setLabel(string $token, string $label = ''): JSONResponse {
return $this->response(fn () => [
'share' => $this->shareService->setDisplayName($this->shareService->get($token), $label)
]);
}

/**
* Convert poll admin to user
* @NoAdminRequired
Expand Down
12 changes: 7 additions & 5 deletions lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function setEmailAddress(Share $share, string $emailAddress, bool $emptyI
}

/**
* Set displayName of personal share
* Set displayName of personal share or label of a public share
*
* @return Share
*/
Expand All @@ -187,12 +187,14 @@ public function setDisplayName(Share $share, string $displayName): Share {

if ($this->share->getType() === Share::TYPE_EXTERNAL) {
$this->systemService->validatePublicUsername($displayName, $this->share);
$this->share->setDisplayName($displayName);
// TODO: Send confirmation
$this->share = $this->shareMapper->update($this->share);
} elseif ($this->share->getType() === Share::TYPE_PUBLIC) {
$this->acl->setPollId($share->getPollId())->request(Acl::PERMISSION_POLL_EDIT);
} else {
throw new InvalidShareTypeException('Displayname can only be changed in external shares.');
throw new InvalidShareTypeException('Displayname can only be changed in external or public shares.');
}

$this->share->setDisplayName($displayName);
$this->share = $this->shareMapper->update($this->share);

$this->eventDispatcher->dispatchTyped(new ShareChangedDisplayNameEvent($this->share));

Expand Down
15 changes: 11 additions & 4 deletions src/js/Api/shares.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ const shares = {
})
},

writeLabel(shareToken, displayName) {
return httpInstance.request({
method: 'PUT',
url: `share/${shareToken}/setlabel`,
data: {
label: displayName,
},
cancelToken: cancelTokenHandlerObject[this.writeLabel.name].handleRequestCancellation().token,
})
},

switchAdmin(shareToken, setTo) {
return httpInstance.request({
method: 'PUT',
url: `share/${shareToken}/${setTo}`,
params: { time: +new Date() },
cancelToken: cancelTokenHandlerObject[this.switchAdmin.name].handleRequestCancellation().token,
})
},
Expand All @@ -56,7 +66,6 @@ const shares = {
return httpInstance.request({
method: 'PUT',
url: `share/${shareToken}/publicpollemail/${setTo}`,
params: { time: +new Date() },
cancelToken: cancelTokenHandlerObject[this.setEmailAddressConstraint.name].handleRequestCancellation().token,
})
},
Expand All @@ -65,7 +74,6 @@ const shares = {
return httpInstance.request({
method: 'POST',
url: `share/${shareToken}/invite`,
params: { time: +new Date() },
cancelToken: cancelTokenHandlerObject[this.sendInvitation.name].handleRequestCancellation().token,
})
},
Expand All @@ -83,7 +91,6 @@ const shares = {
return httpInstance.request({
method: 'DELETE',
url: `share/${shareToken}`,
params: { time: +new Date() },
cancelToken: cancelTokenHandlerObject[this.deleteShare.name].handleRequestCancellation().token,
})
},
Expand Down
219 changes: 219 additions & 0 deletions src/js/components/Shares/ShareItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
<!--
- @copyright Copyright (c) 2018 René Gieling <[email protected]>
-
- @author René Gieling <[email protected]>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->

<template>
<UserItem show-email v-bind="share" :icon="true">
<template #status>
<div v-if="hasVoted(share.userId)">
<VotedIcon class="vote-status voted" :title="t('polls', 'Has voted')" />
</div>
<div v-else-if="['public', 'group'].includes(share.type)">
<div class="vote-status empty" />
</div>
<div v-else>
<UnvotedIcon class="vote-status unvoted" :title="t('polls', 'Has not voted')" />
</div>
</template>

<NcActions>
<NcActionInput v-if="share.type === 'public'"
:show-trailing-button="false"
:value.sync="label"
@input="writeLabel()">
<template #icon>
<EditIcon />
</template>
{{ t('polls', 'Share label') }}
</NcActionInput>

<NcActionButton v-if="share.emailAddress || share.type === 'group'" @click="sendInvitation()">
<template #icon>
<SendEmailIcon />
</template>
{{ share.invitationSent ? t('polls', 'Resend invitation mail') : t('polls', 'Send invitation mail') }}
</NcActionButton>

<NcActionButton v-if="share.type === 'user' || share.type === 'admin'" @click="switchAdmin()">
<template #icon>
<GrantAdminIcon v-if="share.type === 'user'" />
<WithdrawAdminIcon v-else />
</template>
{{ share.type === 'user' ? t('polls', 'Grant poll admin access') : t('polls', 'Withdraw poll admin access') }}
</NcActionButton>

<NcActionButton @click="copyLink()">
<template #icon>
<ClippyIcon />
</template>
{{ t('polls', 'Copy link to clipboard') }}
</NcActionButton>

<NcActionButton v-if="share.URL" @click="$emit('show-qr-code')">
<template #icon>
<QrIcon />
</template>
{{ t('polls', 'Show QR code') }}
</NcActionButton>

<NcActionCaption v-if="share.type === 'public'" :title="t('polls', 'Options for the registration dialog')" />

<NcActionRadio v-if="share.type === 'public'"
name="publicPollEmail"
value="optional"
:checked="share.publicPollEmail === 'optional'"
@change="setPublicPollEmail({ share, value: 'optional' })">
{{ t('polls', 'Email address is optional') }}
</NcActionRadio>

<NcActionRadio v-if="share.type === 'public'"
name="publicPollEmail"
value="mandatory"
:checked="share.publicPollEmail === 'mandatory'"
@change="setPublicPollEmail({ share, value: 'mandatory' })">
{{ t('polls', 'Email address is mandatory') }}
</NcActionRadio>

<NcActionRadio v-if="share.type === 'public'"
name="publicPollEmail"
value="disabled"
:checked="share.publicPollEmail === 'disabled'"
@change="setPublicPollEmail({ share, value: 'disabled' })">
{{ t('polls', 'Do not ask for an email address') }}
</NcActionRadio>
</NcActions>

<ActionDelete :title="t('polls', 'Remove share')"
@delete="removeShare({ share })" />
</UserItem>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import { showSuccess, showError } from '@nextcloud/dialogs'
import { NcActions, NcActionButton, NcActionCaption, NcActionInput, NcActionRadio } from '@nextcloud/vue'
import ActionDelete from '../Actions/ActionDelete.vue'
import VotedIcon from 'vue-material-design-icons/CheckboxMarked.vue'
import UnvotedIcon from 'vue-material-design-icons/MinusBox.vue'
import SendEmailIcon from 'vue-material-design-icons/EmailArrowRight.vue'
import GrantAdminIcon from 'vue-material-design-icons/ShieldCrown.vue'
import EditIcon from 'vue-material-design-icons/Pencil.vue'
import WithdrawAdminIcon from 'vue-material-design-icons/ShieldCrownOutline.vue'
import ClippyIcon from 'vue-material-design-icons/ClipboardArrowLeftOutline.vue'
import QrIcon from 'vue-material-design-icons/Qrcode.vue'

export default {
name: 'ShareItem',

components: {
WithdrawAdminIcon,
GrantAdminIcon,
ClippyIcon,
EditIcon,
QrIcon,
SendEmailIcon,
UnvotedIcon,
VotedIcon,
NcActions,
NcActionButton,
NcActionCaption,
NcActionInput,
NcActionRadio,
ActionDelete,
},

props: {
share: {
type: Object,
default: undefined,
},
},

computed: {
...mapGetters({
hasVoted: 'votes/hasVoted',
}),

label: {
get() {
return this.share.displayName
},
set(value) {
this.$store.commit('shares/setShareProperty', { id: this.share.id, displayName: value })
},
},

},

methods: {
...mapActions({
removeShare: 'shares/delete',
switchAdmin: 'shares/switchAdmin',
setPublicPollEmail: 'shares/setPublicPollEmail',
setLabel: 'shares/writeLabel',
}),

async writeLabel() {
this.setLabel({ token: this.share.token, displayName: this.share.displayName })
},

async sendInvitation() {
const response = await this.$store.dispatch('shares/sendInvitation', { share: this.share })
if (response.data?.sentResult?.sentMails) {
response.data.sentResult.sentMails.forEach((item) => {
showSuccess(t('polls', 'Invitation sent to {displayName} ({emailAddress})', { emailAddress: item.emailAddress, displayName: item.displayName }))
})
}
if (response.data?.sentResult?.abortedMails) {
response.data.sentResult.abortedMails.forEach((item) => {
console.error('Mail could not be sent!', { recipient: item })
showError(t('polls', 'Error sending invitation to {displayName} ({emailAddress})', { emailAddress: item.emailAddress, displayName: item.displayName }))
})
}
},

copyLink() {
try {
navigator.clipboard.writeText(this.share.URL)
showSuccess(t('polls', 'Link copied to clipboard'))
} catch {
showError(t('polls', 'Error while copying link to clipboard'))
}
},
},
}
</script>

<style lang="scss">
.vote-status {
margin-left: 8px;
width: 32px;

&.voted {
color: var(--color-polls-foreground-yes)
}

&.unvoted {
color: var(--color-polls-foreground-no)
}
}

</style>
Loading