refactor(magefile): update schema generator to use 0644 file permissions

This commit is contained in:
Jordan Knott 2021-10-26 14:42:04 -05:00
parent ef2aadefbb
commit d5d85c5e30
14 changed files with 632 additions and 420 deletions

File diff suppressed because it is too large Load Diff

View File

@ -356,16 +356,22 @@ type NewUserAccount struct {
RoleCode string `json:"roleCode"` RoleCode string `json:"roleCode"`
} }
type NotificationActor struct { type NotificationCausedBy struct {
ID uuid.UUID `json:"id"` Fullname string `json:"fullname"`
Type ActorType `json:"type"` Username string `json:"username"`
Name string `json:"name"` ID uuid.UUID `json:"id"`
} }
type NotificationEntity struct { type NotificationData struct {
ID uuid.UUID `json:"id"` Key string `json:"key"`
Type EntityType `json:"type"` Value string `json:"value"`
Name string `json:"name"` }
type Notified struct {
ID uuid.UUID `json:"id"`
Notification *db.Notification `json:"notification"`
Read bool `json:"read"`
ReadAt *time.Time `json:"read_at"`
} }
type OwnedList struct { type OwnedList struct {
@ -758,84 +764,6 @@ func (e ActivityType) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String())) fmt.Fprint(w, strconv.Quote(e.String()))
} }
type ActorType string
const (
ActorTypeUser ActorType = "USER"
)
var AllActorType = []ActorType{
ActorTypeUser,
}
func (e ActorType) IsValid() bool {
switch e {
case ActorTypeUser:
return true
}
return false
}
func (e ActorType) String() string {
return string(e)
}
func (e *ActorType) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = ActorType(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid ActorType", str)
}
return nil
}
func (e ActorType) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}
type EntityType string
const (
EntityTypeTask EntityType = "TASK"
)
var AllEntityType = []EntityType{
EntityTypeTask,
}
func (e EntityType) IsValid() bool {
switch e {
case EntityTypeTask:
return true
}
return false
}
func (e EntityType) String() string {
return string(e)
}
func (e *EntityType) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = EntityType(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid EntityType", str)
}
return nil
}
func (e EntityType) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}
type MyTasksSort string type MyTasksSort string
const ( const (

View File

@ -20,6 +20,61 @@ func (r *notificationResolver) ID(ctx context.Context, obj *db.Notification) (uu
return obj.NotificationID, nil return obj.NotificationID, nil
} }
func (r *notificationResolver) ActionType(ctx context.Context, obj *db.Notification) (ActionType, error) {
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
if err != nil {
return ActionTypeTaskMemberAdded, err
}
actionType := GetActionType(entity.ActionType)
return actionType, nil
}
func (r *notificationResolver) CausedBy(ctx context.Context, obj *db.Notification) (*NotificationCausedBy, error) {
panic(fmt.Errorf("not implemented"))
}
func (r *notificationResolver) Data(ctx context.Context, obj *db.Notification) ([]NotificationData, error) {
panic(fmt.Errorf("not implemented"))
}
func (r *notificationResolver) CreatedAt(ctx context.Context, obj *db.Notification) (*time.Time, error) {
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
if err != nil {
return &time.Time{}, err
}
return &entity.CreatedOn, nil
}
func (r *queryResolver) Notifications(ctx context.Context) ([]Notified, error) {
userID, ok := GetUserID(ctx)
logger.New(ctx).Info("fetching notifications")
if !ok {
return []db.Notification{}, errors.New("user id is missing")
}
notifications, err := r.Repository.GetAllNotificationsForUserID(ctx, userID)
if err == sql.ErrNoRows {
return []db.Notification{}, nil
} else if err != nil {
return []db.Notification{}, err
}
return notifications, nil
}
func (r *subscriptionResolver) NotificationAdded(ctx context.Context) (<-chan *Notified, error) {
panic(fmt.Errorf("not implemented"))
}
// Notification returns NotificationResolver implementation.
func (r *Resolver) Notification() NotificationResolver { return &notificationResolver{r} }
type notificationResolver struct{ *Resolver }
// !!! WARNING !!!
// The code below was going to be deleted when updating resolvers. It has been copied here so you have
// one last chance to move it out of harms way if you want. There are two reasons this happens:
// - When renaming or deleting a resolver the old code will be put in here. You can safely delete
// it when you're done.
// - You have helper methods in this file. Move them out to keep these resolver files clean.
func (r *notificationResolver) Entity(ctx context.Context, obj *db.Notification) (*NotificationEntity, error) { func (r *notificationResolver) Entity(ctx context.Context, obj *db.Notification) (*NotificationEntity, error) {
logger.New(ctx).WithFields(log.Fields{"notificationID": obj.NotificationID}).Info("fetching entity for notification") logger.New(ctx).WithFields(log.Fields{"notificationID": obj.NotificationID}).Info("fetching entity for notification")
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID) entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
@ -40,16 +95,6 @@ func (r *notificationResolver) Entity(ctx context.Context, obj *db.Notification)
panic(fmt.Errorf("not implemented")) panic(fmt.Errorf("not implemented"))
} }
} }
func (r *notificationResolver) ActionType(ctx context.Context, obj *db.Notification) (ActionType, error) {
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
if err != nil {
return ActionTypeTaskMemberAdded, err
}
actionType := GetActionType(entity.ActionType)
return actionType, nil
}
func (r *notificationResolver) Actor(ctx context.Context, obj *db.Notification) (*NotificationActor, error) { func (r *notificationResolver) Actor(ctx context.Context, obj *db.Notification) (*NotificationActor, error) {
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID) entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
if err != nil { if err != nil {
@ -62,31 +107,3 @@ func (r *notificationResolver) Actor(ctx context.Context, obj *db.Notification)
} }
return &NotificationActor{ID: entity.ActorID, Name: user.FullName, Type: ActorTypeUser}, nil return &NotificationActor{ID: entity.ActorID, Name: user.FullName, Type: ActorTypeUser}, nil
} }
func (r *notificationResolver) CreatedAt(ctx context.Context, obj *db.Notification) (*time.Time, error) {
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
if err != nil {
return &time.Time{}, err
}
return &entity.CreatedOn, nil
}
func (r *queryResolver) Notifications(ctx context.Context) ([]db.Notification, error) {
userID, ok := GetUserID(ctx)
logger.New(ctx).Info("fetching notifications")
if !ok {
return []db.Notification{}, errors.New("user id is missing")
}
notifications, err := r.Repository.GetAllNotificationsForUserID(ctx, userID)
if err == sql.ErrNoRows {
return []db.Notification{}, nil
} else if err != nil {
return []db.Notification{}, err
}
return notifications, nil
}
// Notification returns NotificationResolver implementation.
func (r *Resolver) Notification() NotificationResolver { return &notificationResolver{r} }
type notificationResolver struct{ *Resolver }

