mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user