discourse/app/assets/javascripts/admin/models/email-log.js
Robin Ward ba00cc8ec4
DEV: Move Discourse.getURL and related functions to a module (#9966)
* DEV: Move `Discourse.getURL` and related functions to a module

* DEV: Remove `Discourse.getURL` and `Discourse.getURLWithCDN`

* FIX: `get-url` is required for server side code

* DEV: Deprecate `BaseUri` too.
2020-06-03 12:45:26 -04:00

37 lines
834 B
JavaScript

import getURL from "discourse-common/lib/get-url";
import { ajax } from "discourse/lib/ajax";
import AdminUser from "admin/models/admin-user";
import EmberObject from "@ember/object";
const EmailLog = EmberObject.extend({});
EmailLog.reopenClass({
create(attrs) {
attrs = attrs || {};
if (attrs.user) {
attrs.user = AdminUser.create(attrs.user);
}
if (attrs.post_url) {
attrs.post_url = getURL(attrs.post_url);
}
return this._super(attrs);
},
findAll(filter, offset) {
filter = filter || {};
offset = offset || 0;
const status = filter.status || "sent";
filter = _.omit(filter, "status");
return ajax(`/admin/email/${status}.json?offset=${offset}`, {
data: filter
}).then(logs => logs.map(log => EmailLog.create(log)));
}
});
export default EmailLog;