View File

@ -315,6 +315,10 @@ func (r *Resolver) Organization() OrganizationResolver { return &organizationRes
// Query returns QueryResolver implementation. // Query returns QueryResolver implementation.
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} } func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }
// Subscription returns SubscriptionResolver implementation.
func (r *Resolver) Subscription() SubscriptionResolver { return &subscriptionResolver{r} }
type mutationResolver struct{ *Resolver } type mutationResolver struct{ *Resolver }
type organizationResolver struct{ *Resolver } type organizationResolver struct{ *Resolver }
type queryResolver struct{ *Resolver } type queryResolver struct{ *Resolver }
type subscriptionResolver struct{ *Resolver }

View File

@ -1,36 +1,38 @@
extend type Subscription {
notificationAdded: Notified!
}
extend type Query { extend type Query {
notifications: [Notification!]! notifications: [Notified!]!
}
enum EntityType {
TASK
}
enum ActorType {
USER
} }
enum ActionType { enum ActionType {
TASK_MEMBER_ADDED TASK_MEMBER_ADDED
} }
type NotificationActor { type NotificationData {
id: UUID! key: String!
type: ActorType! value: String!
name: String!
} }
type NotificationEntity { type NotificationCausedBy {
id: UUID! fullname: String!
type: EntityType! username: String!
name: String! id: ID!
} }
type Notification { type Notification {
id: ID! id: ID!
entity: NotificationEntity!
actionType: ActionType! actionType: ActionType!
actor: NotificationActor! causedBy: NotificationCausedBy!
read: Boolean! data: [NotificationData!]!
createdAt: Time! createdAt: Time!
} }
type Notified {
id: ID!
notification: Notification!
read: Boolean!
read_at: Time
}

