allow disable sharing for spaces

This commit is contained in:
vabene1111 2021-06-15 21:12:43 +02:00
parent cdf4476345
commit b3504699b1
6 changed files with 39 additions and 12 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.4 on 2021-06-15 19:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0133_sharelink_abuse_blocked'),
]
operations = [
migrations.AddField(
model_name='space',
name='allow_sharing',
field=models.BooleanField(default=True),
),
]

View File

@ -70,6 +70,7 @@ class Space(ExportModelOperationsMixin('space'), models.Model):
max_recipes = models.IntegerField(default=0) max_recipes = models.IntegerField(default=0)
max_file_storage_mb = models.IntegerField(default=0, help_text=_('Maximum file storage for space in MB. 0 for unlimited, -1 to disable file upload.')) max_file_storage_mb = models.IntegerField(default=0, help_text=_('Maximum file storage for space in MB. 0 for unlimited, -1 to disable file upload.'))
max_users = models.IntegerField(default=0) max_users = models.IntegerField(default=0)
allow_sharing = models.BooleanField(default=True)
demo = models.BooleanField(default=False) demo = models.BooleanField(default=False)
def __str__(self): def __str__(self):

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -579,9 +579,12 @@ def sync_all(request):
@group_required('user') @group_required('user')
def share_link(request, pk): def share_link(request, pk):
if request.space.allow_sharing:
recipe = get_object_or_404(Recipe, pk=pk, space=request.space) recipe = get_object_or_404(Recipe, pk=pk, space=request.space)
link = ShareLink.objects.create(recipe=recipe, created_by=request.user, space=request.space) link = ShareLink.objects.create(recipe=recipe, created_by=request.user, space=request.space)
return JsonResponse({'pk': pk, 'share': link.uuid, 'link': request.build_absolute_uri(reverse('view_recipe', args=[pk, link.uuid]))}) return JsonResponse({'pk': pk, 'share': link.uuid, 'link': request.build_absolute_uri(reverse('view_recipe', args=[pk, link.uuid]))})
else:
return JsonResponse({'error': 'sharing_disabled'}, status=403)
@group_required('user') @group_required('user')

View File

@ -42,7 +42,8 @@
rel="noopener noreferrer"><i class="fas fa-file-export fa-fw"></i> {{ $t('Export') }}</a> rel="noopener noreferrer"><i class="fas fa-file-export fa-fw"></i> {{ $t('Export') }}</a>
<button class="dropdown-item" @click="createShareLink()" v-if="recipe.internal"><i <button class="dropdown-item" @click="createShareLink()" v-if="recipe.internal"><i
class="fas fa-share-alt fa-fw"></i> {{ $t('Share') }}</button> class="fas fa-share-alt fa-fw"></i> {{ $t('Share') }}
</button>
</div> </div>
@ -62,8 +63,8 @@
</label> </label>
<br/> <br/>
<br/> <br/>
<b-button variant="success" @click="copyShareLink()" style="margin-right: 1vh; ">{{$t('Copy')}}</b-button> <b-button variant="success" @click="copyShareLink()" style="margin-right: 1vh; ">{{ $t('Copy') }}</b-button>
<b-button @click="$bvModal.hide('modal-share-link')">{{$t('Close')}}</b-button> <b-button @click="$bvModal.hide('modal-share-link')">{{ $t('Close') }}</b-button>
<br/> <br/>
<br/> <br/>
</div> </div>
@ -76,7 +77,7 @@
<script> <script>
import {resolveDjangoUrl, ResolveUrlMixin} from "@/utils/utils"; import {makeToast, resolveDjangoUrl, ResolveUrlMixin} from "@/utils/utils";
import CookLog from "@/components/CookLog"; import CookLog from "@/components/CookLog";
import axios from "axios"; import axios from "axios";
@ -106,14 +107,18 @@ export default {
}, },
methods: { methods: {
createShareLink: function () { createShareLink: function () {
this.$bvModal.show('modal-share-link')
axios.get(resolveDjangoUrl('api_share_link', this.recipe.id)).then(result => { axios.get(resolveDjangoUrl('api_share_link', this.recipe.id)).then(result => {
this.$bvModal.show('modal-share-link')
this.recipe_share_link = result.data.link this.recipe_share_link = result.data.link
console.log('GET', result) }).catch(err => {
if (err.response.status === 403) {
makeToast(this.$t('Share'), this.$t('Sharing is not enabled for this space.'), 'danger')
}
}) })
}, },
copyShareLink: function (){ copyShareLink: function () {
let share_input = this.$refs.share_link_ref; let share_input = this.$refs.share_link_ref;
share_input.select(); share_input.select();