Browse Source

feat: update the isPrivate

tags/v1.21.12.1
colorfulberry 5 years ago
parent
commit
64d784da07
5 changed files with 37 additions and 4 deletions
  1. +2
    -1
      models/attachment.go
  2. +13
    -0
      routers/repo/attachment.go
  3. +1
    -0
      routers/routes/routes.go
  4. +2
    -2
      templates/repo/datasets/dataset_list.tmpl
  5. +19
    -1
      web_src/js/index.js

+ 2
- 1
models/attachment.go View File

@@ -31,6 +31,7 @@ type Attachment struct {
Name string Name string
DownloadCount int64 `xorm:"DEFAULT 0"` DownloadCount int64 `xorm:"DEFAULT 0"`
Size int64 `xorm:"DEFAULT 0"` Size int64 `xorm:"DEFAULT 0"`
IsPrivate bool `xorm:"DEFAULT false"`
CreatedUnix timeutil.TimeStamp `xorm:"created"` CreatedUnix timeutil.TimeStamp `xorm:"created"`
} }


@@ -264,7 +265,7 @@ func updateAttachment(e Engine, atta *Attachment) error {
// Use uuid only if id is not set and uuid is set // Use uuid only if id is not set and uuid is set
sess = e.Where("uuid = ?", atta.UUID) sess = e.Where("uuid = ?", atta.UUID)
} }
_, err := sess.Cols("name", "issue_id", "release_id", "comment_id", "download_count").Update(atta)
_, err := sess.Cols("name", "issue_id", "release_id", "comment_id", "download_count", "is_private").Update(atta)
return err return err
} }




+ 13
- 0
routers/repo/attachment.go View File

@@ -59,6 +59,7 @@ func UploadAttachment(ctx *context.Context) {
datasetID, _ := strconv.ParseInt(ctx.Req.FormValue("dataset_id"), 10, 64) datasetID, _ := strconv.ParseInt(ctx.Req.FormValue("dataset_id"), 10, 64)


attach, err := models.NewAttachment(&models.Attachment{ attach, err := models.NewAttachment(&models.Attachment{
IsPrivate: false,
UploaderID: ctx.User.ID, UploaderID: ctx.User.ID,
Name: header.Filename, Name: header.Filename,
DatasetID: datasetID, DatasetID: datasetID,
@@ -74,6 +75,18 @@ func UploadAttachment(ctx *context.Context) {
}) })
} }


func UpdatePublicAttachment(ctx *context.Context) {
file := ctx.Query("file")
isPrivate, _ := strconv.ParseBool(ctx.Query("is_private"))
attach, err := models.GetAttachmentByUUID(file)
if err != nil {
ctx.Error(404, err.Error())
return
}
attach.IsPrivate = isPrivate
models.UpdateAttachment(attach)
}

// DeleteAttachment response for deleting issue's attachment // DeleteAttachment response for deleting issue's attachment
func DeleteAttachment(ctx *context.Context) { func DeleteAttachment(ctx *context.Context) {
file := ctx.Query("file") file := ctx.Query("file")


+ 1
- 0
routers/routes/routes.go View File

@@ -519,6 +519,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/attachments", func() { m.Group("/attachments", func() {
m.Post("", repo.UploadAttachment) m.Post("", repo.UploadAttachment)
m.Post("/delete", repo.DeleteAttachment) m.Post("/delete", repo.DeleteAttachment)
m.Post("/private", repo.UpdatePublicAttachment)
}, reqSignIn) }, reqSignIn)


m.Group("/:username", func() { m.Group("/:username", func() {


+ 2
- 2
templates/repo/datasets/dataset_list.tmpl View File

@@ -20,9 +20,9 @@


<div class="three wide column"> <div class="three wide column">
<div class="ui buttons mini"> <div class="ui buttons mini">
<a class="ui button mini">private</a>
<a class="ui button mini {{if .IsPrivate}}positive active{{end}}" href="javascript:void(0)" data-dataset-status="true-{{.UUID}}" data-csrf="{{$.CsrfToken}}" data-url="{{AppSubUrl}}/attachments/private" data-uuid={{.UUID}} data-private="true" data-is-private={{.IsPrivate}}>private</a>
<div class="or"></div> <div class="or"></div>
<a class="ui positive button active mini">public</a>
<a class="ui button mini active {{if not .IsPrivate}}positive active{{end}}" href="javascript:void(0)" data-dataset-status="false-{{.UUID}}" data-csrf="{{$.CsrfToken}}" data-url="{{AppSubUrl}}/attachments/private" data-uuid={{.UUID}} data-private="false" data-is-private={{.IsPrivate}}>public</a>
</div> </div>
</div> </div>




+ 19
- 1
web_src/js/index.js View File

@@ -1094,9 +1094,27 @@ async function initRepository() {
$('#dataset-content input').focus(); $('#dataset-content input').focus();
return false; return false;
}; };
$('[data-dataset-status]').on('click', function () {
const $this = $(this);
const $private = $this.data('private');
const $is_private = $this.data('is-private');
if ($is_private === $private) {
return;
}
const $uuid = $this.data('uuid');
$.post($this.data('url'), {
_csrf: $this.data('csrf'),
file: $uuid,
is_private: $private,
}).done((_data) => {
$(`[data-uuid='${$uuid}']`).removeClass('positive active');
$this.addClass('positive active');
}).fail(() => {
window.location.reload();
});
});
$('[data-dataset-delete]').on('click', function () { $('[data-dataset-delete]').on('click', function () {
const $this = $(this); const $this = $(this);

$('#data-dataset-delete-modal').modal({ $('#data-dataset-delete-modal').modal({
closable: false, closable: false,
onApprove() { onApprove() {


Loading…
Cancel
Save