Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
C
CommonsPub Federated Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
10
Issues
10
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bonfire
CommonsPub Federated Server
Commits
08ccdf4e
Commit
08ccdf4e
authored
Nov 10, 2020
by
Antonis Kalou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup ValueFlows.Observation.Process
parent
e45cb329
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
83 deletions
+37
-83
lib/extensions/value_flows/observation/process/graphql.ex
lib/extensions/value_flows/observation/process/graphql.ex
+2
-11
lib/extensions/value_flows/observation/process/process.ex
lib/extensions/value_flows/observation/process/process.ex
+1
-19
lib/extensions/value_flows/observation/process/processes.ex
lib/extensions/value_flows/observation/process/processes.ex
+22
-34
lib/extensions/value_flows/observation/process/queries.ex
lib/extensions/value_flows/observation/process/queries.ex
+6
-14
test/value_flows/observation/process/processes_test.exs
test/value_flows/observation/process/processes_test.exs
+6
-5
No files found.
lib/extensions/value_flows/observation/process/graphql.ex
View file @
08ccdf4e
...
...
@@ -235,7 +235,6 @@ defmodule ValueFlows.Observation.Process.GraphQL do
})
end
# FIXME: duplication!
def
create_process
(%{
process:
process_attrs
},
info
)
do
Repo
.
transact_with
(
fn
->
with
{
:ok
,
user
}
<-
GraphQL
.
current_user_or_not_logged_in
(
info
),
...
...
@@ -248,21 +247,13 @@ defmodule ValueFlows.Observation.Process.GraphQL do
end
)
end
def
update_process
(%{
process:
changes
},
info
)
do
Repo
.
transact_with
(
fn
->
do_update
(
changes
,
info
,
fn
process
,
changes
->
Processes
.
update
(
process
,
changes
)
end
)
end
)
end
defp
do_update
(%{
id:
id
}
=
changes
,
info
,
update_fn
)
do
def
update_process
(%{
process:
%{
id:
id
}
=
changes
},
info
)
do
with
{
:ok
,
user
}
<-
GraphQL
.
current_user_or_not_logged_in
(
info
),
{
:ok
,
process
}
<-
process
(%{
id:
id
},
info
),
:ok
<-
ensure_update_permission
(
user
,
process
),
{
:ok
,
uploads
}
<-
UploadResolver
.
upload
(
user
,
changes
,
info
),
changes
=
Map
.
merge
(
changes
,
uploads
),
{
:ok
,
process
}
<-
update_fn
.
(
process
,
changes
)
do
{
:ok
,
process
}
<-
Processes
.
update
(
process
,
changes
)
do
{
:ok
,
%{
process:
process
}}
end
end
...
...
lib/extensions/value_flows/observation/process/process.ex
View file @
08ccdf4e
...
...
@@ -77,24 +77,7 @@ defmodule ValueFlows.Observation.Process do
end
@required
~w(name is_public)a
@cast
@required
++
~w(note has_beginning has_end finished is_disabled)a
def
create_changeset
(
%
User
{}
=
creator
,
%{
id:
_
}
=
context
,
attrs
)
do
%
Process
{}
|>
Changeset
.
cast
(
attrs
,
@cast
)
|>
Changeset
.
validate_required
(
@required
)
|>
Changeset
.
change
(
creator_id:
creator
.
id
,
context_id:
context
.
id
,
is_public:
true
)
|>
common_changeset
()
end
@cast
@required
++
~w(note has_beginning has_end finished is_disabled context_id based_on_id)a
def
create_changeset
(
%
User
{}
=
creator
,
...
...
@@ -122,7 +105,6 @@ defmodule ValueFlows.Observation.Process do
|>
change_disabled
()
end
def
context_module
,
do
:
ValueFlows
.
Observation
.
Process
.
Processes
def
queries_module
,
do
:
ValueFlows
.
Observation
.
Process
.
Queries
...
...
lib/extensions/value_flows/observation/process/processes.ex
View file @
08ccdf4e
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
ValueFlows
.
Observation
.
Process
.
Processes
do
import
CommonsPub
.
Common
,
only:
[
maybe_put:
3
]
alias
CommonsPub
.
{
Activities
,
Common
,
Feeds
,
Repo
}
alias
CommonsPub
.
GraphQL
.
{
Fields
,
Page
}
alias
CommonsPub
.
Contexts
alias
CommonsPub
.
Feeds
.
FeedActivities
alias
CommonsPub
.
Users
.
User
# alias CommonsPub.Meta.Pointers
# alias Geolocation.Geolocations
# alias Measurement.Measure
alias
ValueFlows
.
Observation
.
Process
alias
ValueFlows
.
Observation
.
Process
.
Queries
alias
ValueFlows
.
Observation
.
EconomicEvent
.
EconomicEvents
...
...
@@ -108,35 +107,27 @@ defmodule ValueFlows.Observation.Process.Processes do
{
:ok
,
nil
}
end
## mutations
def
create
(%
User
{}
=
creator
,
%{
id:
_id
}
=
context
,
attrs
)
when
is_map
(
attrs
)
do
do_create
(
creator
,
attrs
,
fn
->
Process
.
create_changeset
(
creator
,
context
,
attrs
)
end
)
def
preload_all
(%
Process
{}
=
process
)
do
# shouldn't fail
{
:ok
,
process
}
=
one
(
id:
process
.
id
,
preload:
:all
)
process
end
## mutations
# @spec create(User.t(), attrs :: map) :: {:ok, Process.t()} | {:error, Changeset.t()}
def
create
(%
User
{}
=
creator
,
attrs
)
when
is_map
(
attrs
)
do
do_create
(
creator
,
attrs
,
fn
->
Process
.
create_changeset
(
creator
,
attrs
)
end
)
end
def
do_create
(
creator
,
attrs
,
changeset_fn
)
do
Repo
.
transact_with
(
fn
->
cs
=
changeset_fn
.
(
)
attrs
=
prepare_attrs
(
attrs
)
with
{
:ok
,
process
}
<-
Repo
.
insert
(
cs
),
with
{
:ok
,
process
}
<-
Repo
.
insert
(
Process
.
create_changeset
(
creator
,
attrs
)
),
{
:ok
,
process
}
<-
ValueFlows
.
Util
.
try_tag_thing
(
creator
,
process
,
attrs
),
act_attrs
=
%{
verb:
"created"
,
is_local:
true
},
# FIXME
{
:ok
,
activity
}
<-
Activities
.
create
(
creator
,
process
,
act_attrs
),
:ok
<-
publish
(
creator
,
process
,
activity
,
:created
)
do
process
=
%{
process
|
creator:
creator
}
index
(
process
)
{
:ok
,
pr
ocess
}
{
:ok
,
pr
eload_all
(
process
)
}
end
end
)
end
...
...
@@ -189,24 +180,13 @@ defmodule ValueFlows.Observation.Process.Processes do
# TODO: take the user who is performing the update
# @spec update(%Process{}, attrs :: map) :: {:ok, Process.t()} | {:error, Changeset.t()}
def
update
(%
Process
{}
=
process
,
attrs
)
do
do_update
(
process
,
attrs
,
&
Process
.
update_changeset
(
&1
,
attrs
))
end
def
do_update
(
process
,
attrs
,
changeset_fn
)
do
Repo
.
transact_with
(
fn
->
process
=
Repo
.
preload
(
process
,
[
:based_on
])
cs
=
process
|>
changeset_fn
.
()
attrs
=
prepare_attrs
(
attrs
)
with
{
:ok
,
process
}
<-
Repo
.
update
(
cs
),
with
{
:ok
,
process
}
<-
Repo
.
update
(
Process
.
update_changeset
(
process
,
attrs
)
),
{
:ok
,
process
}
<-
ValueFlows
.
Util
.
try_tag_thing
(
nil
,
process
,
attrs
),
:ok
<-
publish
(
process
,
:updated
)
do
{
:ok
,
pr
ocess
}
{
:ok
,
pr
eload_all
(
process
)
}
end
end
)
end
...
...
@@ -242,4 +222,12 @@ defmodule ValueFlows.Observation.Process.Processes do
:ok
end
defp
prepare_attrs
(
attrs
)
do
attrs
|>
maybe_put
(
:based_on_id
,
Map
.
get
(
attrs
,
:based_on
))
|>
maybe_put
(
:context_id
,
attrs
|>
Map
.
get
(
:in_scope_of
)
|>
CommonsPub
.
Common
.
maybe
(
&
List
.
first
/
1
)
)
end
end
lib/extensions/value_flows/observation/process/queries.ex
View file @
08ccdf4e
...
...
@@ -241,20 +241,12 @@ defmodule ValueFlows.Observation.Process.Queries do
select
(
q
,
[
process:
c
],
{
field
(
c
,
^
key
),
count
(
c
.
id
)})
end
def
filter
(
q
,
{
:preload
,
:provider
})
do
preload
(
q
,
[
pointer:
p
],
provider:
p
)
end
def
filter
(
q
,
{
:preload
,
:receiver
})
do
preload
(
q
,
[
pointer:
p
],
receiver:
p
)
end
def
filter
(
q
,
{
:preload
,
:at_location
})
do
q
|>
join_to
(
:geolocation
)
|>
preload
(
:at_location
)
# preload(q, [geolocation: g], at_location: g)
def
filter
(
q
,
{
:preload
,
:all
})
do
preload
(
q
,
[
:based_on
,
:creator
,
:context
])
end
# pagination
...
...
test/value_flows/observation/process/processes_test.exs
View file @
08ccdf4e
...
...
@@ -132,17 +132,18 @@ defmodule ValueFlows.Observation.Process.ProcessesTest do
test
"can create a process"
do
user
=
fake_user!
()
assert
{
:ok
,
spec
}
=
Processes
.
create
(
user
,
process
())
assert_process
(
spec
)
assert
{
:ok
,
process
}
=
Processes
.
create
(
user
,
process
())
assert_process
(
process
)
end
test
"can create a process with context"
do
user
=
fake_user!
()
parent
=
fake_user!
()
assert
{
:ok
,
spec
}
=
Processes
.
create
(
user
,
parent
,
process
())
assert_process
(
spec
)
assert
spec
.
context_id
==
parent
.
id
attrs
=
%{
in_scope_of:
[
parent
.
id
]}
assert
{
:ok
,
process
}
=
Processes
.
create
(
user
,
process
(
attrs
))
assert_process
(
process
)
assert
process
.
context
.
id
==
parent
.
id
end
test
"can create a process with tags"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment