Compare commits

..

1 Commits

Author SHA1 Message Date
wpetit 523fcee03b wip: workgroup description 2023-08-31 06:45:04 -06:00
7 changed files with 51 additions and 8 deletions

View File

@ -14,6 +14,7 @@ export function InfoForm({ workgroup, onChange }: InfoFormProps) {
workgroup: { workgroup: {
id: workgroup && workgroup.id ? workgroup.id : '', id: workgroup && workgroup.id ? workgroup.id : '',
name: workgroup && workgroup.name ? workgroup.name : '', name: workgroup && workgroup.name ? workgroup.name : '',
description: workgroup && workgroup.description ? workgroup.description : '',
createdAt: workgroup && workgroup.createdAt ? workgroup.createdAt : null, createdAt: workgroup && workgroup.createdAt ? workgroup.createdAt : null,
closedAt: workgroup && workgroup.closedAt ? workgroup.closedAt : null, closedAt: workgroup && workgroup.closedAt ? workgroup.closedAt : null,
} }
@ -34,6 +35,7 @@ export function InfoForm({ workgroup, onChange }: InfoFormProps) {
workgroup: { workgroup: {
id: workgroup && workgroup.id ? workgroup.id : '', id: workgroup && workgroup.id ? workgroup.id : '',
name: workgroup && workgroup.name ? workgroup.name : '', name: workgroup && workgroup.name ? workgroup.name : '',
description: workgroup && workgroup.description ? workgroup.description : '',
createdAt: workgroup && workgroup.createdAt ? workgroup.createdAt : null, createdAt: workgroup && workgroup.createdAt ? workgroup.createdAt : null,
closedAt: workgroup && workgroup.closedAt ? workgroup.closedAt : null, closedAt: workgroup && workgroup.closedAt ? workgroup.closedAt : null,
} }
@ -76,6 +78,14 @@ export function InfoForm({ workgroup, onChange }: InfoFormProps) {
onChange={onWorkgroupAttrChange.bind(null, "name")} /> onChange={onWorkgroupAttrChange.bind(null, "name")} />
</div> </div>
</div> </div>
<div className="field">
<label className="label">Nom du groupe</label>
<div className="control">
<textarea className="input" value={state.workgroup.description}
disabled={!isAuthorized}
onChange={onWorkgroupAttrChange.bind(null, "description")}></textarea>
</div>
</div>
{ {
state.workgroup.createdAt ? state.workgroup.createdAt ?
<div className="field"> <div className="field">

View File

@ -7,6 +7,7 @@ mutation updateWorkgroup($workgroupId: ID!, $changes: WorkgroupChanges!) {
updateWorkgroup(workgroupId: $workgroupId, changes: $changes) { updateWorkgroup(workgroupId: $workgroupId, changes: $changes) {
id, id,
name, name,
description,
createdAt, createdAt,
closedAt, closedAt,
members { members {
@ -26,6 +27,7 @@ mutation createWorkgroup($changes: WorkgroupChanges!) {
createWorkgroup(changes: $changes) { createWorkgroup(changes: $changes) {
id, id,
name, name,
description,
createdAt, createdAt,
closedAt, closedAt,
members { members {
@ -47,6 +49,7 @@ mutation joinWorkgroup($workgroupId: ID!) {
joinWorkgroup(workgroupId: $workgroupId) { joinWorkgroup(workgroupId: $workgroupId) {
id, id,
name, name,
description,
createdAt, createdAt,
closedAt, closedAt,
members { members {
@ -78,6 +81,7 @@ mutation leaveWorkgroup($workgroupId: ID!) {
leaveWorkgroup(workgroupId: $workgroupId) { leaveWorkgroup(workgroupId: $workgroupId) {
id, id,
name, name,
description,
createdAt, createdAt,
closedAt, closedAt,
members { members {
@ -117,6 +121,7 @@ mutation closeWorkgroup($workgroupId: ID!) {
closeWorkgroup(workgroupId: $workgroupId) { closeWorkgroup(workgroupId: $workgroupId) {
id, id,
name, name,
description,
createdAt, createdAt,
closedAt, closedAt,
members { members {

View File

@ -7,6 +7,7 @@ export const QUERY_WORKGROUP = gql`
workgroups(filter: $filter) { workgroups(filter: $filter) {
id, id,
name, name,
description,
createdAt, createdAt,
closedAt, closedAt,
members { members {

View File

@ -2,6 +2,7 @@ import { User } from "./user";
export interface Workgroup { export interface Workgroup {
id: string id: string
name: string name: string
description: string
createdAt: Date createdAt: Date
closedAt: Date closedAt: Date
members: User[] members: User[]

View File

@ -27,7 +27,8 @@ func applyMigration(ctx context.Context, ctn *service.Container) error {
// Register available migrations // Register available migrations
migr.Register( migr.Register(
m000initialSchema(), m000InitialSchema(),
m001WorkgroupDescription(),
) )
currentVersion, err := migr.CurrentVersion(ctx) currentVersion, err := migr.CurrentVersion(ctx)
@ -84,7 +85,7 @@ var initialModels = []interface{}{
&model.Event{}, &model.Event{},
} }
func m000initialSchema() orm.Migration { func m000InitialSchema() orm.Migration {
return orm.NewDBMigration( return orm.NewDBMigration(
"00_initial_schema", "00_initial_schema",
func(ctx context.Context, tx *gorm.DB) error { func(ctx context.Context, tx *gorm.DB) error {
@ -107,3 +108,23 @@ func m000initialSchema() orm.Migration {
}, },
) )
} }
func m001WorkgroupDescription() orm.Migration {
return orm.NewDBMigration(
"01_workgroup_description",
func(ctx context.Context, tx *gorm.DB) error {
if err := tx.AutoMigrate(&model.Workgroup{}).Error; err != nil {
return errors.WithStack(err)
}
return nil
},
func(ctx context.Context, tx *gorm.DB) error {
if err := tx.Model(&model.Workgroup{}).DropColumn("description").Error; err != nil {
return errors.WithStack(err)
}
return nil
},
)
}

View File

@ -11,6 +11,7 @@ const ObjectTypeWorkgroup = "workgroup"
type Workgroup struct { type Workgroup struct {
gorm.Model gorm.Model
Name *string `json:"name"` Name *string `json:"name"`
Workgroup *string `json:"workgroup"`
ClosedAt time.Time `json:"closedAt"` ClosedAt time.Time `json:"closedAt"`
Members []*User `gorm:"many2many:users_workgroups;association_autoupdate:false"` Members []*User `gorm:"many2many:users_workgroups;association_autoupdate:false"`
} }

View File

@ -68,9 +68,8 @@ func handleLoginCallback(w http.ResponseWriter, r *http.Request) {
db := orm.Must(ctn).DB() db := orm.Must(ctn).DB()
repo := model.NewUserRepository(db) repo := model.NewUserRepository(db)
user, err := repo.CreateOrConnectUser(ctx, claims.Email) user := &model.User{
if err != nil { Email: claims.Email,
panic(errors.Wrap(err, "could not upsert user"))
} }
authorized, err := auth.Authorize(user) authorized, err := auth.Authorize(user)
@ -85,6 +84,11 @@ func handleLoginCallback(w http.ResponseWriter, r *http.Request) {
return return
} }
user, err = repo.CreateOrConnectUser(ctx, claims.Email)
if err != nil {
panic(errors.Wrap(err, "could not upsert user"))
}
if err := session.SaveUserEmail(w, r, claims.Email); err != nil { if err := session.SaveUserEmail(w, r, claims.Email); err != nil {
panic(errors.WithStack(err)) panic(errors.WithStack(err))
} }