mirror of
https://github.com/wassname/talk.git
synced 2026-07-19 11:28:50 +08:00
Moving action metadata to nested object.
This commit is contained in:
@@ -11,8 +11,8 @@ class FlagButton extends Component {
|
||||
state = {
|
||||
showMenu: false,
|
||||
itemType: '',
|
||||
detail: '',
|
||||
description: '',
|
||||
reason: '',
|
||||
note: '',
|
||||
step: 0,
|
||||
posted: false
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class FlagButton extends Component {
|
||||
|
||||
onPopupContinue = () => {
|
||||
const {postAction, addItem, updateItem, flag, id, author_id} = this.props;
|
||||
const {itemType, field, detail, step, description, posted} = this.state;
|
||||
const {itemType, field, reason, step, note, posted} = this.state;
|
||||
|
||||
//Proceed to the next step or close the menu if we've reached the end
|
||||
if (step + 1 >= this.props.getPopupMenu.length) {
|
||||
@@ -38,8 +38,8 @@ class FlagButton extends Component {
|
||||
this.setState({step: step + 1});
|
||||
}
|
||||
|
||||
// If itemType and detail are both set, post the action
|
||||
if (itemType && detail && !posted) {
|
||||
// If itemType and reason are both set, post the action
|
||||
if (itemType && reason && !posted) {
|
||||
// Set the text from the "other" field if it exists.
|
||||
let item_id;
|
||||
switch(itemType) {
|
||||
@@ -52,9 +52,11 @@ class FlagButton extends Component {
|
||||
}
|
||||
const action = {
|
||||
action_type: 'flag',
|
||||
field,
|
||||
detail,
|
||||
description
|
||||
metadata: {
|
||||
field,
|
||||
reason,
|
||||
note
|
||||
}
|
||||
};
|
||||
postAction(item_id, itemType, action)
|
||||
.then((action) => {
|
||||
@@ -69,7 +71,7 @@ class FlagButton extends Component {
|
||||
onPopupOptionClick = (sets) => (e) => {
|
||||
|
||||
// If the "other" option is clicked, show the other textbox
|
||||
if(sets === 'detail' && e.target.value === 'other') {
|
||||
if(sets === 'reason' && e.target.value === 'other') {
|
||||
this.setState({showOther: true});
|
||||
}
|
||||
|
||||
@@ -91,7 +93,7 @@ class FlagButton extends Component {
|
||||
}
|
||||
|
||||
onOtherTextChange = (e) => {
|
||||
this.setState({description: e.target.value});
|
||||
this.setState({note: e.target.value});
|
||||
}
|
||||
|
||||
handleClickOutside () {
|
||||
@@ -140,16 +142,16 @@ class FlagButton extends Component {
|
||||
)
|
||||
}
|
||||
{
|
||||
this.state.detail && <div>
|
||||
<label htmlFor={'description'} className={`${name}-popup-radio-label`}>
|
||||
this.state.reason && <div>
|
||||
<label htmlFor={'note'} className={`${name}-popup-radio-label`}>
|
||||
{lang.t('flag-reason')}
|
||||
</label><br/>
|
||||
<textarea
|
||||
className={`${name}-other-text`}
|
||||
id="description"
|
||||
id="note"
|
||||
rows={4}
|
||||
onChange={this.onOtherTextChange}
|
||||
value={this.state.description}/>
|
||||
value={this.state.note}/>
|
||||
</div>
|
||||
}
|
||||
</form>
|
||||
|
||||
+1
-3
@@ -13,9 +13,7 @@ const ActionSchema = new Schema({
|
||||
item_type: String,
|
||||
item_id: String,
|
||||
user_id: String,
|
||||
field: String, // Used when an action references a particular field of an object. (e.g. a flag on a username or bio)
|
||||
detail: String, // Describes the reason for an action (e.g. 'Username is offensive')
|
||||
description: String, // Describes the reason for the action in more detail (e.g. A description of why the comment is offensive.)
|
||||
metadata: Object, //Holds arbitrary metadata about the action.
|
||||
}, {
|
||||
timestamps: {
|
||||
createdAt: 'created_at',
|
||||
|
||||
+2
-3
@@ -287,13 +287,12 @@ CommentSchema.statics.pushStatus = (id, status, assigned_by = null) => Comment.u
|
||||
* @param {String} action the new action to the comment
|
||||
* @return {Promise}
|
||||
*/
|
||||
CommentSchema.statics.addAction = (item_id, user_id, action_type, field, detail) => Action.insertUserAction({
|
||||
CommentSchema.statics.addAction = (item_id, user_id, action_type, metadata) => Action.insertUserAction({
|
||||
item_id,
|
||||
item_type: 'comments',
|
||||
user_id,
|
||||
action_type,
|
||||
field,
|
||||
detail
|
||||
metadata
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
+2
-3
@@ -611,11 +611,10 @@ UserService.addBio = (id, bio) => (
|
||||
* @param {String} action the new action to the user
|
||||
* @return {Promise}
|
||||
*/
|
||||
UserService.addAction = (item_id, user_id, action_type, field, detail) => Action.insertUserAction({
|
||||
UserService.addAction = (item_id, user_id, action_type, metadata) => Action.insertUserAction({
|
||||
item_id,
|
||||
item_type: 'users',
|
||||
user_id,
|
||||
action_type,
|
||||
field,
|
||||
detail
|
||||
metadata
|
||||
});
|
||||
|
||||
@@ -187,12 +187,11 @@ router.post('/:comment_id/actions', (req, res, next) => {
|
||||
|
||||
const {
|
||||
action_type,
|
||||
field,
|
||||
detail
|
||||
metadata
|
||||
} = req.body;
|
||||
|
||||
Comment
|
||||
.addAction(req.params.comment_id, req.user.id, action_type, field, detail)
|
||||
.addAction(req.params.comment_id, req.user.id, action_type, metadata)
|
||||
.then((action) => {
|
||||
res.status(201).json(action);
|
||||
})
|
||||
|
||||
@@ -161,12 +161,11 @@ router.put('/:user_id/bio', (req, res, next) => {
|
||||
router.post('/:user_id/actions', authorization.needed(), (req, res, next) => {
|
||||
const {
|
||||
action_type,
|
||||
field,
|
||||
detail
|
||||
metadata
|
||||
} = req.body;
|
||||
|
||||
User
|
||||
.addAction(req.params.user_id, req.user.id, action_type, field, detail)
|
||||
.addAction(req.params.user_id, req.user.id, action_type, metadata)
|
||||
.then((action) => {
|
||||
res.status(201).json(action);
|
||||
})
|
||||
|
||||
@@ -440,12 +440,13 @@ describe('/api/v1/comments/:comment_id/actions', () => {
|
||||
return chai.request(app)
|
||||
.post('/api/v1/comments/abc/actions')
|
||||
.set(passport.inject({id: '456', roles: ['admin']}))
|
||||
.send({'action_type': 'flag', 'detail': 'Comment is too awesome.'})
|
||||
.send({'action_type': 'flag', 'metadata': {'reason': 'Comment is too awesome.'}})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
expect(res).to.have.body;
|
||||
expect(res.body).to.have.property('action_type', 'flag');
|
||||
expect(res.body).to.have.property('detail', 'Comment is too awesome.');
|
||||
expect(res.body).to.have.property('metadata')
|
||||
.and.to.deep.equal({'reason': 'Comment is too awesome.'});
|
||||
expect(res.body).to.have.property('item_id', 'abc');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,14 +31,16 @@ describe('/api/v1/users/:user_id/actions', () => {
|
||||
return chai.request(app)
|
||||
.post('/api/v1/users/abc/actions')
|
||||
.set(passport.inject({id: '456', roles: ['admin']}))
|
||||
.send({'action_type': 'flag', 'detail': 'Bio is too awesome.'})
|
||||
.send({'action_type': 'flag', 'metadata': {'reason': 'Bio is too awesome.'}})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
expect(res).to.have.body;
|
||||
expect(res.body).to.have.property('action_type', 'flag');
|
||||
expect(res.body).to.have.property('detail', 'Bio is too awesome.');
|
||||
expect(res.body).to.have.property('metadata')
|
||||
.and.to.deep.equal({'reason': 'Bio is too awesome.'});
|
||||
expect(res.body).to.have.property('item_id', 'abc');
|
||||
});
|
||||
})
|
||||
.catch(err => console.error(err.message));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user