Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
c321f1d4
Commit
c321f1d4
authored
2 years ago
by
Ron Lucke
Committed by
Elmar Ludwig
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix #2101
Closes #2101 Merge request
studip/studip!1357
parent
fa07240b
No related branches found
No related tags found
1 merge request
!4
Draft: Icon creation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/classes/JsonApi/Routes/Courseware/Authority.php
+5
-2
5 additions, 2 deletions
lib/classes/JsonApi/Routes/Courseware/Authority.php
lib/classes/JsonApi/Routes/Courseware/UnitsCreate.php
+27
-24
27 additions, 24 deletions
lib/classes/JsonApi/Routes/Courseware/UnitsCreate.php
with
32 additions
and
26 deletions
lib/classes/JsonApi/Routes/Courseware/Authority.php
+
5
−
2
View file @
c321f1d4
...
@@ -484,9 +484,12 @@ class Authority
...
@@ -484,9 +484,12 @@ class Authority
return
$GLOBALS
[
'perm'
]
->
have_perm
(
'root'
,
$user
->
id
);
return
$GLOBALS
[
'perm'
]
->
have_perm
(
'root'
,
$user
->
id
);
}
}
public
static
function
canCreateUnit
(
User
$user
):
bool
public
static
function
canCreateUnit
(
User
$user
,
\Range
$range
)
:
bool
{
{
return
$GLOBALS
[
'perm'
]
->
have_perm
(
'tutor'
,
$user
->
id
);
if
(
$user
->
id
===
$range
->
id
)
{
return
true
;
}
return
$GLOBALS
[
'perm'
]
->
have_studip_perm
(
'tutor'
,
$range
->
id
,
$user
->
id
);
}
}
public
static
function
canUpdateUnit
(
User
$user
,
Unit
$resource
):
bool
public
static
function
canUpdateUnit
(
User
$user
,
Unit
$resource
):
bool
...
...
This diff is collapsed.
Click to expand it.
lib/classes/JsonApi/Routes/Courseware/UnitsCreate.php
+
27
−
24
View file @
c321f1d4
...
@@ -24,10 +24,15 @@ class UnitsCreate extends JsonApiController
...
@@ -24,10 +24,15 @@ class UnitsCreate extends JsonApiController
{
{
$json
=
$this
->
validate
(
$request
);
$json
=
$this
->
validate
(
$request
);
$user
=
$this
->
getUser
(
$request
);
$user
=
$this
->
getUser
(
$request
);
if
(
!
Authority
::
canCreateUnit
(
$user
))
{
$range
=
$this
->
getRange
(
$json
);
if
(
!
$range
)
{
throw
new
RecordNotFoundException
();
}
if
(
!
Authority
::
canCreateUnit
(
$user
,
$range
))
{
throw
new
AuthorizationFailedException
();
throw
new
AuthorizationFailedException
();
}
}
$struct
=
$this
->
createUnit
(
$user
,
$json
);
$struct
=
$this
->
createUnit
(
$user
,
$range
,
$json
);
return
$this
->
getCreatedResponse
(
$struct
);
return
$this
->
getCreatedResponse
(
$struct
);
}
}
...
@@ -57,31 +62,33 @@ class UnitsCreate extends JsonApiController
...
@@ -57,31 +62,33 @@ class UnitsCreate extends JsonApiController
}
}
}
}
private
function
validate
Range
(
$json
):
bool
private
function
get
Range
(
$json
):
?
\Range
{
{
$rangeData
=
self
::
arrayGet
(
$json
,
'data.relationships.range.data'
);
$rangeData
=
self
::
arrayGet
(
$json
,
'data.relationships.range.data'
);
if
(
!
in_array
(
$rangeData
[
'type'
],
[
'courses'
,
'users'
]))
{
try
{
return
false
;
return
\RangeFactory
::
createRange
(
}
$this
->
getRangeType
(
$rangeData
[
'type'
]),
if
(
$rangeData
[
'
type'
]
===
'courses'
)
{
$rangeData
[
'
id'
]
$range
=
\Course
::
find
(
$rangeData
[
'id'
]
);
);
}
else
{
}
catch
(
\Exception
$e
)
{
$range
=
\User
::
find
(
$rangeData
[
'id'
])
;
return
null
;
}
}
}
private
function
validateRange
(
$json
):
bool
{
$range
=
$this
->
getRange
(
$json
);
return
isset
(
$range
);
return
isset
(
$range
);
}
}
private
function
createUnit
(
\User
$user
,
array
$json
)
private
function
createUnit
(
\User
$user
,
\Range
$range
,
array
$json
)
{
{
$range_id
=
self
::
arrayGet
(
$json
,
'data.relationships.range.data.id'
);
$struct
=
\Courseware\StructuralElement
::
create
([
$range_type
=
self
::
getRangeType
(
self
::
arrayGet
(
$json
,
'data.relationships.range.data.type'
));
$struct
=
\Courseware\StructuralElement
::
build
([
'parent_id'
=>
null
,
'parent_id'
=>
null
,
'range_id'
=>
$range
_id
,
'range_id'
=>
$range
->
getRangeId
()
,
'range_type'
=>
$range
_t
ype
,
'range_type'
=>
$range
->
getRangeT
ype
()
,
'owner_id'
=>
$user
->
id
,
'owner_id'
=>
$user
->
id
,
'editor_id'
=>
$user
->
id
,
'editor_id'
=>
$user
->
id
,
'edit_blocker_id'
=>
''
,
'edit_blocker_id'
=>
''
,
...
@@ -91,11 +98,9 @@ class UnitsCreate extends JsonApiController
...
@@ -91,11 +98,9 @@ class UnitsCreate extends JsonApiController
'position'
=>
0
'position'
=>
0
]);
]);
$struct
->
store
();
$unit
=
\Courseware\Unit
::
create
([
'range_id'
=>
$range
->
getRangeId
(),
$unit
=
\Courseware\Unit
::
build
([
'range_type'
=>
$range
->
getRangeType
(),
'range_id'
=>
$range_id
,
'range_type'
=>
$range_type
,
'structural_element_id'
=>
$struct
->
id
,
'structural_element_id'
=>
$struct
->
id
,
'content_type'
=>
'courseware'
,
'content_type'
=>
'courseware'
,
'creator_id'
=>
$user
->
id
,
'creator_id'
=>
$user
->
id
,
...
@@ -104,8 +109,6 @@ class UnitsCreate extends JsonApiController
...
@@ -104,8 +109,6 @@ class UnitsCreate extends JsonApiController
'withdraw_date'
=>
self
::
arrayGet
(
$json
,
'data.attributes.withdraw-date'
),
'withdraw_date'
=>
self
::
arrayGet
(
$json
,
'data.attributes.withdraw-date'
),
]);
]);
$unit
->
store
();
return
$unit
;
return
$unit
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment