Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
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
8c918d10
Commit
8c918d10
authored
Nov 09, 2020
by
Antonis Kalou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove do_create/do_update from ResourceSpecification
parent
4f451133
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
91 deletions
+17
-91
lib/extensions/value_flows/knowledge/resource_specification/graphql.ex
...s/value_flows/knowledge/resource_specification/graphql.ex
+2
-56
lib/extensions/value_flows/knowledge/resource_specification/resource_spec.ex
...e_flows/knowledge/resource_specification/resource_spec.ex
+1
-1
lib/extensions/value_flows/knowledge/resource_specification/resource_specs.ex
..._flows/knowledge/resource_specification/resource_specs.ex
+14
-34
No files found.
lib/extensions/value_flows/knowledge/resource_specification/graphql.ex
View file @
8c918d10
...
...
@@ -180,39 +180,6 @@ defmodule ValueFlows.Knowledge.ResourceSpecification.GraphQL do
})
end
def
create_resource_spec
(
%{
resource_specification:
%{
in_scope_of:
context_ids
}
=
resource_spec_attrs
},
info
)
when
is_list
(
context_ids
)
do
# FIXME: support multiple contexts?
context_id
=
List
.
first
(
context_ids
)
create_resource_spec
(
%{
resource_specification:
Map
.
merge
(
resource_spec_attrs
,
%{
in_scope_of:
context_id
})},
info
)
end
def
create_resource_spec
(
%{
resource_specification:
%{
in_scope_of:
context_id
}
=
resource_spec_attrs
},
info
)
when
not
is_nil
(
context_id
)
do
Repo
.
transact_with
(
fn
->
with
{
:ok
,
user
}
<-
GraphQL
.
current_user_or_not_logged_in
(
info
),
{
:ok
,
pointer
}
<-
Pointers
.
one
(
id:
context_id
),
context
=
Pointers
.
follow!
(
pointer
),
{
:ok
,
uploads
}
<-
UploadResolver
.
upload
(
user
,
resource_spec_attrs
,
info
),
resource_spec_attrs
=
Map
.
merge
(
resource_spec_attrs
,
uploads
),
resource_spec_attrs
=
Map
.
merge
(
resource_spec_attrs
,
%{
is_public:
true
}),
{
:ok
,
resource_spec
}
<-
ResourceSpecifications
.
create
(
user
,
context
,
resource_spec_attrs
)
do
{
:ok
,
%{
resource_specification:
resource_spec
}}
end
end
)
end
# FIXME: duplication!
def
create_resource_spec
(%{
resource_specification:
resource_spec_attrs
},
info
)
do
Repo
.
transact_with
(
fn
->
...
...
@@ -226,34 +193,13 @@ defmodule ValueFlows.Knowledge.ResourceSpecification.GraphQL do
end
)
end
def
update_resource_spec
(%{
resource_specification:
%{
in_scope_of:
context_ids
}
=
changes
},
info
)
do
context_id
=
List
.
first
(
context_ids
)
Repo
.
transact_with
(
fn
->
do_update
(
changes
,
info
,
fn
resource_spec
,
changes
->
with
{
:ok
,
pointer
}
<-
Pointers
.
one
(
id:
context_id
)
do
context
=
Pointers
.
follow!
(
pointer
)
ResourceSpecifications
.
update
(
resource_spec
,
context
,
changes
)
end
end
)
end
)
end
def
update_resource_spec
(%{
resource_specification:
changes
},
info
)
do
Repo
.
transact_with
(
fn
->
do_update
(
changes
,
info
,
fn
resource_spec
,
changes
->
ResourceSpecifications
.
update
(
resource_spec
,
changes
)
end
)
end
)
end
defp
do_update
(%{
id:
id
}
=
changes
,
info
,
update_fn
)
do
def
update_resource_spec
(%{
resource_specification:
%{
id:
id
}
=
changes
},
info
)
do
with
{
:ok
,
user
}
<-
GraphQL
.
current_user_or_not_logged_in
(
info
),
{
:ok
,
resource_spec
}
<-
resource_spec
(%{
id:
id
},
info
),
:ok
<-
ensure_update_permission
(
user
,
resource_spec
),
{
:ok
,
uploads
}
<-
UploadResolver
.
upload
(
user
,
changes
,
info
),
changes
=
Map
.
merge
(
changes
,
uploads
),
{
:ok
,
resource_spec
}
<-
update_fn
.
(
resource_spec
,
changes
)
do
{
:ok
,
resource_spec
}
<-
ResourceSpecifications
.
update
(
resource_spec
,
changes
)
do
{
:ok
,
%{
resource_specification:
resource_spec
}}
end
end
...
...
lib/extensions/value_flows/knowledge/resource_specification/resource_spec.ex
View file @
8c918d10
...
...
@@ -50,7 +50,7 @@ defmodule ValueFlows.Knowledge.ResourceSpecification do
end
@required
~w(name is_public)a
@cast
@required
++
~w(note is_disabled image_id)a
@cast
@required
++
~w(note is_disabled
context_id
image_id)a
def
create_changeset
(
%
User
{}
=
creator
,
...
...
lib/extensions/value_flows/knowledge/resource_specification/resource_specs.ex
View file @
8c918d10
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
ValueFlows
.
Knowledge
.
ResourceSpecification
.
ResourceSpecifications
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 Measurement.Measure
alias
ValueFlows
.
Knowledge
.
ResourceSpecification
alias
ValueFlows
.
Knowledge
.
ResourceSpecification
.
Queries
# alias ValueFlows.Knowledge.Action
# alias ValueFlows.Knowledge.Action.Actions
def
cursor
(),
do
:
&
[
&1
.
id
]
def
test_cursor
(),
do
:
&
[
&1
[
"id"
]]
...
...
@@ -86,26 +84,12 @@ defmodule ValueFlows.Knowledge.ResourceSpecification.ResourceSpecifications do
## mutations
# @spec create(User.t(), Community.t(), attrs :: map) :: {:ok, ResourceSpecification.t()} | {:error, Changeset.t()}
def
create
(%
User
{}
=
creator
,
%{
id:
_id
}
=
context
,
attrs
)
when
is_map
(
attrs
)
do
do_create
(
creator
,
attrs
,
fn
->
ResourceSpecification
.
create_changeset
(
creator
,
context
,
attrs
)
end
)
end
# @spec create(User.t(), attrs :: map) :: {:ok, ResourceSpecification.t()} | {:error, Changeset.t()}
@spec
create
(
User
.
t
(),
attrs
::
map
)
::
{
:ok
,
ResourceSpecification
.
t
()}
|
{
:error
,
Changeset
.
t
()}
def
create
(%
User
{}
=
creator
,
attrs
)
when
is_map
(
attrs
)
do
do_create
(
creator
,
attrs
,
fn
->
ResourceSpecification
.
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
,
item
}
<-
Repo
.
insert
(
cs
),
with
{
:ok
,
item
}
<-
Repo
.
insert
(
ResourceSpecification
.
create_changeset
(
creator
,
attrs
)
),
{
:ok
,
item
}
<-
ValueFlows
.
Util
.
try_tag_thing
(
creator
,
item
,
attrs
),
act_attrs
=
%{
verb:
"created"
,
is_local:
true
},
# FIXME
...
...
@@ -166,25 +150,14 @@ defmodule ValueFlows.Knowledge.ResourceSpecification.ResourceSpecifications do
# TODO: take the user who is performing the update
# @spec update(%ResourceSpecification{}, attrs :: map) :: {:ok, ResourceSpecification.t()} | {:error, Changeset.t()}
def
update
(%
ResourceSpecification
{}
=
resource_spec
,
attrs
)
do
do_update
(
resource_spec
,
attrs
,
&
ResourceSpecification
.
update_changeset
(
&1
,
attrs
))
end
def
update
(%
ResourceSpecification
{}
=
resource_spec
,
%{
id:
_id
}
=
context
,
attrs
)
do
do_update
(
resource_spec
,
attrs
,
&
ResourceSpecification
.
update_changeset
(
&1
,
context
,
attrs
))
end
def
do_update
(
resource_spec
,
attrs
,
changeset_fn
)
do
Repo
.
transact_with
(
fn
->
resource_spec
=
Repo
.
preload
(
resource_spec
,
[
:default_unit_of_effort
])
cs
=
resource_spec
|>
changeset_fn
.
()
with
{
:ok
,
resource_spec
}
<-
Repo
.
update
(
cs
),
attrs
=
prepare_attrs
(
attrs
)
with
{
:ok
,
resource_spec
}
<-
Repo
.
update
(
ResourceSpecification
.
update_changeset
(
resource_spec
,
attrs
)),
{
:ok
,
resource_spec
}
<-
ValueFlows
.
Util
.
try_tag_thing
(
nil
,
resource_spec
,
attrs
)
do
publish
(
resource_spec
,
:updated
)
{
:ok
,
resource_spec
}
...
...
@@ -226,4 +199,11 @@ defmodule ValueFlows.Knowledge.ResourceSpecification.ResourceSpecifications do
:ok
end
defp
prepare_attrs
(
attrs
)
do
attrs
|>
maybe_put
(
:context_id
,
attrs
|>
Map
.
get
(
:in_scope_of
)
|>
CommonsPub
.
Common
.
maybe
(
&
List
.
first
/
1
)
)
end
end
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