Fix multi copy ownership setting.

This commit is contained in:
Max Goodman
2013-07-15 16:15:52 -07:00
parent 3d97fa7a2a
commit e03cb367d3
2 changed files with 9 additions and 4 deletions

View File

@@ -30,13 +30,14 @@ from r2.controllers.oauth2 import (
OAuth2ResourceController,
require_oauth2_scope,
)
from r2.models.account import Account
from r2.models.subreddit import (
FakeSubreddit,
Subreddit,
LabeledMulti,
TooManySubredditsError,
)
from r2.lib.db import tdb_cassandra
from r2.lib.db import tdb_cassandra, thing
from r2.lib.wrapped import Wrapped
from r2.lib.validator import (
validate,
@@ -219,10 +220,13 @@ class MultiApiController(RedditController, OAuth2ResourceController):
def _copy_multi(self, from_multi, to_path_info):
self._check_new_multi_path(to_path_info)
to_owner = Account._by_name(to_path_info['username'])
try:
LabeledMulti._byID(to_path_info['path'])
except tdb_cassandra.NotFound:
to_multi = LabeledMulti.copy(to_path_info['path'], from_multi)
to_multi = LabeledMulti.copy(to_path_info['path'], from_multi,
owner=to_owner)
else:
raise RedditError('MULTI_EXISTS', code=409, fields='multipath')

View File

@@ -1406,10 +1406,11 @@ class LabeledMulti(tdb_cassandra.Thing, MultiReddit):
return obj
@classmethod
def copy(cls, path, multi):
def copy(cls, path, multi, owner):
obj = cls(_id=path, **multi._t)
obj.owner_fullname = owner._fullname
obj._commit()
obj._owner = multi.owner
obj._owner = owner
return obj
@classmethod