mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-02 11:58:10 -05:00
Moved editors from PUT to POST so that version saving behavior is preserved and admins can PUT without saving new versions.
This commit is contained in:
parent
d85bf8d59a
commit
c54fd5ab4b
9 changed files with 35 additions and 36 deletions
|
@ -33,7 +33,7 @@ module.exports = class ForkModal extends ModalView
|
||||||
if @model.schema().properties.permissions
|
if @model.schema().properties.permissions
|
||||||
newModel.set 'permissions', [access: 'owner', target: me.id]
|
newModel.set 'permissions', [access: 'owner', target: me.id]
|
||||||
newPathPrefix = "editor/#{@editorPath}/"
|
newPathPrefix = "editor/#{@editorPath}/"
|
||||||
res = newModel.save()
|
res = newModel.save(null, {type: 'POST'}) # Override PUT so we can trigger postFirstVersion logic
|
||||||
return unless res
|
return unless res
|
||||||
res.error =>
|
res.error =>
|
||||||
@hideLoading()
|
@hideLoading()
|
||||||
|
|
|
@ -83,7 +83,7 @@ module.exports = class ArticleEditView extends RootView
|
||||||
|
|
||||||
newArticle = if e.major then @article.cloneNewMajorVersion() else @article.cloneNewMinorVersion()
|
newArticle = if e.major then @article.cloneNewMajorVersion() else @article.cloneNewMinorVersion()
|
||||||
newArticle.set('commitMessage', e.commitMessage)
|
newArticle.set('commitMessage', e.commitMessage)
|
||||||
res = newArticle.save()
|
res = newArticle.save(null, {type: 'POST'}) # Override PUT so we can trigger postNewVersion logic
|
||||||
return unless res
|
return unless res
|
||||||
modal = @$el.find('#save-version-modal')
|
modal = @$el.find('#save-version-modal')
|
||||||
@enableModalInProgress(modal)
|
@enableModalInProgress(modal)
|
||||||
|
|
|
@ -28,7 +28,7 @@ module.exports = class NewLevelComponentModal extends ModalView
|
||||||
component.set 'name', name
|
component.set 'name', name
|
||||||
component.set 'code', component.get('code', true).replace(/AttacksSelf/g, name)
|
component.set 'code', component.get('code', true).replace(/AttacksSelf/g, name)
|
||||||
component.set 'permissions', [{access: 'owner', target: me.id}] # Private until saved in a published Level
|
component.set 'permissions', [{access: 'owner', target: me.id}] # Private until saved in a published Level
|
||||||
res = component.save()
|
res = component.save(null, {type: 'POST'}) # Override PUT so we can trigger postFirstVersion logic
|
||||||
return unless res
|
return unless res
|
||||||
|
|
||||||
@showLoading()
|
@showLoading()
|
||||||
|
|
|
@ -97,7 +97,7 @@ module.exports = class SaveLevelModal extends SaveVersionModal
|
||||||
tuples = _.zip(modelsToSave, formsToSave)
|
tuples = _.zip(modelsToSave, formsToSave)
|
||||||
for [newModel, form] in tuples
|
for [newModel, form] in tuples
|
||||||
newModel.updateI18NCoverage() if newModel.get('i18nCoverage')
|
newModel.updateI18NCoverage() if newModel.get('i18nCoverage')
|
||||||
res = newModel.save()
|
res = newModel.save(null, {type: 'POST'}) # Override PUT so we can trigger postNewVersion logic
|
||||||
do (newModel, form) =>
|
do (newModel, form) =>
|
||||||
res.error =>
|
res.error =>
|
||||||
@hideLoading()
|
@hideLoading()
|
||||||
|
|
|
@ -22,7 +22,7 @@ module.exports = class NewLevelSystemModal extends ModalView
|
||||||
system.set 'name', name
|
system.set 'name', name
|
||||||
system.set 'code', system.get('code').replace(/Jitter/g, name)
|
system.set 'code', system.get('code').replace(/Jitter/g, name)
|
||||||
system.set 'permissions', [{access: 'owner', target: me.id}] # Private until saved in a published Level
|
system.set 'permissions', [{access: 'owner', target: me.id}] # Private until saved in a published Level
|
||||||
res = system.save()
|
res = system.save(null, {type: 'POST'}) # Override PUT so we can trigger postFirstVersion logic
|
||||||
return unless res
|
return unless res
|
||||||
|
|
||||||
@showLoading()
|
@showLoading()
|
||||||
|
|
|
@ -36,7 +36,7 @@ module.exports = class NewModelModal extends ModalView
|
||||||
onModelSubmitted: (e) ->
|
onModelSubmitted: (e) ->
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
model = @makeNewModel()
|
model = @makeNewModel()
|
||||||
res = model.save()
|
res = model.save(null, {type: 'POST'}) # Override PUT so we can trigger postFirstVersion logic if needed
|
||||||
return unless res
|
return unless res
|
||||||
|
|
||||||
forms.clearFormAlerts @$el
|
forms.clearFormAlerts @$el
|
||||||
|
|
|
@ -367,7 +367,7 @@ module.exports = class ThangTypeEditView extends RootView
|
||||||
newThangType.set('commitMessage', e.commitMessage)
|
newThangType.set('commitMessage', e.commitMessage)
|
||||||
newThangType.updateI18NCoverage() if newThangType.get('i18nCoverage')
|
newThangType.updateI18NCoverage() if newThangType.get('i18nCoverage')
|
||||||
|
|
||||||
res = newThangType.save()
|
res = newThangType.save(null, {type: 'POST'}) # Override PUT so we can trigger postNewVersion logic
|
||||||
return unless res
|
return unless res
|
||||||
modal = $('#save-version-modal')
|
modal = $('#save-version-modal')
|
||||||
@enableModalInProgress(modal)
|
@enableModalInProgress(modal)
|
||||||
|
|
|
@ -160,7 +160,7 @@ module.exports = class I18NEditModelView extends RootView
|
||||||
button = $(e.target)
|
button = $(e.target)
|
||||||
button.attr('disabled', 'disabled')
|
button.attr('disabled', 'disabled')
|
||||||
return button.text('Failed to Submit Changes') if errors
|
return button.text('Failed to Submit Changes') if errors
|
||||||
res = modelToSave.save()
|
res = modelToSave.save(null, {type: 'POST'}) # Override PUT so we can trigger postNewVersion logic
|
||||||
return button.text('Failed to Submit Changes') unless res
|
return button.text('Failed to Submit Changes') unless res
|
||||||
res.error => button.text('Error Submitting Changes')
|
res.error => button.text('Error Submitting Changes')
|
||||||
res.success => button.text('Submit Changes')
|
res.success => button.text('Submit Changes')
|
||||||
|
|
|
@ -34,7 +34,7 @@ module.exports = class Handler
|
||||||
hasAccessToDocument: (req, document, method=null) ->
|
hasAccessToDocument: (req, document, method=null) ->
|
||||||
return true if req.user?.isAdmin()
|
return true if req.user?.isAdmin()
|
||||||
|
|
||||||
if @modelClass.schema.uses_coco_translation_coverage and (method or req.method).toLowerCase() is 'put'
|
if @modelClass.schema.uses_coco_translation_coverage and (method or req.method).toLowerCase() is 'post'
|
||||||
return true if @isJustFillingTranslations(req, document)
|
return true if @isJustFillingTranslations(req, document)
|
||||||
|
|
||||||
if @modelClass.schema.uses_coco_permissions
|
if @modelClass.schema.uses_coco_permissions
|
||||||
|
@ -335,8 +335,7 @@ module.exports = class Handler
|
||||||
put: (req, res, id) ->
|
put: (req, res, id) ->
|
||||||
# Client expects PATCH behavior for PUTs
|
# Client expects PATCH behavior for PUTs
|
||||||
# Real PATCHs return incorrect HTTP responses in some environments (e.g. Browserstack, schools)
|
# Real PATCHs return incorrect HTTP responses in some environments (e.g. Browserstack, schools)
|
||||||
return @postNewVersion(req, res) if @modelClass.schema.uses_coco_versions # Old logic - https://github.com/codecombat/codecombat/commit/0bdec68cfc2997a1d03458e516ecedd7c7f389a9#diff-859d2856438fffa609001ae3b7b74c27R331
|
return @sendForbiddenError(res) if @modelClass.schema.uses_coco_versions and not req.user.isAdmin() # Campaign editor just saves over things.
|
||||||
#return @sendForbiddenError(res) if @modelClass.schema.uses_coco_versions and not req.user.isAdmin() # New logic (from campaign editor) that breaks saving versioned documents, like in the level editor.
|
|
||||||
return @sendBadInputError(res, 'No input.') if _.isEmpty(req.body)
|
return @sendBadInputError(res, 'No input.') if _.isEmpty(req.body)
|
||||||
return @sendForbiddenError(res) unless @hasAccess(req)
|
return @sendForbiddenError(res) unless @hasAccess(req)
|
||||||
@getDocumentForIdOrSlug req.body._id or id, (err, document) =>
|
@getDocumentForIdOrSlug req.body._id or id, (err, document) =>
|
||||||
|
|
Loading…
Reference in a new issue