Setting group defaults from group config.

This commit is contained in:
Nick Gerakines 2020-03-30 18:02:54 -04:00
parent 7aa1e4737a
commit 363d0997b8
No known key found for this signature in database
GPG Key ID: 33D43D854F96B2E4
3 changed files with 38 additions and 3 deletions

View File

@ -36,7 +36,7 @@ var DefaultGroupMemberRoleFlag = cli.IntFlag{
Name: "default-group-member-role",
Usage: "The default member role for groups.",
EnvVars: []string{"DEFAULT_GROUP_MEMBER_ROLE"},
Value: 0,
Value: 1,
}
func NewGroupConfig(cliCtx *cli.Context) (GroupConfig, error) {
@ -44,6 +44,7 @@ func NewGroupConfig(cliCtx *cli.Context) (GroupConfig, error) {
EnableGroups: cliCtx.Bool("enable-groups"),
AllowAutoAcceptGroupFollowers: cliCtx.Bool("allow-auto-accept-group-followers"),
AllowRemoteGroupFollowers: cliCtx.Bool("allow-remote-group-followers"),
DefaultGroupMemberRole: cliCtx.Int("default-group-member-role"),
}
return cfg, nil
}

View File

@ -41,6 +41,9 @@ type GroupStorage interface {
RemoveGroupMember(ctx context.Context, groupActorRowID, memberActorRowID uuid.UUID) error
UpdateGroupMemberRole(ctx context.Context, groupActorRowID, memberActorRowID uuid.UUID, role GroupRole) error
UpdateGroupMemberStatus(ctx context.Context, groupActorRowID, memberActorRowID uuid.UUID, status RelationshipStatus) error
UpdateGroupDefaultRole(ctx context.Context, groupActorRowID uuid.UUID, role GroupRole) error
UpdateGroupAcceptFollowers(ctx context.Context, groupRowID uuid.UUID, acceptFollowers bool) error
UpdateGroupAllowRemote(ctx context.Context, groupRowID uuid.UUID, allowRemote bool) error
}
type Group struct {
@ -63,7 +66,7 @@ type GroupRole int16
const (
// GroupOwner can manage the group.
GroupOwner GroupRole = 3
GroupOwner GroupRole = 2
// GroupMember can post to the group.
GroupMember GroupRole = 1
// GroupViewer can receive group activities, but cannot create group activities.
@ -318,3 +321,21 @@ func (s pgStorage) MinutesSinceGroupBoost(ctx context.Context, groupActorRowID,
query := `SELECT (DATE_PART('day', NOW() - updated_at::timestamp) * 24 + DATE_PART('hour', NOW() - updated_at::timestamp)) * 60 + DATE_PART('minute', NOW() - updated_at::timestamp) FROM group_boosts WHERE group_actor_id = $1 AND object_id = $2`
return s.wrappedSelectInt(errors.WrapGroupBoostQueryFailedError, ctx, query, groupActorRowID, objectRowID)
}
func (s pgStorage) UpdateGroupDefaultRole(ctx context.Context, groupRowID uuid.UUID, role GroupRole) error {
now := s.now()
_, err := s.db.ExecContext(ctx, "UPDATE groups SET default_member_role = $3, updated_at = $2 WHERE id = $1", groupRowID, now, role)
return errors.WrapUserUpdateFailedError(err)
}
func (s pgStorage) UpdateGroupAcceptFollowers(ctx context.Context, groupRowID uuid.UUID, acceptFollowers bool) error {
now := s.now()
_, err := s.db.ExecContext(ctx, "UPDATE groups SET accept_followers = $3, updated_at = $2 WHERE id = $1", groupRowID, now, acceptFollowers)
return errors.WrapUserUpdateFailedError(err)
}
func (s pgStorage) UpdateGroupAllowRemote(ctx context.Context, groupRowID uuid.UUID, allowRemote bool) error {
now := s.now()
_, err := s.db.ExecContext(ctx, "UPDATE groups SET allow_remote = $3, updated_at = $2 WHERE id = $1", groupRowID, now, allowRemote)
return errors.WrapUserUpdateFailedError(err)
}

View File

@ -115,7 +115,20 @@ func (h handler) dashboardGroupsCreate(c *gin.Context) {
return err
}
_, err = tx.RecordGroup(ctx, localUser.ID, actorRowID, name, publicKey, privateKey, name, "")
groupRowID, err := tx.RecordGroup(ctx, localUser.ID, actorRowID, name, publicKey, privateKey, name, "")
if err != nil {
return err
}
err = tx.UpdateGroupAcceptFollowers(ctx, groupRowID, h.groupConfig.AllowAutoAcceptGroupFollowers)
if err != nil {
return err
}
err = tx.UpdateGroupAllowRemote(ctx, groupRowID, h.groupConfig.AllowRemoteGroupFollowers)
if err != nil {
return err
}
err = tx.UpdateGroupDefaultRole(ctx, groupRowID, storage.GroupRole(h.groupConfig.DefaultGroupMemberRole))
if err != nil {
return err
}