refactor(magefile): update schema generator to use 0644 file permissions
This commit is contained in:
parent
ef2aadefbb
commit
d5d85c5e30
File diff suppressed because it is too large
Load Diff
@ -356,16 +356,22 @@ type NewUserAccount struct {
|
||||
RoleCode string `json:"roleCode"`
|
||||
}
|
||||
|
||||
type NotificationActor struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Type ActorType `json:"type"`
|
||||
Name string `json:"name"`
|
||||
type NotificationCausedBy struct {
|
||||
Fullname string `json:"fullname"`
|
||||
Username string `json:"username"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
}
|
||||
|
||||
type NotificationEntity struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Type EntityType `json:"type"`
|
||||
Name string `json:"name"`
|
||||
type NotificationData struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -758,84 +764,6 @@ func (e ActivityType) MarshalGQL(w io.Writer) {
|
||||
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
|
||||
|
||||
const (
|
||||
|
@ -20,6 +20,61 @@ func (r *notificationResolver) ID(ctx context.Context, obj *db.Notification) (uu
|
||||
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 ¬ificationResolver{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) {
|
||||
logger.New(ctx).WithFields(log.Fields{"notificationID": obj.NotificationID}).Info("fetching entity for notification")
|
||||
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"))
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
|
||||
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
|
||||
}
|
||||
|
||||
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 ¬ificationResolver{r} }
|
||||
|
||||
type notificationResolver struct{ *Resolver }
|
||||
|
@ -315,6 +315,10 @@ func (r *Resolver) Organization() OrganizationResolver { return &organizationRes
|
||||
// Query returns QueryResolver implementation.
|
||||
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 organizationResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
type subscriptionResolver struct{ *Resolver }
|
||||
|
@ -1,36 +1,38 @@
|
||||
extend type Subscription {
|
||||
notificationAdded: Notified!
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
notifications: [Notification!]!
|
||||
}
|
||||
|
||||
enum EntityType {
|
||||
TASK
|
||||
}
|
||||
|
||||
enum ActorType {
|
||||
USER
|
||||
notifications: [Notified!]!
|
||||
}
|
||||
|
||||
enum ActionType {
|
||||
TASK_MEMBER_ADDED
|
||||
}
|
||||
|
||||
type NotificationActor {
|
||||
id: UUID!
|
||||
type: ActorType!
|
||||
name: String!
|
||||
type NotificationData {
|
||||
key: String!
|
||||
value: String!
|
||||
}
|
||||
|
||||
type NotificationEntity {
|
||||
id: UUID!
|
||||
type: EntityType!
|
||||
name: String!
|
||||
type NotificationCausedBy {
|
||||
fullname: String!
|
||||
username: String!
|
||||
id: ID!
|
||||
}
|
||||
|
||||
type Notification {
|
||||
id: ID!
|
||||
entity: NotificationEntity!
|
||||
actionType: ActionType!
|
||||
actor: NotificationActor!
|
||||
read: Boolean!
|
||||
causedBy: NotificationCausedBy!
|
||||
data: [NotificationData!]!
|
||||
createdAt: Time!
|
||||
}
|
||||
|
||||
type Notified {
|
||||
id: ID!
|
||||
notification: Notification!
|
||||
read: Boolean!
|
||||
read_at: Time
|
||||
}
|
||||
|
||||
|
@ -1,36 +1,37 @@
|
||||
extend type Subscription {
|
||||
notificationAdded: Notified!
|
||||
}
|
||||
|
||||
extend type Query {
|
||||
notifications: [Notification!]!
|
||||
}
|
||||
|
||||
enum EntityType {
|
||||
TASK
|
||||
}
|
||||
|
||||
enum ActorType {
|
||||
USER
|
||||
notifications: [Notified!]!
|
||||
}
|
||||
|
||||
enum ActionType {
|
||||
TASK_MEMBER_ADDED
|
||||
}
|
||||
|
||||
type NotificationActor {
|
||||
id: UUID!
|
||||
type: ActorType!
|
||||
name: String!
|
||||
type NotificationData {
|
||||
key: String!
|
||||
value: String!
|
||||
}
|
||||
|
||||
type NotificationEntity {
|
||||
id: UUID!
|
||||
type: EntityType!
|
||||
name: String!
|
||||
type NotificationCausedBy {
|
||||
fullname: String!
|
||||
username: String!
|
||||
id: ID!
|
||||
}
|
||||
|
||||
type Notification {
|
||||
id: ID!
|
||||
entity: NotificationEntity!
|
||||
actionType: ActionType!
|
||||
actor: NotificationActor!
|
||||
read: Boolean!
|
||||
causedBy: NotificationCausedBy!
|
||||
data: [NotificationData!]!
|
||||
createdAt: Time!
|
||||
}
|
||||
|
||||
type Notified {
|
||||
id: ID!
|
||||
notification: Notification!
|
||||
read: Boolean!
|
||||
read_at: Time
|
||||
}
|
||||
|
@ -181,3 +181,4 @@ type DeleteProjectPayload {
|
||||
ok: Boolean!
|
||||
project: Project!
|
||||
}
|
||||
|
||||
|
@ -88,6 +88,7 @@ type Query {
|
||||
}
|
||||
|
||||
|
||||
type Subscription
|
||||
type Mutation
|
||||
|
||||
enum MyTasksStatus {
|
||||
|
@ -415,3 +415,4 @@ input UpdateTaskName {
|
||||
taskID: UUID!
|
||||
name: String!
|
||||
}
|
||||
|
||||
|
@ -6,3 +6,5 @@ type TaskGroup {
|
||||
position: Float!
|
||||
tasks: [Task!]!
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,7 +11,6 @@ type TeamPermission {
|
||||
org: RoleCode!
|
||||
}
|
||||
|
||||
|
||||
extend type Mutation {
|
||||
createTeamMember(input: CreateTeamMember!):
|
||||
CreateTeamMemberPayload! @hasRole(roles: [ADMIN], level: TEAM, type: TEAM)
|
||||
@ -77,3 +76,4 @@ type DeleteTeamPayload {
|
||||
team: Team!
|
||||
projects: [Project!]!
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,6 @@ type InvitedUserAccount {
|
||||
member: MemberList!
|
||||
}
|
||||
|
||||
|
||||
|
||||
extend type Mutation {
|
||||
createUserAccount(input: NewUserAccount!):
|
||||
UserAccount! @hasRole(roles: [ADMIN], level: ORG, type: ORG)
|
||||
@ -116,3 +114,4 @@ type DeleteUserAccountPayload {
|
||||
ok: Boolean!
|
||||
userAccount: UserAccount!
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ func (Backend) Schema() error {
|
||||
}
|
||||
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 {
|
||||
panic(err)
|
||||
|
18
migrations/0066_redesign-notification-table.up.sql
Normal file
18
migrations/0066_redesign-notification-table.up.sql
Normal 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
|
||||
);
|
Loading…
Reference in New Issue
Block a user