mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Make clan name and description editable
This commit is contained in:
parent
bc35a27750
commit
2b29e755fe
6 changed files with 120 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
||||||
c = require './../schemas'
|
c = require './../schemas'
|
||||||
|
|
||||||
|
# TODO: Require name to be non-empty
|
||||||
|
|
||||||
ClanSchema = c.object {title: 'Clan', required: ['name', 'type']}
|
ClanSchema = c.object {title: 'Clan', required: ['name', 'type']}
|
||||||
c.extendNamedProperties ClanSchema # name first
|
c.extendNamedProperties ClanSchema # name first
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,19 @@
|
||||||
width: 240px
|
width: 240px
|
||||||
background: rgba(0, 0, 0, 0.0)
|
background: rgba(0, 0, 0, 0.0)
|
||||||
|
|
||||||
|
#editDescriptionModal .modal-dialog
|
||||||
|
background-color: white
|
||||||
|
|
||||||
|
#editNameModal .modal-dialog
|
||||||
|
background-color: white
|
||||||
|
max-width: 400px
|
||||||
|
|
||||||
|
.edit-description-input
|
||||||
|
width: 100%
|
||||||
|
|
||||||
|
.edit-name-input
|
||||||
|
width: 100%
|
||||||
|
|
||||||
$spriteSheetSize: 30px
|
$spriteSheetSize: 30px
|
||||||
|
|
||||||
td.hero-icon-cell
|
td.hero-icon-cell
|
||||||
|
|
|
@ -2,14 +2,44 @@ extends /templates/base
|
||||||
|
|
||||||
block content
|
block content
|
||||||
|
|
||||||
|
.modal#editNameModal
|
||||||
|
.modal-dialog
|
||||||
|
.modal-header
|
||||||
|
button.close(data-dismiss='modal')
|
||||||
|
span ×
|
||||||
|
h3.modal-title Edit Clan Name
|
||||||
|
.modal-body
|
||||||
|
input.edit-name-input(type='text' value="#{clan.get('name')}")
|
||||||
|
.modal-footer
|
||||||
|
button.btn(data-dismiss='modal') Close
|
||||||
|
button.btn.edit-name-save-btn Save changes
|
||||||
|
|
||||||
|
.modal#editDescriptionModal
|
||||||
|
.modal-dialog
|
||||||
|
.modal-header
|
||||||
|
button.close(data-dismiss='modal')
|
||||||
|
span ×
|
||||||
|
h3.modal-title Edit Clan Description
|
||||||
|
.modal-body
|
||||||
|
textarea.edit-description-input(rows=2)= clan.get('description')
|
||||||
|
.modal-footer
|
||||||
|
button.btn(data-dismiss='modal') Close
|
||||||
|
button.btn.edit-description-save-btn Save changes
|
||||||
|
|
||||||
if clan
|
if clan
|
||||||
h1 #{clan.get('name')}
|
h1 #{clan.get('name')}
|
||||||
if clan.get('type') === 'private'
|
if clan.get('type') === 'private'
|
||||||
small (private)
|
small (private)
|
||||||
|
if clan.get('ownerID') === me.id
|
||||||
|
span.spl
|
||||||
|
button.btn.btn-xs.edit-name-btn(data-toggle='modal', data-target='#editNameModal') edit name
|
||||||
|
|
||||||
if clan.get('description')
|
if clan.get('description')
|
||||||
.clan-description
|
.clan-description
|
||||||
each line in clan.get('description').split('\n')
|
each line in clan.get('description').split('\n')
|
||||||
p= line
|
p= line
|
||||||
|
if clan.get('ownerID') === me.id
|
||||||
|
button.btn.btn-xs.edit-description-btn(data-toggle='modal', data-target='#editDescriptionModal') edit description
|
||||||
|
|
||||||
h5 Summary
|
h5 Summary
|
||||||
table.table.table-condensed.stats-table
|
table.table.table-condensed.stats-table
|
||||||
|
|
|
@ -19,6 +19,8 @@ module.exports = class ClanDetailsView extends RootView
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click .delete-clan-btn': 'onDeleteClan'
|
'click .delete-clan-btn': 'onDeleteClan'
|
||||||
|
'click .edit-description-save-btn': 'onEditDescriptionSave'
|
||||||
|
'click .edit-name-save-btn': 'onEditNameSave'
|
||||||
'click .join-clan-btn': 'onJoinClan'
|
'click .join-clan-btn': 'onJoinClan'
|
||||||
'click .leave-clan-btn': 'onLeaveClan'
|
'click .leave-clan-btn': 'onLeaveClan'
|
||||||
'click .remove-member-btn': 'onRemoveMember'
|
'click .remove-member-btn': 'onRemoveMember'
|
||||||
|
@ -134,6 +136,18 @@ module.exports = class ClanDetailsView extends RootView
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
@supermodel.addRequestResource( 'delete_clan', options).load()
|
@supermodel.addRequestResource( 'delete_clan', options).load()
|
||||||
|
|
||||||
|
onEditDescriptionSave: (e) ->
|
||||||
|
description = $('.edit-description-input').val()
|
||||||
|
@clan.set 'description', description
|
||||||
|
@clan.patch()
|
||||||
|
$('#editDescriptionModal').modal('hide')
|
||||||
|
|
||||||
|
onEditNameSave: (e) ->
|
||||||
|
if name = $('.edit-name-input').val()
|
||||||
|
@clan.set 'name', name
|
||||||
|
@clan.patch()
|
||||||
|
$('#editNameModal').modal('hide')
|
||||||
|
|
||||||
onJoinClan: (e) ->
|
onJoinClan: (e) ->
|
||||||
return @openModalView(new AuthModal()) if me.isAnonymous()
|
return @openModalView(new AuthModal()) if me.isAnonymous()
|
||||||
return unless @clan.loaded
|
return unless @clan.loaded
|
||||||
|
|
|
@ -100,7 +100,7 @@ ClanHandler = class ClanHandler extends Handler
|
||||||
Clan.findById clanID, (err, clan) =>
|
Clan.findById clanID, (err, clan) =>
|
||||||
return @sendDatabaseError(res, err) if err
|
return @sendDatabaseError(res, err) if err
|
||||||
return @sendDatabaseError(res, err) unless clan
|
return @sendDatabaseError(res, err) unless clan
|
||||||
memberIDs = _.map clan.get('members') ? [], (memberID) -> memberID.toHexString()
|
memberIDs = _.map clan.get('members') ? [], (memberID) -> memberID.toHexString?() or memberID
|
||||||
EarnedAchievement.find {user: {$in: memberIDs}}, (err, documents) =>
|
EarnedAchievement.find {user: {$in: memberIDs}}, (err, documents) =>
|
||||||
return @sendDatabaseError(res, err) if err?
|
return @sendDatabaseError(res, err) if err?
|
||||||
cleandocs = (EarnedAchievementHandler.formatEntity(req, doc) for doc in documents)
|
cleandocs = (EarnedAchievementHandler.formatEntity(req, doc) for doc in documents)
|
||||||
|
@ -122,7 +122,7 @@ ClanHandler = class ClanHandler extends Handler
|
||||||
Clan.findById clanID, (err, clan) =>
|
Clan.findById clanID, (err, clan) =>
|
||||||
return @sendDatabaseError(res, err) if err
|
return @sendDatabaseError(res, err) if err
|
||||||
return @sendDatabaseError(res, err) unless clan
|
return @sendDatabaseError(res, err) unless clan
|
||||||
memberIDs = _.map clan.get('members') ? [], (memberID) -> memberID.toHexString()
|
memberIDs = _.map clan.get('members') ? [], (memberID) -> memberID.toHexString?() or memberID
|
||||||
LevelSession.find {creator: {$in: memberIDs}}, (err, documents) =>
|
LevelSession.find {creator: {$in: memberIDs}}, (err, documents) =>
|
||||||
return @sendDatabaseError(res, err) if err?
|
return @sendDatabaseError(res, err) if err?
|
||||||
cleandocs = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
|
cleandocs = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
|
||||||
|
|
|
@ -77,6 +77,64 @@ describe 'Clans', ->
|
||||||
expect(res.statusCode).toBe(422)
|
expect(res.statusCode).toBe(422)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it 'Edit clan name', (done) ->
|
||||||
|
newName = 'new clan name'
|
||||||
|
loginNewUser (user1) ->
|
||||||
|
createClan user1, 'public', 'test description', (clan) ->
|
||||||
|
requestBody = clan.toObject()
|
||||||
|
requestBody.name = newName
|
||||||
|
request.put {uri: clanURL, json: requestBody }, (err, res, body) ->
|
||||||
|
expect(err).toBeNull()
|
||||||
|
expect(body.name).toEqual(newName)
|
||||||
|
Clan.findById clan.id, (err, clan) ->
|
||||||
|
expect(err).toBeNull()
|
||||||
|
expect(clan.get('name')).toEqual(newName)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'Edit clan name, not owner 403', (done) ->
|
||||||
|
loginNewUser (user1) ->
|
||||||
|
createClan user1, 'public', 'test description', (clan) ->
|
||||||
|
oldName = clan.get('name')
|
||||||
|
loginNewUser (user2) ->
|
||||||
|
requestBody = clan.toObject()
|
||||||
|
requestBody.name = 'new clan name'
|
||||||
|
request.put {uri: clanURL, json: requestBody }, (err, res, body) ->
|
||||||
|
expect(err).toBeNull()
|
||||||
|
expect(res.statusCode).toEqual(403)
|
||||||
|
Clan.findById clan.id, (err, clan) ->
|
||||||
|
expect(err).toBeNull()
|
||||||
|
expect(clan.get('name')).toEqual(oldName)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'Edit clan description', (done) ->
|
||||||
|
newDescription = 'new description'
|
||||||
|
loginNewUser (user1) ->
|
||||||
|
createClan user1, 'public', 'test description', (clan) ->
|
||||||
|
requestBody = clan.toObject()
|
||||||
|
requestBody.description = newDescription
|
||||||
|
request.put {uri: clanURL, json: requestBody }, (err, res, body) ->
|
||||||
|
expect(err).toBeNull()
|
||||||
|
expect(body.description).toEqual(newDescription)
|
||||||
|
Clan.findById clan.id, (err, clan) ->
|
||||||
|
expect(err).toBeNull()
|
||||||
|
expect(clan.get('description')).toEqual(newDescription)
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'Edit clan description, not owner 403', (done) ->
|
||||||
|
loginNewUser (user1) ->
|
||||||
|
createClan user1, 'public', 'test description', (clan) ->
|
||||||
|
oldDescription = clan.get('description')
|
||||||
|
loginNewUser (user2) ->
|
||||||
|
requestBody = clan.toObject()
|
||||||
|
requestBody.description = 'new description'
|
||||||
|
request.put {uri: clanURL, json: requestBody }, (err, res, body) ->
|
||||||
|
expect(err).toBeNull()
|
||||||
|
expect(res.statusCode).toEqual(403)
|
||||||
|
Clan.findById clan.id, (err, clan) ->
|
||||||
|
expect(err).toBeNull()
|
||||||
|
expect(clan.get('description')).toEqual(oldDescription)
|
||||||
|
done()
|
||||||
|
|
||||||
it 'Get public clans', (done) ->
|
it 'Get public clans', (done) ->
|
||||||
loginNewUser (user1) ->
|
loginNewUser (user1) ->
|
||||||
createClan user1, 'public', null, (clan1) ->
|
createClan user1, 'public', null, (clan1) ->
|
||||||
|
|
Loading…
Reference in a new issue