mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-03-13 23:32:41 +00:00
Some cleanup and renames.
This commit is contained in:
parent
5a1547f2e8
commit
f99434fe69
3 changed files with 22 additions and 28 deletions
|
@ -92,7 +92,7 @@ type AbuseReport struct {
|
|||
ID int64 `xorm:"pk autoincr"`
|
||||
Status ReportStatusType `xorm:"NOT NULL DEFAULT 1"`
|
||||
// The ID of the user who submitted the report.
|
||||
ReporterID int64 `xorm:"NOT NULL"` // index ?!
|
||||
ReporterID int64 `xorm:"NOT NULL"`
|
||||
// Reported content type: user/organization profile, repository, issue/pull or comment.
|
||||
ContentType ReportedContentType `xorm:"INDEX NOT NULL"`
|
||||
// The ID of the reported item (based on ContentType: user, repository, issue or comment).
|
||||
|
@ -100,7 +100,7 @@ type AbuseReport struct {
|
|||
// The abuse category selected by the reporter.
|
||||
Category AbuseCategoryType `xorm:"INDEX NOT NULL"`
|
||||
// Remarks provided by the reporter.
|
||||
Remarks string // TODO: ReporterReparks or Reason
|
||||
Remarks string
|
||||
// The ID of the corresponding shadow-copied content when exists; otherwise null.
|
||||
ShadowCopyID sql.NullInt64 `xorm:"DEFAULT NULL"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
|
||||
|
|
|
@ -37,12 +37,12 @@ func CreateShadowCopyForUser(ctx context.Context, userID int64, content string)
|
|||
return createShadowCopy(ctx, ReportedContentTypeUser, userID, content)
|
||||
}
|
||||
|
||||
func CreateShadowCopyForRepository(ctx context.Context, commentID int64, content string) error {
|
||||
return createShadowCopy(ctx, ReportedContentTypeRepository, commentID, content)
|
||||
func CreateShadowCopyForRepository(ctx context.Context, repoID int64, content string) error {
|
||||
return createShadowCopy(ctx, ReportedContentTypeRepository, repoID, content)
|
||||
}
|
||||
|
||||
func CreateShadowCopyForIssue(ctx context.Context, commentID int64, content string) error {
|
||||
return createShadowCopy(ctx, ReportedContentTypeIssue, commentID, content)
|
||||
func CreateShadowCopyForIssue(ctx context.Context, issueID int64, content string) error {
|
||||
return createShadowCopy(ctx, ReportedContentTypeIssue, issueID, content)
|
||||
}
|
||||
|
||||
func CreateShadowCopyForComment(ctx context.Context, commentID int64, content string) error {
|
||||
|
@ -74,7 +74,6 @@ func createShadowCopy(ctx context.Context, contentType ReportedContentType, cont
|
|||
_, err = sess.Where(builder.Eq{
|
||||
"content_type": contentType,
|
||||
"content_id": contentID,
|
||||
// TODO: What should happen if an item is updated multiple times (and the reports already have a shadow copy ID)?
|
||||
}).And(builder.IsNull{"shadow_copy_id"}).Update(&AbuseReport{ShadowCopyID: shadowCopy.NullableID()})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not link the shadow copy (%d) to reported content with type %d and ID %d - %w", shadowCopy.ID, contentType, contentID, err)
|
||||
|
|
|
@ -31,30 +31,28 @@ type UserData struct {
|
|||
// This field was intentionally renamed so that is not the same with the one from User struct.
|
||||
// If we keep it the same as in User, during login it might trigger the creation of a shadow copy.
|
||||
// TODO: Should we decide that this field is not that relevant for abuse reporting purposes, better remove it.
|
||||
LastLogin timeutil.TimeStamp `json:"LastLoginUnix"`
|
||||
Avatar string
|
||||
AvatarEmail string
|
||||
NormalizedFederatedURI string
|
||||
LastLogin timeutil.TimeStamp `json:"LastLoginUnix"`
|
||||
Avatar string
|
||||
AvatarEmail string
|
||||
}
|
||||
|
||||
// newUserData creates a trimmed down user to be used just to create a JSON structure
|
||||
// (keeping only the fields relevant for moderation purposes)
|
||||
func newUserData(user *User) UserData {
|
||||
return UserData{
|
||||
Name: user.Name,
|
||||
FullName: user.FullName,
|
||||
Email: user.Email,
|
||||
LoginName: user.LoginName,
|
||||
Location: user.Location,
|
||||
Website: user.Website,
|
||||
Pronouns: user.Pronouns,
|
||||
Description: user.Description,
|
||||
CreatedUnix: user.CreatedUnix,
|
||||
UpdatedUnix: user.UpdatedUnix,
|
||||
LastLogin: user.LastLoginUnix,
|
||||
Avatar: user.Avatar,
|
||||
AvatarEmail: user.AvatarEmail,
|
||||
NormalizedFederatedURI: user.NormalizedFederatedURI,
|
||||
Name: user.Name,
|
||||
FullName: user.FullName,
|
||||
Email: user.Email,
|
||||
LoginName: user.LoginName,
|
||||
Location: user.Location,
|
||||
Website: user.Website,
|
||||
Pronouns: user.Pronouns,
|
||||
Description: user.Description,
|
||||
CreatedUnix: user.CreatedUnix,
|
||||
UpdatedUnix: user.UpdatedUnix,
|
||||
LastLogin: user.LastLoginUnix,
|
||||
Avatar: user.Avatar,
|
||||
AvatarEmail: user.AvatarEmail,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,9 +83,6 @@ func IfNeededCreateShadowCopyForUser(ctx context.Context, user *User, alteredCol
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Maybe it is better (faster) to first check the result of moderation.IsReported()
|
||||
// and only when true to check if any of the columns being updated is relevant in the context of shadow copying.
|
||||
|
||||
if shouldCheckIfReported && moderation.IsReported(ctx, moderation.ReportedContentTypeUser, user.ID) {
|
||||
userData := newUserData(user)
|
||||
content, err := json.Marshal(userData)
|
||||
|
|
Loading…
Reference in a new issue