add summary field to challenges and guilds (#8960)

* create new summary field for challenges

* finish implementating summary for challenges, add some support for guilds

* make small improvements to challenges code

* fix lint errors

* add more code to support summaries for guilds (still more needed)

* fix existing tests by adding summary field

* make existing tests pass

* WIP make "Public Challenges" text translatable

* change "leader" locale key to "guildOrPartyLeader" to make searches for it easier

* remove v-once from h2 headings

* remove failed attempt to localise text in <script>

* add quick-and-dirty error checking for guild not having categories

* make "Public Challenges" text translatable

* rename final ...PlaceHolder strings to ...Placeholder (lower-case "h") for consistency with existing Placeholder strings
This commit is contained in:
Alys
2017-08-23 06:39:45 +10:00
committed by GitHub
parent bd46e3e195
commit 7d0ab1ba25
14 changed files with 199 additions and 92 deletions

View File

@@ -18,9 +18,13 @@ import { syncableAttrs } from '../libs/taskManager';
const Schema = mongoose.Schema;
const MIN_SHORTNAME_SIZE_FOR_CHALLENGES = shared.constants.MIN_SHORTNAME_SIZE_FOR_CHALLENGES;
const MAX_SUMMARY_SIZE_FOR_CHALLENGES = shared.constants.MAX_SUMMARY_SIZE_FOR_CHALLENGES;
let schema = new Schema({
name: {type: String, required: true},
shortName: {type: String, required: true, minlength: 3},
shortName: {type: String, required: true, minlength: MIN_SHORTNAME_SIZE_FOR_CHALLENGES},
summary: {type: String, maxlength: MAX_SUMMARY_SIZE_FOR_CHALLENGES},
description: String,
official: {type: Boolean, default: false},
tasksOrder: {
@@ -43,6 +47,18 @@ schema.plugin(baseModel, {
timestamps: true,
});
schema.pre('init', function ensureSummaryIsFetched (next, chal) {
// The Vue website makes the summary be mandatory for all new challenges, but the
// Angular website did not, and the API does not yet for backwards-compatibilty.
// When any challenge without a summary is fetched from the database, this code
// supplies the name as the summary. This can be removed when all challenges have
// a summary and the API makes it mandatory (a breaking change!)
if (!chal.summary) {
chal.summary = chal.name ? chal.name.substring(0, MAX_SUMMARY_SIZE_FOR_CHALLENGES) : ' ';
}
next();
});
// A list of additional fields that cannot be updated (but can be set on creation)
let noUpdate = ['group', 'official', 'shortName', 'prize'];
schema.statics.sanitizeUpdate = function sanitizeUpdate (updateObj) {
@@ -91,6 +107,7 @@ schema.methods.syncToUser = async function syncChallengeToUser (user) {
if (i !== -1) {
if (userTags[i].name !== challenge.shortName) {
// update the name - it's been changed since
// @TODO: We probably want to remove this. Owner is not allowed to change participant's copy of the tag.
userTags[i].name = challenge.shortName;
}
} else {

View File

@@ -40,6 +40,7 @@ export const TAVERN_ID = shared.TAVERN_ID;
const NO_CHAT_NOTIFICATIONS = [TAVERN_ID];
const LARGE_GROUP_COUNT_MESSAGE_CUTOFF = shared.constants.LARGE_GROUP_COUNT_MESSAGE_CUTOFF;
const MAX_SUMMARY_SIZE_FOR_GUILDS = shared.constants.MAX_SUMMARY_SIZE_FOR_GUILDS;
const GUILDS_PER_PAGE = shared.constants.GUILDS_PER_PAGE;
const CRON_SAFE_MODE = nconf.get('CRON_SAFE_MODE') === 'true';
@@ -58,6 +59,7 @@ export const SPAM_MIN_EXEMPT_CONTRIB_LEVEL = 4;
export let schema = new Schema({
name: {type: String, required: true},
summary: {type: String, maxlength: MAX_SUMMARY_SIZE_FOR_GUILDS},
description: String,
leader: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.'], required: true},
type: {type: String, enum: ['guild', 'party'], required: true},
@@ -137,6 +139,24 @@ schema.plugin(baseModel, {
},
});
schema.pre('init', function ensureSummaryIsFetched (next, group) {
// The Vue website makes the summary be mandatory for all new groups, but the
// Angular website did not, and the API does not yet for backwards-compatibilty.
// When any public guild without a summary is fetched from the database, this code
// supplies the name as the summary. This can be removed when all public guilds have
// a summary and the API makes it mandatory (a breaking change!)
// NOTE: these groups do NOT need summaries: Tavern, private guilds, parties
// ALSO NOTE: it's possible for a private guild to become public and vice versa when
// a guild owner requests it of an admin so that must be taken into account
// when making the summary mandatory - process for changing privacy:
// http://habitica.wikia.com/wiki/Guilds#Changing_a_Guild_from_Private_to_Public_or_Public_to_Private
// Maybe because of that we'd want to keep this code here forever. @TODO: think about that.
if (!group.summary) {
group.summary = group.name ? group.name.substring(0, MAX_SUMMARY_SIZE_FOR_GUILDS) : ' ';
}
next();
});
// A list of additional fields that cannot be updated (but can be set on creation)
let noUpdate = ['privacy', 'type'];
schema.statics.sanitizeUpdate = function sanitizeUpdate (updateObj) {
@@ -319,7 +339,7 @@ schema.statics.toJSONCleanChat = function groupToJSONCleanChat (group, user) {
};
/**
* Checks inivtation uuids and emails for possible errors.
* Checks invitation uuids and emails for possible errors.
*
* @param uuids An array of user ids
* @param emails An array of emails