View File

@ -1,36 +1,37 @@
extend type Subscription {
notificationAdded: Notified!
}
extend type Query { extend type Query {
notifications: [Notification!]! notifications: [Notified!]!
}
enum EntityType {
TASK
}
enum ActorType {
USER
} }
enum ActionType { enum ActionType {
TASK_MEMBER_ADDED TASK_MEMBER_ADDED
} }
type NotificationActor { type NotificationData {
id: UUID! key: String!
type: ActorType! value: String!
name: String!
} }
type NotificationEntity { type NotificationCausedBy {
id: UUID! fullname: String!
type: EntityType! username: String!
name: String! id: ID!
} }
type Notification { type Notification {
id: ID! id: ID!
entity: NotificationEntity!
actionType: ActionType! actionType: ActionType!
actor: NotificationActor! causedBy: NotificationCausedBy!
read: Boolean! data: [NotificationData!]!
createdAt: Time! createdAt: Time!
} }
type Notified {
id: ID!
notification: Notification!
read: Boolean!
read_at: Time
}

View File

@ -181,3 +181,4 @@ type DeleteProjectPayload {
ok: Boolean! ok: Boolean!
project: Project! project: Project!
} }

View File

@ -88,6 +88,7 @@ type Query {
} }
type Subscription
type Mutation type Mutation
enum MyTasksStatus { enum MyTasksStatus {

View File

@ -415,3 +415,4 @@ input UpdateTaskName {
taskID: UUID! taskID: UUID!
name: String! name: String!
} }

View File

@ -6,3 +6,5 @@ type TaskGroup {
position: Float! position: Float!
tasks: [Task!]! tasks: [Task!]!
} }

View File

@ -11,7 +11,6 @@ type TeamPermission {
org: RoleCode! org: RoleCode!
} }
extend type Mutation { extend type Mutation {
createTeamMember(input: CreateTeamMember!): createTeamMember(input: CreateTeamMember!):
CreateTeamMemberPayload! @hasRole(roles: [ADMIN], level: TEAM, type: TEAM) CreateTeamMemberPayload! @hasRole(roles: [ADMIN], level: TEAM, type: TEAM)
@ -77,3 +76,4 @@ type DeleteTeamPayload {
team: Team! team: Team!
projects: [Project!]! projects: [Project!]!
} }

View File

@ -19,8 +19,6 @@ type InvitedUserAccount {
member: MemberList! member: MemberList!
} }
extend type Mutation { extend type Mutation {
createUserAccount(input: NewUserAccount!): createUserAccount(input: NewUserAccount!):
UserAccount! @hasRole(roles: [ADMIN], level: ORG, type: ORG) UserAccount! @hasRole(roles: [ADMIN], level: ORG, type: ORG)
@ -116,3 +114,4 @@ type DeleteUserAccountPayload {
ok: Boolean! ok: Boolean!
userAccount: UserAccount! userAccount: UserAccount!
} }

View File

@ -151,7 +151,7 @@ func (Backend) Schema() error {
} }
fmt.Fprintln(&schema, string(content)) fmt.Fprintln(&schema, string(content))
} }
err = ioutil.WriteFile("internal/graph/schema/"+folder.Name()+".gql", []byte(schema.String()), os.FileMode(0755)) err = ioutil.WriteFile("internal/graph/schema/"+folder.Name()+".gql", []byte(schema.String()), os.FileMode(0644))
} }
if err != nil { if err != nil {
panic(err) panic(err)

View File

@ -0,0 +1,18 @@
DROP TABLE notification_object CASCADE;
DROP TABLE notification CASCADE;
CREATE TABLE notification (
notification_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
actor_id uuid,
action_type int NOT NULL,
data jsonb,
created_on timestamptz NOT NULL
);
CREATE TABLE notification_notified (
notified_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
notification_id uuid REFERENCES notification(notification_id) ON DELETE CASCADE,
user_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE,
read boolean NOT NULL DEFAULT false,
read_at timestamptz
);